tests module¶
This module collects tools for unit testing the functions in the
FreqDemod package. Unit tests were developed using the unittest
package. To run the unit tests, open a terminal in the FreqDemod directory
and run either:
python -m unittest discover
(or python -m unittest discover --verbose)
or:
python setup.py test
In some of the unit tests, we compare two numpy arrays. In developing this
comparison we found the stackoverflow discussion “Comparing numpy float arrays
in unit tests” helpful [link].
tests.test_hdf5 module¶
Tests for the hdf5 module. In writing units tests, it is crucially important
to remember that the unittest object is recreated every function call
[see here].
You thus cannot expect, say, self.f to retain a value if it is passed
between functions. You cannot pass a value between functions this way if
your object is a unittest object.
You can pass values from the setUp function to other functions, because
the setUp function is called once before every other function in the class.
Likewise the tearDown function.
There is a way to pass data between functions in a unittest onject.
This requires use of the special setUpClass, illustrated below in the
object Test_disk_data2. This test mimics how we would like to use
HDF5 data: open file on disk, pass the data between object methods, reading
and writing the data as needed.
Additional Resources
-
class
test_hdf5.Test_update_attrs(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseTest the helper function update_attrs
-
filename= '.Test_update_h5_attrs.h5'¶
-
-
class
test_hdf5.Test_memory_data(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseWrite to memory, read, close; Write to memory, read, close; etc
-
filename= '.Test_update_h5_data.h5'¶
-
-
class
test_hdf5.Test_disk_data(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseWrite to disk, open, read, close; Write to disk, open, read, close; etc
-
filename= '.Test_update_h5_data.h5'¶
-
-
class
test_hdf5.Test_disk_data2(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseWrite once to disk, open once from disk, read, write, read, close. Leave the file intact to we can examine it by calling:
h5ls -v .Test_disk_data2.h5
-
class
test_hdf5.Test_update_attrs_extended(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseRead and write an x and y dataset representing a cantilever oscillation. Use an HDF5 file format that Dwyer, Marohn, and Harrell have agreed upon (with minor modifications). This class’s unit tests create a hidden HDF5 whose contents can be examined using the command-line call:
h5ls -v .Test_update_attrs_extended.h5
The function
test_02_readreads the h5 file and prints out its contents. The outputs of print statements are usually swallowed during the unit test. To display the informative print statements, you can initiate unit testing using the following command:nosetests -sv
-
filename= '.Test_update_attrs_extended.h5'¶
-
setUp()[source]¶ “Record the date and time for use by the functions below. Delete the output file if it exists so we can make it anew.
-
tests.test_freqdemod module¶
Tests for the demodulate module.
-
class
test_freqdemod.InitLoadSaveTests(methodName='runTest')[source]¶ Bases:
unittest.case.TestCaseMake sure the Signal object is set up correctly.
-
filename= '.InitLoadSaveTests_1.h5'¶
-
-
class
test_freqdemod.TestClose(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase-
filename= '.TestClose.h5'¶
-
-
class
test_freqdemod.MaskTests(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
-
class
test_freqdemod.HDF5LoadGeneral(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase-
filename= '.general_format_h5_file.h5'¶
-