After we write the tests, It's time run them.
Run the following command in the project root.
python -m unittest tests.load
You should get the following output:
$ python -m unittest tests.load
EEEE.
======================================================================
ERROR: test_load_0 (tests.load.TestLoad)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\projects\playground\tests\load.py", line 32, in test_load_0
self.assertLeaf(tree,0)
File "C:\projects\playground\tests\load.py", line 22, in assertLeaf
self.assertEqual(tree.data, data)
AttributeError: 'NoneType' object has no attribute 'data'
======================================================================
ERROR: test_load_0_1 (tests.load.TestLoad)
...
======================================================================
ERROR: test_load_0_1_2_x_4_5 (tests.load.TestLoad)
...
======================================================================
ERROR: test_load_0_x_2 (tests.load.TestLoad)
...
----------------------------------------------------------------------
Ran 5 tests in 0.001s
FAILED (errors=4)
So, what this output tells us?
Ran 5 tests in 0.001s
At the bottom of the output, we can see how many tests were running and the time it takes. In our case, we ran all the 5 tests in the tests.load module in 0.001 seconds.
FAILED (errors=4)
We also see in the bottom of the output, whether we pass the test. There are two options to this summary message:
What is the difference between failure and an error:
In our case, 4 tests ended with error - therefore we the second summary message is displayed.
======================================================================
ERROR: test_load_0 (tests.load.TestLoad)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\projects\playground\tests\load.py", line 32, in test_load_0
self.assertLeaf(tree,0)
File "C:\projects\playground\tests\load.py", line 22, in assertLeaf
self.assertEqual(tree.data, data)
AttributeError: 'NoneType' object has no attribute 'data'
For each error or failure, you can see :
EEEE.
At the top of the output. We can see concise summary results of all the ran tests. For each ran test, one character is displayed that shows the status of the test:
We can see that there is a test that passed without writing any code. Can you conclude what the test that passed is from the output?
The test_empty is passed since the load stub return the expected None.
However, It is not enough - To write a correct code, all test needs to pass.
Rememeber that even a broken watch shows the right time twice a day :-)
In the next part, we write the code for the load function