We start to setup the regression testing infrastructure for our data processing pipeline by writting a test for the EyeSize class.
Consider reading Testing Your Code — The Hitchhiker's Guide to Python
Let's have a look at a first implementation of function named eye_test
that simply:
1066744
) and save it to disk as TralitusSaltrator.jpg
estimate
and get back the segmented eye and estimated radius%cd
%cd dexy/test
/home/reproducible /home/reproducible/dexy/test
%more eyesize_0_basic_test.py
%run eyesize_0_basic_test.py
eyesize_basic_test()
Output information providing context, for example the current and expected value.
Note that logging information when functions and tests work as expected is not recommended, it will pollute the output and may prevent the developer from having his attention dran on real issue.
%more eyesize_1_noisy_test.py
%run eyesize_1_noisy_test.py
eyesize_noisy_test()
It is always good to start from a clean environment by removing files previously generated.
Instead of dumping the files along side the python scripts, let's organize files by having:
inputs
folderoutputs
folder! rm TralitusSaltrator.jpg
! rm SegmentedEye.png
%more eyesize_2_cleanplate_test.py
%run eyesize_2_cleanplate_test.py
eyesize_cleanplate_test()
%more eyesize_3_withorigin_test.py
%run eyesize_3_withorigin_test.py
eyesize_withorigin_test()
ls inputs
TralitusSaltrator_figshare_1066744.jpg
ls outputs
SegmentedEye_204_400.png
Nosetests is a script that collects tests automatically.
!nosetests --nocapture -v
eyesize_0_basic_test.eyesize_basic_test ... ok eyesize_1_noisy_test.eyesize_noisy_test ... ok eyesize_2_cleanplate_test.eyesize_cleanplate_test ... ok eyesize_3_withorigin_test.eyesize_withorigin_test ... ok ---------------------------------------------------------------------- Ran 4 tests in 7.174s OK
Add a test for the download
function of the ImageDownloader
class