Test failure
When running the unit tests, I get stuck at:
------------------------------------------------------------------------
Running SpyFile read tests on BSQ complex128 little-endian file without memmap...
------------------------------------------------------------------------
Testing getitem_i_j......................................... OK
Testing getitem_i_j_k....................................... OK
Testing getitem_i_j_kslice.................................. OK
Testing getitem_islice_jslice............................... OK
Testing load................................................ OK
Testing read_band........................................... OK
Testing read_bands.......................................... OK
Testing read_bands_duplicates............................... OK
Testing read_bands_nonascending............................. OK
Testing read_datum.......................................... OK
Testing read_pixel.......................................... OK
Testing read_subimage....................................... OK
Testing read_subregion...................................... OK
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/Adam/Downloads/spectral/spectral/tests/run.py", line 47, in <module>
test.run()
~~~~~~~~^^
File "/Users/Adam/Downloads/spectral/spectral/tests/spyfile.py", line 348, in run
tests = create_complex_test_files(dtypes)
File "/Users/Adam/Downloads/spectral/spectral/tests/spyfile.py", line 319, in create_complex_test_files
spy.envi.save_image(fname, X)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Users/Adam/Downloads/spectral/spectral/io/envi.py", line 470, in save_image
_write_image(hdr_file, data, metadata, **kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/spectral/spectral/io/envi.py", line 688, in _write_image
(hdr_file, img_file) = check_new_filename(hdr_file, img_ext, force)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/Downloads/spectral/spectral/io/envi.py", line 390, in check_new_filename
raise EnviException('Header file %s already exists. Use `force` '
'keyword to force overwrite.' % hdr_file)
spectral.io.envi.EnviException: Header file /Users/Adam/Downloads/spectral/spectral_test_files/test_complex64.hdr already exists. Use `force` keyword to force overwrite.
Adding force=True helps, but I'm not sure if this is a test cleanup problem.
Next bug:
------------------------------------------------------------------------
Running continuum tests.
------------------------------------------------------------------------
Testing 2d_array............................................ OK
Testing 3d_array............................................ OK
Testing few_simple_cases.................................... OK
Testing out_parameter....................................... OK
Testing simple_segmented.................................... OK
Testing points_of_real_spectrum............................. OK
Testing points_of_real_spectrum_segmented................... OK
Testing in_and_out_same..................................... FAILED
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/Users/Adam/Downloads/spectral/spectral/tests/run.py", line 47, in <module>
test.run()
~~~~~~~~^^
File "/Users/Adam/Downloads/spectral/spectral/tests/continuum.py", line 243, in run
T().run()
~~~~~~~^^
File "/Users/Adam/Downloads/spectral/spectral/tests/spytest.py", line 57, in run
method()
~~~~~~^^
File "/Users/Adam/Downloads/spectral/spectral/tests/continuum.py", line 234, in test_in_and_out_same
assert (res[1, 1, 200] == 0.8372113957762342)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Not sure what's wrong here.
The first error usually occurs if the spectral_test_files folder (which is generated by the tests) already exists. Please delete that folder and rerun the tests to see if that fixes the issue.
I ignored both errors and measured ~69% code coverage. Does that sound about right?
I don't know about code coverage but 100% of unit tests should pass. Please delete the spectral_test_files folder and run the tests again to see what happens (you can add the "-c" option to continue after a failure).
Okay, deleting the spectral_test_files directory let's me run all tests, the only failing test is the res assertion. I guess we should delete the spectral_test_files during test cleanup. Not sure why the assertion is failing. Let me know if you want help reproducing/debugging.
Any help you can offer on that is appreciated. Did you run with "-c" to see if any other tests fail?
I commented out the assert and reran everything and that is definitely the only one that fails. I'm only familiar with pytest, but I think SPy's test infrastructure was written before pytest even existed, so I'm not sure how much I can help. How do I run a single test?
You can't run a single unit test from the command line but you can limit it to the continuum tests like this:
python -m spectral.tests.continuum
I didn't create the failing test but my guess is that it might be due to a numeric precision issue and the test should be updated to use np.testing.assert_almost_equal. Though if that is the case, I'm surprised it has never been an issue until now.
~Unfortunately that didn't work, they aren't close either.~ I didn't use the function correctly, it does actually work!
How do I print the value of res[1, 1, 200]? print() isn't working.
SPy unit tests redirect sys.stdout during execution to suppress lots of extraneous outputs, which is why default print statements have no effect. You should still be able to use stderr like this:
print("Error message", file=sys.stderr)