Skip to content

Commit 9fb66e3

Browse files
committed
one more bugfix in checker
1 parent 741decd commit 9fb66e3

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

tests/sourcetree.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ def split_into_chunks(code):
294294
chunk = ""
295295
for line in code.splitlines():
296296
if line.strip() == "[...]":
297-
yield chunk
298-
chunk = ""
297+
if chunk:
298+
yield chunk
299+
chunk = ""
299300
elif line.startswith("[...]"):
300-
yield chunk
301-
chunk = ""
301+
if chunk:
302+
yield chunk
303+
chunk = ""
302304
elif line.endswith("[...]"):
303305
linestart, _, _ = line.partition("[...]")
304306
chunk += linestart

tests/test_sourcetree.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from book_parser import CodeListing
88
from sourcetree import (
9-
BOOTSTRAP_WGET,
109
ApplyCommitException,
1110
Commit,
1211
SourceTree,
@@ -824,7 +823,6 @@ def method1(self):
824823
with self.assertRaises(ApplyCommitException):
825824
check_chunks_against_future_contents(code, future_contents)
826825

827-
828826
def test_leading_blank_lines_in_listing_are_ignored(self):
829827
code = dedent(
830828
"""
@@ -844,6 +842,40 @@ def method1(self):
844842
).strip()
845843
check_chunks_against_future_contents(code, future_contents) # should not raise
846844

845+
def test_thing(self):
846+
code = dedent(
847+
"""
848+
[...]
849+
item.save()
850+
851+
return render(
852+
request,
853+
"home.html",
854+
{"new_item_text": item.text},
855+
)
856+
"""
857+
)
858+
future_contents = dedent(
859+
"""
860+
from django.shortcuts import render
861+
from lists.models import Item
862+
863+
864+
def home_page(request):
865+
item = Item()
866+
item.text = request.POST.get("item_text", "")
867+
item.save()
868+
869+
return render(
870+
request,
871+
"home.html",
872+
{"new_item_text": item.text},
873+
)
874+
"""
875+
).strip()
876+
check_chunks_against_future_contents(code, future_contents) # should not raise
877+
878+
847879
def test_trailing_blank_lines_in_listing_are_ignored(self):
848880
code = dedent(
849881
"""

0 commit comments

Comments
 (0)