Skip to content

Commit 3e3ea85

Browse files
authored
Merge pull request #218 from Xronophobe/update--chapter-12
Update chapter 12
2 parents e8abda8 + 7729fb8 commit 3e3ea85

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

chapter_12_organising_test_files.asciidoc

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ and wait until we're back to a fully passing test suite before refactoring.
159159
160160
Kent Beck has a book-length exploration of the tradeoffs
161161
of refactor-now vs refactor-later, called
162-
https://learning.oreilly.com/library/view/tidy-first/9781098151232/[Tidy First?]
162+
https://www.oreilly.com/library/view/tidy-first/9781098151232/[Tidy First?]
163163
**********************************************************************
164164

165165

@@ -262,6 +262,9 @@ class FunctionalTest(StaticLiveServerTestCase):
262262
NOTE: Keeping helper methods in a base `FunctionalTest` class
263263
is one useful way of preventing duplication in FTs.
264264
Later in the book (in <<chapter_page_pattern>>) we'll use the "Page pattern",
265+
// CSANAD: is this reference to the chapter "The Token Social Bit, the Page
266+
// Pattern, and an Exercise for the Reader" as chapter_page_pattern
267+
// still clear in print?
265268
which is related, but prefers composition over inheritance--always a good thing.
266269

267270
Our first FT is now in its own file,
@@ -291,7 +294,7 @@ Some people like to use them a lot in Django code
291294
(e.g., your views might import models using `from .models import List`,
292295
instead of `from list.models`).
293296
Ultimately this is a matter of personal preference.
294-
I prefer to use relative imports only when I'm super-super
297+
I prefer to use relative imports only when I'm super-super confident
295298
that the relative position of the thing I'm importing won't change.
296299
That applies in this case because I know for sure
297300
all the tests will sit next to _base.py_, which they inherit from.
@@ -378,14 +381,16 @@ AssertionError: write me!
378381
Brilliant--no need to sit around waiting for all the FTs
379382
when we're only interested in a single one.
380383
Although we need to remember to run all of them now and again, to check for regressions.
381-
Later in the book we'll see how to give that task over to an automated Continuous Integration loop.
382-
For now, let's commit!
384+
Later in the book we'll set up a Continuous Integration (CI) server to run all the tests automatically,
385+
for example every time we push to master.
386+
For now, a good prompt for running all the tests is "just before you do a commit",
387+
so let's get into that habit now:
383388

384389
[subs="specialcharacters,quotes"]
385390
----
386391
$ *git status*
387392
$ *git add src/functional_tests*
388-
$ *git commit -m "Moved Fts into their own individual files"*
393+
$ *git commit -m "Moved FTs into their own individual files"*
389394
----
390395

391396
Great. We've split our functional tests nicely out into different files.
@@ -547,6 +552,8 @@ Like this:
547552
((("Python 3", "lambda functions")))
548553
`lambda` in Python is the syntax for making a one-line, throwaway function--it
549554
saves you from having to use `def..():` and an indented block:
555+
// CSANAD: the `def..` and the `():` renders apart from each other, on two
556+
// lines. I couldn't find out how to keep them together.
550557
551558
[role="skipme"]
552559
[source,python]
@@ -561,9 +568,10 @@ saves you from having to use `def..():` and an indented block:
561568
5
562569
----
563570
564-
In our case, we're using it to transform a bit of code that would otherwise be
565-
executed immediately into a function that we can pass as an argument,
571+
In our case, we're using it to transform a bit of code--that would otherwise be
572+
executed immediately--into a function that we can pass as an argument,
566573
and that can be executed later, and multiple times:
574+
// CSANAD: I think it's easier to read like this.
567575
568576
[role="skipme"]
569577
[source,python]
@@ -621,18 +629,24 @@ FAILED (errors=1)
621629
The order of the traceback is a little confusing, but we can more or less follow
622630
through what happened:
623631

624-
<1> At line 15 in our FT, we go into our `self.wait_for` helper,
625-
passing it the `lambda`-ified version of the `assertEqual`.
632+
<1> In our FT, we call our `self.wait_for` helper, where we pass
633+
the `lambda`-ified version of `assertEqual`.
626634

627635
<2> We go into `self.wait_for` in _base.py_,
628-
where we can see that we're inside `fn()`,
629-
which is the name for our lambda inside the helper.
636+
where we're calling (and returning) `fn()`, which refers to the passed
637+
lambda function encapsulating our test assertion.
630638

631639
<3> To explain where the exception has actually come from,
632640
the traceback takes us back into _test_list_item_validation.py_
633641
and inside the body of the `lambda` function,
634-
and tells us that it the attempt to find the `.invalid-feedback` element
642+
and tells us that it was attempt to find the `.invalid-feedback` element
635643
that failed.
644+
// CSANAD: I changed two things here:
645+
// First, I think it's better to remove the specific line number which may
646+
// vary due to personal formatting preferences (and following the pep8 puts
647+
// this on line 16 for me)
648+
// Secondly, we say we go into self.wait_for in step#2. Here, in step#1 we
649+
// are only calling it. Overall, I tried making it clearer a bit.
636650

637651

638652
((("functional programming")))
@@ -767,7 +781,8 @@ $ *cp src/lists/tests/test_views.py src/lists/tests/test_models.py*
767781
----
768782

769783
And strip _test_models.py_ down
770-
to being just the one test--it means it needs far fewer imports:
784+
to being just the one test:
785+
// CSANAD: the imports are unchanged, only the view-related tests are removed
771786

772787
[role="sourcecode"]
773788
.src/lists/tests/test_models.py (ch11l016)
@@ -792,10 +807,10 @@ Whereas _test_views.py_ just loses one class:
792807
----
793808
--- a/src/lists/tests/test_views.py
794809
+++ b/src/lists/tests/test_views.py
795-
@@ -103,34 +104,3 @@ class ListViewTest(TestCase):
796-
self.assertNotContains(response, "other list item 1")
797-
self.assertNotContains(response, "other list item 2")
810+
33 +74,3 @@ class NewItemTest(TestCase):
811+
)
798812
813+
self.assertRedirects(response, f"/lists/{correct_list.id}/")
799814
-
800815
-
801816
-class ListAndItemModelsTest(TestCase):

0 commit comments

Comments
 (0)