Skip to content

Commit

Permalink
fixed warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolearyc committed Aug 11, 2024
1 parent bfbc2e4 commit 49e2f57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
12 changes: 6 additions & 6 deletions ramannoodle/polarizability/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ def _construct_and_add_interpolations(
f"due to symmetry, amplitude {duplicate} should not be specified"
)

if len(interpolation_x) <= interpolation_order:
raise InvalidDOFException(
f"insufficient points ({len(interpolation_x)}) available for "
f"{interpolation_order}-order interpolation"
)

# Warn user if amplitudes don't span zero
max_amplitude = np.max(interpolation_x)
min_amplitude = np.min(interpolation_x)
Expand All @@ -252,12 +258,6 @@ def _construct_and_add_interpolations(
DOFWarning,
)

if len(interpolation_x) <= interpolation_order:
raise InvalidDOFException(
f"insufficient points ({len(interpolation_x)}) available for "
f"{interpolation_order}-order interpolation"
)

sort_indices = np.argsort(interpolation_x)
try:
interpolations_to_add.append(
Expand Down
4 changes: 2 additions & 2 deletions test/tests/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_add_art(
"exception_type,in_reason",
[
(
"test/data/STO_RATTLED_OUTCAR",
"test/data/STO_RATTLED_OUTCAR", # This case gives a warning.
[0],
np.array([[1, 0, 0]]),
np.array([0.1]),
Expand Down Expand Up @@ -226,7 +226,7 @@ def test_add_art_from_files_exception(
exception_type: Type[Exception],
in_reason: str,
) -> None:
"""Test add_dof_from_files (exception)."""
"""Test add_art_from_files (exception)."""
ref_structure = outcar_ref_structure_fixture
model = ARTModel(ref_structure, np.zeros((3, 3)))
with pytest.raises(exception_type) as error:
Expand Down
33 changes: 12 additions & 21 deletions test/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ def test_add_dof(
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1]),
np.zeros((1, 3, 3)),
4,
np.array([-0.1, 0.1]),
np.zeros((2, 3, 3)),
5,
InvalidDOFException,
"insufficient points",
),
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1, 0.1]),
np.array([-0.1, 0.1]),
np.zeros((1, 3, 3)),
1,
ValueError,
Expand All @@ -94,26 +94,17 @@ def test_add_dof(
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1]),
np.zeros((2, 3, 3)),
1,
ValueError,
"polarizabilities has wrong shape",
),
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1]),
np.zeros((2, 3, 3)),
np.array([-0.1, 0.1]),
np.zeros((2, 5, 3)),
1,
ValueError,
"polarizabilities has wrong shape",
),
(
"test/data/STO_RATTLED_OUTCAR",
[[0], [0, 1]],
np.array([0.1]),
np.zeros((1, 3, 3)),
np.array([-0.1, 0.1]),
np.zeros((2, 3, 3)),
1,
InvalidDOFException,
"not orthogonal",
Expand Down Expand Up @@ -148,17 +139,17 @@ def test_add_dof(
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1]),
np.zeros((1, 3, 3)),
np.array([-0.1, 0.1]),
np.zeros((2, 3, 3)),
-1.6,
TypeError,
"interpolation_order should have type int, not float",
),
(
"test/data/STO_RATTLED_OUTCAR",
[[0]],
np.array([0.1, 0.1]),
np.zeros((2, 3, 3)),
np.array([-0.1, 0.1, 0.1]),
np.zeros((3, 3, 3)),
-1.6,
InvalidDOFException,
"due to symmetry, amplitude 0.1 should not be specified",
Expand Down

0 comments on commit 49e2f57

Please sign in to comment.