Skip to content

Pass atol parameter to FITSDiff #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

- Add ability to compare to Pandas DataFrames and store them as HDF5 files [#23]

- Fix ``array_compare`` so that the ``atol`` parameter is correctly used with
FITS files. [#33]

0.5 (2022-01-12)
----------------

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ The supported formats at this time are ``text`` and ``fits``, and
contributions for other formats are welcome. The default format is
``text``.

Another argument is the relative tolerance for floating point values
(which defaults to 1e-7):
Additional arguments are the relative and absolute tolerances for floating
point values (which default to 1e-7 and 0, respectively):

.. code:: python

@pytest.mark.array_compare(rtol=20)
@pytest.mark.array_compare(rtol=20, atol=0.1)
def test_array():
...

Expand Down
3 changes: 2 additions & 1 deletion pytest_arraydiff/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def compare(cls, reference_file, test_file, atol=None, rtol=None):
from astropy.io.fits.diff import FITSDiff
from astropy.utils.introspection import minversion
if minversion(astropy, '2.0'):
diff = FITSDiff(reference_file, test_file, rtol=rtol)
diff = FITSDiff(reference_file, test_file, rtol=rtol, atol=atol)
else:
# `atol` is not supported prior to Astropy 2.0
diff = FITSDiff(reference_file, test_file, tolerance=rtol)
return diff.identical, diff.report()

Expand Down
Binary file added tests/baseline/test_relative_tolerance.fits
Binary file not shown.
17 changes: 14 additions & 3 deletions tests/test_pytest_arraydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,20 @@ def test_default_format(file_format):
assert os.path.exists(os.path.join(gen_dir, 'test_default.' + ('fits' if file_format == 'fits' else 'txt')))


@pytest.mark.array_compare(reference_dir=reference_dir, rtol=0.5, file_format='fits')
def test_tolerance():
return np.ones((3, 4)) * 1.6
@pytest.mark.array_compare(reference_dir=reference_dir, rtol=0.5,
file_format='fits')
def test_relative_tolerance():
# Scale up the output values by 1.5 to ensure the large `rtol` value is
# needed. (The comparison file contains all 1.6.)
return np.ones((3, 4)) * 1.6 * 1.5


@pytest.mark.array_compare(reference_dir=reference_dir, atol=1.5,
file_format='fits')
def test_absolute_tolerance():
# Increase the output values by 1.4 to ensure the large `atol` value is
# needed. (The comparison file contains all 1.6.)
return np.ones((3, 4)) * 1.6 + 1.4


def test_nofile():
Expand Down