Skip to content

Commit

Permalink
Tweak Abins-Pychop test; LinAlgError is only encountered on Windows
Browse files Browse the repository at this point in the history
When testing on Linux, Abins returns NaN rather than raise LinAlgError
when the chopper settings are out of range. Our test should detect
both cases and ensure appropriate behaviour in corresponding
situation. (i.e. raise NoTransmissionError)
  • Loading branch information
ajjackson committed Nov 11, 2024
1 parent b5e2676 commit 4fc9ab8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/integration_tests/test_pychop.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,25 @@ def _test_against_abins(abins, rf_2d, setting, matrix):
abins._polyfits = {}
expected = abins.calculate_sigma(frequencies * MEV_TO_WAVENUMBER) * WAVENUMBER_TO_MEV
except LinAlgError:
# On Windows we get this error instead of passing NaN
# Make sure this library agrees it is a no-transmission situation.
with pytest.raises(NoTransmissionError):
rf_2d.get_resolution_function('PyChop_fit', chopper_package=setting, e_init=energy, chopper_frequency=chopper_frequency
)
return

if np.any(np.isnan(expected)):
# If chopper/energy settings block transmission, width via AbINS is NaN.
# This library should raise NoTransmissionError instead.
with pytest.raises(NoTransmissionError):
rf_2d.get_resolution_function('PyChop_fit', chopper_package=setting, e_init=energy, chopper_frequency=chopper_frequency)
else:
rf = rf_2d.get_resolution_function('PyChop_fit', chopper_package=setting, e_init=energy,
chopper_frequency=chopper_frequency)
actual = rf(frequencies)
return

rf = rf_2d.get_resolution_function('PyChop_fit', chopper_package=setting, e_init=energy,
chopper_frequency=chopper_frequency)
actual = rf(frequencies)

assert_allclose(actual, expected, rtol=1e-5)
assert_allclose(actual, expected, rtol=1e-5)


@pytest.fixture(scope='module',
Expand Down

0 comments on commit 4fc9ab8

Please sign in to comment.