Skip to content

Commit afdc39f

Browse files
committed
Fixed a bug with showing negative number of koans to complete when all koans are completed. Added a little highlighing for which file and line number to edit. Removed some brittle tests
1 parent d5899a0 commit afdc39f

File tree

4 files changed

+59
-83
lines changed

4 files changed

+59
-83
lines changed

python2/runner/runner_tests/test_sensei.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,30 +225,6 @@ def test_that_scraping_the_assertion_error_with_list_error(self):
225225
def test_that_scraping_a_non_existent_stack_dump_gives_you_nothing(self):
226226
self.assertEqual("", self.sensei.scrapeInterestingStackDump(None))
227227

228-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_messaged_assert(self):
229-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py", line 43, in test_durability
230-
self.assertEqual("Steel","Lard", "Another fine mess you've got me into Stanley...")"""
231-
self.assertEqual(expected,
232-
self.sensei.scrapeInterestingStackDump(error_assertion_with_message))
233-
234-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_assert_equals(self):
235-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py", line 49, in test_math
236-
self.assertEqual(4,99)"""
237-
self.assertEqual(expected,
238-
self.sensei.scrapeInterestingStackDump(error_assertion_equals))
239-
240-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_assert_true(self):
241-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_armories.py", line 25, in test_weoponary
242-
self.assertTrue("Pen" > "Sword")"""
243-
self.assertEqual(expected,
244-
self.sensei.scrapeInterestingStackDump(error_assertion_true))
245-
246-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_syntax_error(self):
247-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_asserts.py", line 20
248-
self.assertTrue(eoe"Pen" > "Sword", "nhnth")"""
249-
self.assertEqual(expected,
250-
self.sensei.scrapeInterestingStackDump(error_mess))
251-
252228
def test_that_if_there_are_no_failures_say_the_final_zenlike_remark(self):
253229
self.sensei.failures = None
254230
words = self.sensei.say_something_zenlike()

python2/runner/sensei.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def learn(self):
8787
self.stream.writeln("")
8888
self.stream.writeln("")
8989
self.stream.writeln(self.report_progress())
90+
if self.failures:
91+
self.stream.writeln(self.report_remaining())
9092
self.stream.writeln("")
9193
self.stream.writeln(self.say_something_zenlike())
9294

@@ -138,36 +140,46 @@ def scrapeInterestingStackDump(self, err):
138140

139141
sep = '@@@@@SEP@@@@@'
140142

141-
scrape = ""
143+
stack_text = ""
142144
for line in lines:
143145
m = re.search("^ File .*$",line)
144146
if m and m.group(0):
145-
scrape += '\n' + line
147+
stack_text += '\n' + line
146148

147149
m = re.search("^ \w(\w)+.*$",line)
148150
if m and m.group(0):
149-
scrape += sep + line
151+
stack_text += sep + line
150152

151-
lines = scrape.splitlines()
153+
lines = stack_text.splitlines()
152154

153-
scrape = ""
155+
stack_text = ""
154156
for line in lines:
155157
m = re.search("^.*[/\\\\]koans[/\\\\].*$",line)
156158
if m and m.group(0):
157-
scrape += line + '\n'
158-
return scrape.replace(sep, '\n').strip('\n')
159+
stack_text += line + '\n'
160+
161+
162+
stack_text = stack_text.replace(sep, '\n').strip('\n')
163+
stack_text = re.sub(r'(about_\w+.py)',
164+
r"{0}\1{1}".format(Fore.BLUE, Fore.YELLOW), stack_text)
165+
stack_text = re.sub(r'(line \d+)',
166+
r"{0}\1{1}".format(Fore.BLUE, Fore.YELLOW), stack_text)
167+
return stack_text
159168

160169
def report_progress(self):
161-
koans_complete = self.pass_count
162-
lessons_complete = self.lesson_pass_count
163-
koans_remaining = self.total_koans() - koans_complete
164-
lessons_remaining = self.total_lessons() - lessons_complete
165-
166-
sent1 = "You have completed {0} koans and " \
167-
"{1} lessons.\n".format(koans_complete, lessons_complete)
168-
sent2 = "You are now {0} koans and {1} lessons away from " \
169-
"reaching enlightenment.".format(koans_remaining, lessons_remaining)
170-
return sent1+sent2
170+
return "You have completed {0} koans and " \
171+
"{1} lessons.".format(
172+
self.pass_count,
173+
self.lesson_pass_count)
174+
175+
def report_remaining(self):
176+
koans_remaining = self.total_koans() - self.pass_count
177+
lessons_remaining = self.total_lessons() - self.pass_count
178+
179+
return "You are now {0} koans and {1} lessons away from " \
180+
"reaching enlightenment.".format(
181+
koans_remaining,
182+
lessons_remaining)
171183

172184
# Hat's tip to Tim Peters for the zen statements from The 'Zen
173185
# of Python' (http://www.python.org/dev/peps/pep-0020/)

python3/runner/runner_tests/test_sensei.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AboutFreemasons:
3232
pass
3333

