This module will collect tools for unit testing the functions in the
FreqDemod package. Unit tests were developed using the unittest package.
To run the unit tests, open up a terminal in the FreqDemod directory and
run either:
python -m unittest discover
(or python -m unittest discover --verbose)
or:
nosetests
(or nosetests -v
or notetests -sv)
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
- HDF5 Command-line Tools [link]
- h5ls command line tool [link]
-
class test_hdf5.Test_update_attrs(methodName='runTest')[source]
Bases: unittest.case.TestCase
Test the helper function update_attrs
-
filename = '.Test_update_h5_attrs.h5'
-
setUp()[source]
-
test_overwrite()[source]
The function should overwrite existing attributes
-
test_normal_write()[source]
Writing a non-empty dictionary should do something
-
test_empty_write()[source]
Writing an empty dictionary should do nothing.
-
tearDown()[source]
Close the h5 file, and remove the file for the next iteration.
-
class test_hdf5.Test_memory_data(methodName='runTest')[source]
Bases: unittest.case.TestCase
Write to memory, read, close; Write to memory, read, close; etc
-
filename = '.Test_update_h5_data.h5'
-
setUp()[source]
-
test_array_read()[source]
Open in memory, write, read array, close
-
test_attr_read()[source]
Open in memory, write, read attribute, close
-
tearDown()[source]
Close the h5 file, and remove the file for the next iteration.
-
class test_hdf5.Test_disk_data(methodName='runTest')[source]
Bases: unittest.case.TestCase
Write to disk, open, read, close; Write to disk, open, read, close; etc
-
filename = '.Test_update_h5_data.h5'
-
setUp()[source]
-
test_01_read()[source]
Open file from disk, read array, close
-
test_02_read()[source]
Open file from disk, read attribute, close
-
tearDown()[source]
Remove the file for the next iteration.
-
class test_hdf5.Test_disk_data2(methodName='runTest')[source]
Bases: unittest.case.TestCase
Write 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
-
classmethod setUpClass()[source]
-
test_01_read()[source]
Read array
-
test_02_read()[source]
Read attribute
-
test_03_write()[source]
Write new attribute
-
test_04_read()[source]
Read new attribute
-
classmethod tearDownClass()[source]
-
class test_hdf5.Test_update_attrs_extended(methodName='runTest')[source]
Bases: unittest.case.TestCase
Read and write an x and y dataset representing a cantielver 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_read reads 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:
-
filename = '.Test_update_attrs_extended.h5'
-
classmethod setUpClass()[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.
-
test_01_write()[source]
Write the representative dataset to a file.
-
test_02_read()[source]
Read the representative dataset, print out the elements, and compare
the printout with the expected string.
tests.test_freqdemod module
Tests for the demodulate module.
-
class test_freqdemod.InitLoadSaveTests(methodName='runTest')[source]
Bases: unittest.case.TestCase
Make sure the Signal object is set up correctly.
-
setUp()[source]
Create an trial Signal object
-
test_report()[source]
Initialize Signal object
-
test_x()[source]
Check x-array data.
-
test_y()[source]
Check y-array data.
-
test_close()[source]
Verify closed object by testing one of the attributes
-
tearDown()[source]
Close the h5 files before the next iteration.
-
class test_freqdemod.MaskTests(methodName='runTest')[source]
Bases: unittest.case.TestCase
-
setUp()[source]
Create a trial Signal object
-
test_binarate_1()[source]
Binarate mask middle; test length is 2^n
-
test_binarate_2()[source]
Binarate mask start; test length is 2^n
-
test_binarate_3()[source]
Binarate mask end test length is 2^n
-
test_binarate_4()[source]
If we have not called binarate, then workup/time/mask/binarate does not exist
-
test_binarate_5()[source]
If we have called binarate, then workup/time/mask/binarate does exist
-
tearDown()[source]
Close the h5 files before the next iteration.
-
class test_freqdemod.FFTTests(methodName='runTest')[source]
Bases: unittest.case.TestCase
-
setUp()[source]
Create an trial Signal object
-
testfft_1()[source]
FFT: test that the resulting data is complex
-
testfft_2()[source]
FFT: test that the complex Hilbert transform filter is real
-
testfft_3()[source]
FFT: test the complex Hilbert transform filter near freq = 0
-
tearDown()[source]
Close the h5 files before the next iteration.
-
class test_freqdemod.MiscTests(methodName='runTest')[source]
Bases: unittest.case.TestCase
-
test_array_middle_1()[source]
Misc: mean time (n odd)
-
test_array_middle_2()[source]
Misc: mean time (n even)