Skip to content

Commit

Permalink
Merge branch 'main' and its testing improvements into add_let
Browse files Browse the repository at this point in the history
  • Loading branch information
Rastislav Turanyi committed Nov 22, 2024
2 parents f36e3dc + 4bf9324 commit fbd134e
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 92 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run tests

on: [push,workflow_dispatch]

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Setup Miniconda
uses: conda-incubator/[email protected]
with:
python-version: '3.10'
channels: conda-forge
miniforge-version: "latest"

- name: Install tox
shell: bash -el {0}
run: mamba install tox

- name: Test with tox
shell: bash -el {0}
run: tox
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = 'resolutions_functions'
Expand Down Expand Up @@ -27,7 +28,9 @@ dev = [
]
test = [
"pytest >= 8.3.2",
"mantid >= 6.10.0"
"mantid >= 6.10.0",
"pychop @ git+https://github.com/mducle/pychop.git",
"more_itertools >= 10.5.0",
]

[project.urls]
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file.
20 changes: 15 additions & 5 deletions tests/integration_tests/test_lagrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ def lagrange_abins_plus_rf_abins_resolution_function(lagrange_rf, request):
return abins, rf


@pytest.mark.parametrize('frequencies',
[np.arange(10, 400, 10), np.arange(100, 1000, 50)])
def test_lagrange_against_abins(frequencies,
lagrange_abins_plus_rf_abins_resolution_function):
@pytest.mark.parametrize(
"frequencies",
[
pytest.param(np.arange(100, 1000, 50), id="high frequencies: 100:1000:50"),
pytest.param(
np.arange(10, 100, 10),
id="low frequencies: 10:100:10",
marks=pytest.mark.xfail(reason="LAGRANGE low frequencies to be fixed in Abins"),
),
],
)
def test_lagrange_against_abins(
frequencies, lagrange_abins_plus_rf_abins_resolution_function
):
abins, rf = lagrange_abins_plus_rf_abins_resolution_function

actual = rf(frequencies)
expected = abins.get_sigma(frequencies * MEV_TO_WAVENUMBER) * WAVENUMBER_TO_MEV

assert_allclose(actual, expected)
assert_allclose(actual, expected, rtol=1e-5)
31 changes: 19 additions & 12 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,18 +71,24 @@ 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:
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)

assert_allclose(actual, expected, rtol=1e-5)
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

except Warning:
# 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

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)


@pytest.fixture(scope='module',
Expand Down
Empty file added tests/unit_tests/__init__.py
Empty file.
Loading

0 comments on commit fbd134e

Please sign in to comment.