Making the test pass

Let's fix our failing test by defining analyze_text(). Remember that in test-driven development we only write enough code to satisfy our tests, so all we do right now is create an empty function. For simplicity's sake we'll put this function in text_analyzer.py, though normally your test code and implementation code will be in different modules:

# text_analyzer.py

def analyze_text():
"""Calculate the number of lines and characters in a file.
"""
pass

Put this function at module scope. Running the test again, we find that they now
pass:

% python text_analyzer.py
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

We've completed a single TDD cycle, but of course our code doesn't really do anything yet. We'll iteratively improve our tests and implementation to arrive at a real solution.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset