Skip to content

Commit 1af2acd

Browse files
authored
Merge pull request #33 from svank/fix-atol
Pass `atol` parameter to FITSDiff
2 parents a74f2e3 + b015c5c commit 1af2acd

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

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

6+
- Fix ``array_compare`` so that the ``atol`` parameter is correctly used with
7+
FITS files. [#33]
8+
69
0.5 (2022-01-12)
710
----------------
811

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ The supported formats at this time are ``text`` and ``fits``, and
111111
contributions for other formats are welcome. The default format is
112112
``text``.
113113

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

117117
.. code:: python
118118
119-
@pytest.mark.array_compare(rtol=20)
119+
@pytest.mark.array_compare(rtol=20, atol=0.1)
120120
def test_array():
121121
...
122122

pytest_arraydiff/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def compare(cls, reference_file, test_file, atol=None, rtol=None):
116116
from astropy.io.fits.diff import FITSDiff
117117
from astropy.utils.introspection import minversion
118118
if minversion(astropy, '2.0'):
119-
diff = FITSDiff(reference_file, test_file, rtol=rtol)
119+
diff = FITSDiff(reference_file, test_file, rtol=rtol, atol=atol)
120120
else:
121+
# `atol` is not supported prior to Astropy 2.0
121122
diff = FITSDiff(reference_file, test_file, tolerance=rtol)
122123
return diff.identical, diff.report()
123124

5.63 KB
Binary file not shown.

tests/test_pytest_arraydiff.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,20 @@ def test_default_format(file_format):
132132
assert os.path.exists(os.path.join(gen_dir, 'test_default.' + ('fits' if file_format == 'fits' else 'txt')))
133133

134134

135-
@pytest.mark.array_compare(reference_dir=reference_dir, rtol=0.5, file_format='fits')
136-
def test_tolerance():
137-
return np.ones((3, 4)) * 1.6
135+
@pytest.mark.array_compare(reference_dir=reference_dir, rtol=0.5,
136+
file_format='fits')
137+
def test_relative_tolerance():
138+
# Scale up the output values by 1.5 to ensure the large `rtol` value is
139+
# needed. (The comparison file contains all 1.6.)
140+
return np.ones((3, 4)) * 1.6 * 1.5
141+
142+
143+
@pytest.mark.array_compare(reference_dir=reference_dir, atol=1.5,
144+
file_format='fits')
145+
def test_absolute_tolerance():
146+
# Increase the output values by 1.4 to ensure the large `atol` value is
147+
# needed. (The comparison file contains all 1.6.)
148+
return np.ones((3, 4)) * 1.6 + 1.4
138149

139150

140151
def test_nofile():

0 commit comments

Comments
 (0)