June 2017
Beginner
352 pages
8h 39m
English
So let's add a test for the other feature we want, which is to count the number of characters in the file. Since analyze_text() is now supposed to return two values, we'll have it return a tuple with line count in the first position and character count in the second. Our new test looks like this:
# text_analyzer.pyclass TextAnalysisTests(unittest.TestCase): . . . def test_character_count(self): "Check that the character count is correct." self.assertEqual(analyze_text(self.filename)[1], 131)
And it fails as expected:
% python text_analyzer.pyE..======================================================================ERROR: test_character_count (__main__.TextAnalysisTests)---------------------------------------------------------------------- ...
Read now
Unlock full access