June 2017
Beginner
352 pages
8h 39m
English
Finally, we can see one more very useful type of assertion by writing a test to verify that analyze_text() doesn't delete the file — a reasonable requirement for the function!:
# text_analyzer.pyclass TextAnalysisTests(unittest.TestCase): . . . def test_no_deletion(self): "Check that the function doesn't delete the input file." analyze_text(self.filename) self.assertTrue(os.path.exists(self.filename))
The TestCase.assertTrue() function simply checks that the value passed to it evaluates to True. There is an equivalent assertFalse() which does the same test for false values.
As you probably expect, this test passes already as well:
% python text_analyzer.py.....---------------------------------------------------------------------- ...
Read now
Unlock full access