Skip to content

Commit

Permalink
re-enable pylbo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n-claes committed Jul 8, 2021
1 parent e1f5c70 commit 515d366
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 34 deletions.
27 changes: 3 additions & 24 deletions .github/workflows/pylbo_core.yml → .github/workflows/pylbo.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: pylbo-core
name: pylbo

on:
push:
Expand Down Expand Up @@ -53,32 +53,11 @@ jobs:
- name: Install python dependencies
run: |
python -m pip install --upgrade pip
pip install pytest numpy matplotlib f90nml tqdm psutil pytest-mpl pytest-timeout
pip install pytest pytest-cov
cd post_processing
python setup.py develop
- name: Install Legolas dependencies
run: |
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt-get install gfortran-9
sudo apt-get -y install cmake
sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev
gfortran-9 --version
cmake --version
- name: Compile Legolas
run: sh setup_tools/buildlegolas.sh

- name: Test Pylbo core
run: |
cd tests/pylbo_tests
pytest --mpl --mpl-results-path=results --verbose
- name: Archive failed logs
uses: actions/upload-artifact@v1
if: failure()
with:
name: failed_logs
path: tests/pylbo_tests/results
pytest -v
71 changes: 61 additions & 10 deletions tests/pylbo_tests/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import f90nml
import pytest
import numpy as np
from pathlib import Path
from pylbo.automation.generator import ParfileGenerator

Expand All @@ -20,37 +22,86 @@ def test_outputdir_invalid():
ParfileGenerator({}, output_dir="invalid_dir")


def test_invalid_dict_type(tmp_path):
gen = ParfileGenerator({"gridpoints": 100.5}, output_dir=tmp_path)
def test_invalid_dict_type():
gen = ParfileGenerator({"gridpoints": 100.5})
with pytest.raises(TypeError):
gen.create_namelist_from_dict()


def test_unknown_namelist_item(tmp_path):
def test_unknown_namelist_item():
from pylbo.exceptions import ParfileGenerationError

gen = ParfileGenerator({"gridpoints": 10, "unknown_item": 5}, output_dir=tmp_path)
gen = ParfileGenerator({"gridpoints": 10, "unknown_item": 5})
with pytest.raises(ParfileGenerationError):
gen.create_namelist_from_dict()


def test_invalid_nb_runs(tmp_path):
def test_invalid_nb_runs():
from pylbo.exceptions import ParfileGenerationError

gen = ParfileGenerator(
{"gridpoints": [50, 100], "number_of_runs": 1}, output_dir=tmp_path
)
gen = ParfileGenerator({"gridpoints": [50, 100], "number_of_runs": 1})
with pytest.raises(ParfileGenerationError):
gen.create_namelist_from_dict()


def test_savelist_not_present(tmp_path):
import f90nml

gen = ParfileGenerator(
{"gridpoints": 100, "equilibrium_type": "adiabatic_homo"}, output_dir=tmp_path
)
gen.create_namelist_from_dict()
parfile = gen.generate_parfiles()
parfile_dict = f90nml.read(*parfile)
assert "savelist" in parfile_dict.keys()


def test_paramlist_present():
gen = ParfileGenerator(
{
"gridpoints": 50,
"equilibrium_type": "adiabatic_homo",
"parameters": {"k2": 2, "k3": 0, "cte_T0": 5},
},
)
gen.create_namelist_from_dict()
assert "paramlist" in gen.container.keys()
for key, value in zip(("k2", "k3", "cte_T0"), ([2], [0], [5])):
assert gen.container["paramlist"].get(key) == value


def test_nb_runs():
gen = ParfileGenerator(
{
"gridpoints": [50, 80, 150],
"number_of_runs": 3,
"equilibrium_type": "adiabatic_homo",
},
)
gen.create_namelist_from_dict()
assert gen.container["gridlist"].get("gridpoints") == [50, 80, 150]
assert (
gen.container["equilibriumlist"].get("equilibrium_type")
== ["adiabatic_homo"] * 3
)


def test_sigma_complex():
gen = ParfileGenerator({"solver": "arnoldi", "sigma": 5.0})
gen.create_namelist_from_dict()
sigma = gen.container["solvelist"].get("sigma")[0]
assert isinstance(sigma, complex)
assert np.isclose(sigma, 5.0 + 0j)


def test_logfile_name(tmp_path):
gen = ParfileGenerator(
{
"gridpoints": 50,
"equilibrium_type": "user_defined",
"basename_logfile": "mylog",
},
output_dir=tmp_path,
)
gen.create_namelist_from_dict()
parfile = gen.generate_parfiles()
parfile_dict = f90nml.read(*parfile)
assert parfile_dict["savelist"].get("basename_logfile") == "mylog"

0 comments on commit 515d366

Please sign in to comment.