Skip to content

Commit

Permalink
Detect PyChop Warning in Abins integration test
Browse files Browse the repository at this point in the history
This is a bit cleaner than having separate checks for different
OS/Library situations
  • Loading branch information
ajjackson committed Nov 11, 2024
1 parent 4c7023e commit 3069ae2
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions tests/integration_tests/test_pychop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
import warnings

import numpy as np
from numpy.linalg.linalg import LinAlgError
Expand Down Expand Up @@ -70,28 +71,23 @@ def _test_against_abins(abins, rf_2d, setting, matrix):
abins._pychop_instrument.chopper_system.setFrequency(chopper_frequency)
abins._pychop_instrument.frequency = chopper_frequency

try:
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
abins._polyfits = {}

with warnings.catch_warnings():
warnings.filterwarnings("error", message="PyChop: tchop\(\): No transmission.*")
try:
expected = abins.calculate_sigma(frequencies * MEV_TO_WAVENUMBER) * WAVENUMBER_TO_MEV

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)
return
except Warning:
# Make sure this library agrees it is a no-transmission situation.
with pytest.raises(NoTransmissionError):
dg rf_2d.get_resolution_function('PyChop_fit', chopper_package=setting, e_init=energy, chopper_frequency=chopper_frequency
)
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)


Expand Down

0 comments on commit 3069ae2

Please sign in to comment.