3434
error_assertion_with_message = """Traceback (most recent call last):
35-
File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py", line 43, in test_durability
35+
File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py ", line 43, in test_durability
3636
self.assertEqual("Steel","Lard", "Another fine mess you've got me into Stanley...")
3737
AssertionError: Another fine mess you've got me into Stanley..."""
3838

@@ -205,30 +205,6 @@ def test_that_scraping_the_assertion_error_with_list_error(self):
205205
def test_that_scraping_a_non_existent_stack_dump_gives_you_nothing(self):
206206
self.assertEqual("", self.sensei.scrapeInterestingStackDump(None))
207207

208-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_messaged_assert(self):
209-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py", line 43, in test_durability
210-
self.assertEqual("Steel","Lard", "Another fine mess you've got me into Stanley...")"""
211-
self.assertEqual(expected,
212-
self.sensei.scrapeInterestingStackDump(error_assertion_with_message))
213-
214-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_assert_equals(self):
215-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_exploding_trousers.py", line 49, in test_math
216-
self.assertEqual(4,99)"""
217-
self.assertEqual(expected,
218-
self.sensei.scrapeInterestingStackDump(error_assertion_equals))
219-
220-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_assert_true(self):
221-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_armories.py", line 25, in test_weoponary
222-
self.assertTrue("Pen" > "Sword")"""
223-
self.assertEqual(expected,
224-
self.sensei.scrapeInterestingStackDump(error_assertion_true))
225-
226-
def test_that_scraping_the_stack_dump_only_shows_interesting_lines_for_syntax_error(self):
227-
expected = """ File "/Users/Greg/hg/python_koans/koans/about_asserts.py", line 20
228-
self.assertTrue(eoe"Pen" > "Sword", "nhnth")"""
229-
self.assertEqual(expected,
230-
self.sensei.scrapeInterestingStackDump(error_mess))
231-
232208
def test_that_if_there_are_no_failures_say_the_final_zenlike_remark(self):
233209
self.sensei.failures = None
234210
words = self.sensei.say_something_zenlike()

python3/runner/sensei.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def learn(self):
8686
self.stream.writeln("")
8787
self.stream.writeln("")
8888
self.stream.writeln(self.report_progress())
89+
if self.failures:
90+
self.stream.writeln(self.report_remaining())
8991
self.stream.writeln("")
9092
self.stream.writeln(self.say_something_zenlike())
9193

@@ -138,36 +140,46 @@ def scrapeInterestingStackDump(self, err):
138140

139141
sep = '@@@@@SEP@@@@@'
140142

141-
scrape = ""
143+
stack_text = ""
142144
for line in lines:
143145
m = re.search("^ File .*$",line)
144146
if m and m.group(0):
145-
scrape += '\n' + line
147+
stack_text += '\n' + line
146148

147149
m = re.search("^ \w(\w)+.*$",line)
148150
if m and m.group(0):
149-
scrape += sep + line
151+
stack_text += sep + line
150152

151-
lines = scrape.splitlines()
153+
lines = stack_text.splitlines()
152154

153-
scrape = ""
155+
stack_text = ""
154156
for line in lines:
155157
m = re.search("^.*[/\\\\]koans[/\\\\].*$",line)
156158
if m and m.group(0):
157-
scrape += line + '\n'
158-
return scrape.replace(sep, '\n').strip('\n')
159+
stack_text += line + '\n'
160+
161+
162+
stack_text = stack_text.replace(sep, '\n').strip('\n')
163+
stack_text = re.sub(r'(about_\w+.py)',
164+
r"{0}\1{1}".format(Fore.BLUE, Fore.YELLOW), stack_text)
165+
stack_text = re.sub(r'(line \d+)',
166+
r"{0}\1{1}".format(Fore.BLUE, Fore.YELLOW), stack_text)
167+
return stack_text
159168

160169
def report_progress(self):
161-
koans_complete = self.pass_count
162-
lessons_complete = self.lesson_pass_count
163-
koans_remaining = self.total_koans() - koans_complete
164-
lessons_remaining = self.total_lessons() - lessons_complete
165-
166-
sent1 = "You have completed {0} koans and " \
167-
"{1} lessons.\n".format(koans_complete, lessons_complete)
168-
sent2 = "You are now {0} koans and {1} lessons away from " \
169-
"reaching enlightenment.".format(koans_remaining, lessons_remaining)
170-
return sent1+sent2
170+
return "You have completed {0} koans and " \
171+
"{1} lessons.".format(
172+
self.pass_count,
173+
self.lesson_pass_count)
174+
175+
def report_remaining(self):
176+
koans_remaining = self.total_koans() - self.pass_count
177+
lessons_remaining = self.total_lessons() - self.pass_count
178+
179+
return "You are now {0} koans and {1} lessons away from " \
180+
"reaching enlightenment.".format(
181+
koans_remaining,
182+
lessons_remaining)
171183

172184
# Hat's tip to Tim Peters for the zen statements from The 'Zen
173185
# of Python' (http://www.python.org/dev/peps/pep-0020/)

0 commit comments

Comments
 (0)