Skip to content

Commit

Permalink
refactor requires_dbase_version marker
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes committed Jan 17, 2024
1 parent 2d5c9a5 commit 2c307db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
26 changes: 19 additions & 7 deletions fiasco/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np
import pathlib
import pytest

from packaging.version import Version

from fiasco.util import check_database, read_chianti_version

# Force MPL to use non-gui backends for testing.
Expand Down Expand Up @@ -160,14 +163,23 @@ def requires_dbase_version(request, dbase_version):
# NOTE: Fixtures that depend on other fixtures are awkward to implement.
# See this SO answer: https://stackoverflow.com/a/28198398
if marker := request.node.get_closest_marker('requires_dbase_version'):
version_condition = marker.args[0]
# NOTE: This currently only works for major versions. If we
# need tests that discriminate between minor versions or patches,
# this logic will need to be added.
conditional = f'{dbase_version["major"]}{version_condition}'
allowed_dbase_version = eval(conditional)
# NOTE: This has to have a space between the operator and the target
if len(marker.args) != 2:
raise ValueError("Arguments must contain a condition and a version number, e.g. '<', '8.0.7'")

Check warning on line 168 in fiasco/conftest.py

View check run for this annotation

Codecov / codecov/patch

fiasco/conftest.py#L168

Added line #L168 was not covered by tests
operator, target_version = marker.args
op_dict = {'<': np.less,
'<=': np.less_equal,
'>': np.greater,
'>=': np.greater_equal,
'=': np.equal,
'!=': np.not_equal}
if operator not in op_dict:
raise ValueError(f'''{operator} is not a supported comparison operation.

Check warning on line 177 in fiasco/conftest.py

View check run for this annotation

Codecov / codecov/patch

fiasco/conftest.py#L177

Added line #L177 was not covered by tests
Must be one of {list(op_dict.keys())}.''')
target_version = Version(target_version)
allowed_dbase_version = op_dict[operator](dbase_version, target_version)
if not allowed_dbase_version:
pytest.skip(f'Test skipped because current dbase version {conditional}.')
pytest.skip(f'Skip because database version {dbase_version} is not {operator} {target_version}.')


def pytest_configure(config):
Expand Down
4 changes: 2 additions & 2 deletions fiasco/io/sources/tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
'fe_2.trparams',
'fe_12.drparams',
'al_3.diparams',
pytest.param('fe_23.auto', marks=pytest.mark.requires_dbase_version('>=9')),
pytest.param('fe_23.rrlvl', marks=pytest.mark.requires_dbase_version('>=9')),
pytest.param('fe_23.auto', marks=pytest.mark.requires_dbase_version('>=', '9')),
pytest.param('fe_23.rrlvl', marks=pytest.mark.requires_dbase_version('>=', '9')),
])
def test_ion_sources(ascii_dbase_root, filename,):
parser = fiasco.io.Parser(filename, ascii_dbase_root=ascii_dbase_root)
Expand Down
2 changes: 1 addition & 1 deletion fiasco/tests/test_ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def test_level_populations_normalized(pops_no_correction, pops_with_correction):
assert u.allclose(pops_no_correction.sum(axis=1), 1, atol=None, rtol=1e-15)


@pytest.mark.requires_dbase_version('<=8')
@pytest.mark.requires_dbase_version('<=','8')
def test_level_populations_correction(fe20, pops_no_correction, pops_with_correction):
# Test level-resolved correction applied to correct levels
i_corrected = np.unique(np.concatenate([fe20._cilvl['upper_level'], fe20._reclvl['upper_level']]))
Expand Down

0 comments on commit 2c307db

Please sign in to comment.