Skip to content

Commit

Permalink
Add parametrized testing for get_variables
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed May 22, 2024
1 parent f7a4dc1 commit 3d3b639
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# limitations under the License.
#

import pytest
import numpy as np

from nomad.units import ureg
Expand Down Expand Up @@ -67,14 +68,26 @@ def test_is_not_representative():
# ! Missing test for RusselSandersState (but this class will probably be deprecated)


def test_get_variables():
@pytest.mark.parametrize(
'variables, result, result_length',
[
(None, [], 0),
([], [], 0),
([Temperature()], [], 0),
([Temperature(), Energy(n_points=4)], [Energy(n_points=4)], 1),
(
[Temperature(), Energy(n_points=2), Energy(n_points=10)],
[Energy(n_points=2), Energy(n_points=10)],
2,
),
# TODO add testing when we have variables which inherit from another variable
],
)
def test_get_variables(variables: list, result: list, result_length: int):
"""
Test the `get_variables` utility function
"""
variables = [
Temperature(points=list(range(-3, 4)) * ureg.kelvin),
Energy(points=list(range(-3, 4)) * ureg.joule),
]
energies = get_variables(variables, Energy)
assert len(energies) == 1
assert np.allclose(energies[0].points.magnitude, [-3, -2, -1, 0, 1, 2, 3])
assert len(energies) == result_length
for i, energy in enumerate(energies): # asserting energies == result does not work
assert energy.n_points == result[i].n_points

0 comments on commit 3d3b639

Please sign in to comment.