diff --git a/.github/workflows/pylbo_core.yml b/.github/workflows/pylbo.yml similarity index 68% rename from .github/workflows/pylbo_core.yml rename to .github/workflows/pylbo.yml index 5053720e..9504f693 100644 --- a/.github/workflows/pylbo_core.yml +++ b/.github/workflows/pylbo.yml @@ -1,4 +1,4 @@ -name: pylbo-core +name: pylbo on: push: @@ -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 diff --git a/tests/pylbo_tests/test_generator.py b/tests/pylbo_tests/test_generator.py index a84a6afd..de8aeb77 100644 --- a/tests/pylbo_tests/test_generator.py +++ b/tests/pylbo_tests/test_generator.py @@ -1,4 +1,6 @@ +import f90nml import pytest +import numpy as np from pathlib import Path from pylbo.automation.generator import ParfileGenerator @@ -20,33 +22,29 @@ 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 ) @@ -54,3 +52,56 @@ def test_savelist_not_present(tmp_path): 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"