diff --git a/.github/workflows/poetry-test.yml b/.github/workflows/poetry-test.yml new file mode 100644 index 0000000..f4a163c --- /dev/null +++ b/.github/workflows/poetry-test.yml @@ -0,0 +1,43 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions using Poetry + +name: poetry-test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + ci: + strategy: + fail-fast: false + matrix: + python-version: ["3.10", "3.11", "3.12"] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + # Cache the installation of Poetry itself. This prevents the workflow + # from installing Poetry every time, which can be slow + - name: Cache poetry install + uses: actions/cache@v2 + with: + path: ~/.local + key: poetry-1.8.2-0 + + - name: Run image + uses: abatilo/actions-poetry@v3.0.0 + with: + version: 1.8.2 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Install project dependencies + run: poetry install --no-interaction + + - name: Run tests + run: poetry run pytest -v diff --git a/tests/scalar/test_data_manager.py b/tests/scalar/test_data_manager.py index 1f659ae..21a09a3 100644 --- a/tests/scalar/test_data_manager.py +++ b/tests/scalar/test_data_manager.py @@ -1,5 +1,6 @@ import h5py import numpy as np +from pathlib import Path import pygpe.shared.data_manager_paths as dmp from pygpe.scalar.data_manager import DataManager @@ -7,7 +8,7 @@ from pygpe.shared.grid import Grid FILENAME = "scalar_test.hdf5" -FILE_PATH = "data" +FILE_PATH = "." def generate_wavefunction( @@ -49,6 +50,8 @@ def test_data_manager_creation(): params = generate_parameters() DataManager(FILENAME, FILE_PATH, wavefunction, params) + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_parameters(): """Tests whether condensate parameters are correctly saved to file.""" @@ -61,6 +64,8 @@ def test_correct_parameters(): for key, value in params.items(): assert value == file[f"{dmp.PARAMETERS}/{key}"][...] + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_wavefunction(): """Tests whether the condensate wavefunction is correctly saved to file.""" @@ -71,3 +76,5 @@ def test_correct_wavefunction(): with h5py.File(f"{FILE_PATH}/{FILENAME}", "r") as file: saved_wavefunction = np.asarray(file[f"{dmp.SCALAR_WAVEFUNCTION}"][:, :, 0]) np.testing.assert_array_almost_equal(wavefunction.component, saved_wavefunction) + + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) diff --git a/tests/spinhalf/test_spinhalf_data_manager.py b/tests/spinhalf/test_spinhalf_data_manager.py index 1350694..0d7c37f 100644 --- a/tests/spinhalf/test_spinhalf_data_manager.py +++ b/tests/spinhalf/test_spinhalf_data_manager.py @@ -1,5 +1,6 @@ import h5py import numpy as np +from pathlib import Path import pygpe.shared.data_manager_paths as dmp from pygpe.shared.grid import Grid @@ -7,7 +8,7 @@ from pygpe.spinhalf.wavefunction import SpinHalfWavefunction FILENAME = "spinhalf_test.hdf5" -FILE_PATH = "data" +FILE_PATH = "." def generate_wavefunction( @@ -57,6 +58,8 @@ def test_data_manager_creation(): params = generate_parameters() DataManager(FILENAME, FILE_PATH, wavefunction, params) + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_parameters(): """Tests whether condensate parameters are correctly saved to file.""" @@ -69,6 +72,8 @@ def test_correct_parameters(): for key, value in params.items(): assert value == file[f"{dmp.PARAMETERS}/{key}"][...] + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_wavefunction(): """Tests whether the condensate wavefunction is correctly saved to file.""" @@ -89,3 +94,5 @@ def test_correct_wavefunction(): np.testing.assert_array_almost_equal( wavefunction.minus_component, saved_wavefunction_minus ) + + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) diff --git a/tests/spinone/test_spinone_data_manager.py b/tests/spinone/test_spinone_data_manager.py index 8e79657..65deff1 100644 --- a/tests/spinone/test_spinone_data_manager.py +++ b/tests/spinone/test_spinone_data_manager.py @@ -1,5 +1,6 @@ import h5py import numpy as np +from pathlib import Path import pygpe.shared.data_manager_paths as dmp from pygpe.shared.grid import Grid @@ -7,7 +8,7 @@ from pygpe.spinone.wavefunction import SpinOneWavefunction FILENAME = "spinone_test.hdf5" -FILE_PATH = "data" +FILE_PATH = "." def generate_wavefunction( @@ -58,6 +59,8 @@ def test_data_manager_creation(): params = generate_parameters() DataManager(FILENAME, FILE_PATH, wavefunction, params) + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_parameters(): """Tests whether condensate parameters are correctly saved to file.""" @@ -70,6 +73,8 @@ def test_correct_parameters(): for key, value in params.items(): assert value == file[f"{dmp.PARAMETERS}/{key}"][...] + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_wavefunction(): """Tests whether the condensate wavefunction is correctly saved to file.""" @@ -96,3 +101,5 @@ def test_correct_wavefunction(): np.testing.assert_array_almost_equal( wavefunction.minus_component, saved_wavefunction_minus ) + + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) diff --git a/tests/spintwo/test_spintwo_data_manager.py b/tests/spintwo/test_spintwo_data_manager.py index db0be9b..87f1b35 100644 --- a/tests/spintwo/test_spintwo_data_manager.py +++ b/tests/spintwo/test_spintwo_data_manager.py @@ -1,5 +1,6 @@ import h5py import numpy as np +from pathlib import Path import pygpe.shared.data_manager_paths as dmp from pygpe.shared.grid import Grid @@ -7,7 +8,7 @@ from pygpe.spintwo.wavefunction import SpinTwoWavefunction FILENAME = "spintwo_test.hdf5" -FILE_PATH = "data" +FILE_PATH = "." def generate_wavefunction( @@ -59,6 +60,8 @@ def test_data_manager_creation(): params = generate_parameters() DataManager(FILENAME, FILE_PATH, wavefunction, params) + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_parameters(): """Tests whether condensate parameters are correctly saved to file.""" @@ -71,6 +74,8 @@ def test_correct_parameters(): for key, value in params.items(): assert value == file[f"{dmp.PARAMETERS}/{key}"][...] + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}")) + def test_correct_wavefunction(): """Tests whether the condensate wavefunction is correctly saved to file.""" @@ -109,3 +114,5 @@ def test_correct_wavefunction(): np.testing.assert_array_almost_equal( wavefunction.minus2_component, saved_wavefunction_minus2 ) + + Path.unlink(Path(f"{FILE_PATH}/{FILENAME}"))