Skip to content

Commit

Permalink
pylbo: added unit tests for derived eigenfunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
n-claes committed Aug 17, 2021
1 parent cffb164 commit e227766
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/pylbo_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def datv0():
return utils / "v0_datfile_efs.dat"


@pytest.fixture
def datv1():
return utils / "v1_datfile_matrices.dat"


@pytest.fixture
def datv112_eta():
return utils / "v1.1.2_datfile_eta.dat"


@pytest.mark.timeout(5)
@pytest.fixture
def ds_v090():
Expand Down Expand Up @@ -128,6 +138,12 @@ def ds_v114_subset():
return pylbo.load(utils / "v1.1.4_datfile_subset.dat")


@pytest.mark.timeout(5)
@pytest.fixture
def ds_v114_subset_defs():
return pylbo.load(utils / "v1.1.4_datfile_subset_defs.dat")


@pytest.mark.timeout(5)
@pytest.fixture
def ds_v114():
Expand Down
29 changes: 29 additions & 0 deletions tests/pylbo_tests/test_eigenfunction_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,32 @@ def test_subset_eigenfunction_retrieval_outside(ds_v114_subset):
assert ev is not None
assert not np.isnan(ev)
assert efs is None


def test_subset_derived_efs_present(ds_v114_subset_defs):
assert ds_v114_subset_defs.ef_subset
assert ds_v114_subset_defs.pp_names is not None


def test_subset_derived_efs_retrieval_inside(ds_v114_subset_defs):
guess = 10.0 - 0.1j
_, ev = ds_v114_subset_defs.get_nearest_eigenvalues(ev_guesses=guess)
(efs,) = ds_v114_subset_defs.get_eigenfunctions(ev_guesses=guess)
(defs,) = ds_v114_subset_defs.get_postprocessed(ev_guesses=guess)
assert ev is not None
assert not np.isnan(ev)
assert efs is not None
assert defs is not None
assert isinstance(defs, dict)
assert np.isclose(efs["eigenvalue"], ev)
assert np.isclose(defs["eigenvalue"], ev)
assert set(ds_v114_subset_defs.pp_names).issubset(defs.keys())


def test_subset_derived_efs_retrieval_outside(ds_v114_subset_defs):
guess = 35.0 - 0.01j
_, ev = ds_v114_subset_defs.get_nearest_eigenvalues(ev_guesses=guess)
(defs,) = ds_v114_subset_defs.get_postprocessed(ev_guesses=guess)
assert ev is not None
assert not np.isnan(ev)
assert defs is None
22 changes: 22 additions & 0 deletions tests/pylbo_tests/test_loading.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import numpy as np
import pylbo


Expand All @@ -21,6 +22,27 @@ def test_load_invalid(datv0):
pylbo.load([datv0, datv0])


def test_load_no_version(datv0):
ds = pylbo.load(datv0)
assert ds.legolas_version == "0.0.0"


def test_load_series_empty():
with pytest.raises(ValueError):
pylbo.load_series([])


def test_load_multiple_equilibria(datv1, datv112_eta):
with pytest.raises(ValueError):
pylbo.load_series([datv1, datv112_eta])


def test_load_logfile(logv0):
eigenvals = pylbo.load_logfile(logv0)
assert isinstance(eigenvals, np.ndarray)


def test_load_logfile_and_sort(logv0):
eigenvals = pylbo.load_logfile(logv0, sort=True)
assert isinstance(eigenvals, np.ndarray)
assert np.all(eigenvals[:-1] <= eigenvals[1:])
Binary file not shown.

0 comments on commit e227766

Please sign in to comment.