Skip to content

Commit

Permalink
Test for invalid structures
Browse files Browse the repository at this point in the history
  • Loading branch information
sstendahl committed Aug 30, 2023
1 parent 164bad1 commit 9acce71
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion hogben/tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from hogben.utils import fisher
from refnx.reflect import SLD as SLD_refnx
from refl1d.material import SLD as SLD_refl1d
from unittest.mock import patch
from unittest.mock import Mock, patch


@pytest.fixture
Expand Down Expand Up @@ -169,6 +169,34 @@ def test_reflectivity_profile_positive(sample_class,
q, r = sample._get_reflectivity_profile(0.005, 0.4, 500, 1, 1e-7, 2)
assert min(r) > 0

def test_reflectivity_invalid_structure():
"""
Test whether a RunTimeError is correctly given when an invalid sample
structure is used in get_reflectivity_profile
"""
sample = Mock(spec=None)
with pytest.raises(RuntimeError):
Sample._get_reflectivity_profile(sample, 0.005, 0.4, 500, 1,
1e-7, 2)

def test_sld_invalid_structure():
"""
Test whether a RunTimeError is correctly given when an invalid sample
structure is used in get_sld_profile
"""
sample = Mock(spec=None)
with pytest.raises(RuntimeError):
Sample._get_sld_profile(sample)

def test_vary_structure_invalid_structure():
"""
Test whether a RunTimeError is correctly given when an invalid sample
structure is used in _vary_structure
"""
structure = Mock(spec=None)
with pytest.raises(RuntimeError):
Sample._Sample__vary_structure(structure)

@pytest.mark.parametrize('sample_class', ("refnx_sample",
"refl1d_sample"))
def test_reflectivity_profile_length(sample_class,
Expand Down

0 comments on commit 9acce71

Please sign in to comment.