2 Tidy the project
Build it yourself. Read the tutorial is the other way to read this part.
If you start at this part, make your clone as Get the project says, and then run this command. It puts in your clone the files that this part starts from. A file that the project deleted before this part stays, so delete it if git check lists it:
git rm -rq --cached --ignore-unmatch -- :/ && git restore --source 96d6bbd94a65 --staged --worktree -- :/just setupThe release is out. Now we tidy the project, so that it is easier to find your way in it. The top folder keeps the files that a user reads first. The tests, in two files, go into one file, named after the project.
Each file that moves or goes here moves by a command, mv, or goes by a command, rm.
The code before this part. The code after it.
2.1 A hidden file for the recipes
A user of tally reads README.md first, and has no use for the recipes of the justfile. They are for the people
who work on tally. just also finds its recipes in a file named .justfile, a hidden file that ls does not list.
mv gives the justfile that name.
mv justfile .justfilejust --listIt prints the same four recipes as before, default, run, setup and test.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check f338b5b0824cIf you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source 96d6bbd94a65 --staged -- :/ && git restore --source f338b5b0824c --staged --worktree -- :/What changed
.justfile: the recipes, in a hidden file. Renamed fromjustfile. It comes frommv justfile .justfile. The file.
2.2 A test of lines
A text often has more than one line. No test yet gives count a text with a newline in it. A new test,
test_lines, counts a b, a newline, and a.
Apply the patch to tests/test_count.py, from the top of the project:
curl -fsSL https://github.com/rahuldave/tally/commit/3a4ad8d9af5153b7eb458030e59169de6d7fef95.diff | git apply --include=tests/test_count.pyThe patch adds the test test_lines at the end of the class Count.
uv run python -m unittest discover -s tests -qAll five tests pass.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check 3a4ad8d9af51If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source f338b5b0824c --staged -- :/ && git restore --source 3a4ad8d9af51 --staged --worktree -- :/What changed
tests/test_count.py: a test of a text of two lines. 3 lines added. The file.- look at
def test_lines(self):
- look at
The patch to tests/test_count.py
@@ -9,3 +9,6 @@ class Count(unittest.TestCase):
def test_case(self):
self.assertEqual(count("A a"), {"a": 2})
+
+ def test_lines(self):
+ self.assertEqual(count("a b\na"), {"a": 2, "b": 1})2.3 One name for the tests
The tests are in two files, tests/test_count.py and tests/test_edge.py. One file is one place to look. It
gets the name of the project, tests/test_tally.py. mv gives the file of edge cases that name.
mv tests/test_edge.py tests/test_tally.pyuv run python -m unittest discover -s tests -qAll five tests pass, as before. unittest finds each file whose name starts with test.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check fa608c2a2aa3If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source 3a4ad8d9af51 --staged -- :/ && git restore --source fa608c2a2aa3 --staged --worktree -- :/What changed
tests/test_tally.py: the tests of edge cases, under the new name. Renamed fromtests/test_edge.py. It comes frommv tests/test_edge.py tests/test_tally.py. The file.
2.4 Every test in one file
The class Count, with its three tests, goes into tests/test_tally.py too.
Apply the patch to tests/test_tally.py, from the top of the project:
curl -fsSL https://github.com/rahuldave/tally/commit/3d2bf4fc97f4b3711f3f8378b4db3311ce795a24.diff | git apply --include=tests/test_tally.pyThe patch adds the class Count, with its three tests, at the end of tests/test_tally.py.
uv run python -m unittest discover -s tests -qAll eight tests pass. The three tests of Count run twice, once from each file. The next change removes the old
file.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check 3d2bf4fc97f4If you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source fa608c2a2aa3 --staged -- :/ && git restore --source 3d2bf4fc97f4 --staged --worktree -- :/What changed
tests/test_tally.py: every test of tally, in one file. 11 lines added. The file.- look at
class Count(unittest.TestCase):
- look at
The patch to tests/test_tally.py
@@ -9,3 +9,14 @@ class Edge(unittest.TestCase):
def test_spaces(self):
self.assertEqual(count(" \n\t "), {})
+
+
+class Count(unittest.TestCase):
+ def test_words(self):
+ self.assertEqual(count("a b a"), {"a": 2, "b": 1})
+
+ def test_case(self):
+ self.assertEqual(count("A a"), {"a": 2})
+
+ def test_lines(self):
+ self.assertEqual(count("a b\na"), {"a": 2, "b": 1})2.5 The old file of tests goes
Every test of tests/test_count.py is now in tests/test_tally.py too. rm removes the old file.
rm tests/test_count.pyuv run python -m unittest discover -s tests -qEach test now runs one time only, and all five tests pass.
Check your files against this move. The command prints nothing when they match, and otherwise shows what differs:
git check eb82f801c8dfIf you are stuck, this command puts the files of this move in place of yours. A file that you made yourself stays:
git restore --source 3d2bf4fc97f4 --staged -- :/ && git restore --source eb82f801c8df --staged --worktree -- :/What changed
tests/test_count.py: its tests are intests/test_tally.py. Deleted. It comes fromrm tests/test_count.py.
The diff that rm tests/test_count.py makes in tests/test_count.py
@@ -1,14 +0,0 @@
-import unittest
-
-from tally import count
-
-
-class Count(unittest.TestCase):
- def test_words(self):
- self.assertEqual(count("a b a"), {"a": 2, "b": 1})
-
- def test_case(self):
- self.assertEqual(count("A a"), {"a": 2})
-
- def test_lines(self):
- self.assertEqual(count("a b\na"), {"a": 2, "b": 1})