Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create poetry-test.yml #13

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/poetry-test.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
9 changes: 8 additions & 1 deletion tests/scalar/test_data_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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
from pygpe.scalar.wavefunction import ScalarWavefunction
from pygpe.shared.grid import Grid

FILENAME = "scalar_test.hdf5"
FILE_PATH = "data"
FILE_PATH = "."


def generate_wavefunction(
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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}"))
9 changes: 8 additions & 1 deletion tests/spinhalf/test_spinhalf_data_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import h5py
import numpy as np
from pathlib import Path

import pygpe.shared.data_manager_paths as dmp
from pygpe.shared.grid import Grid
from pygpe.spinhalf.data_manager import DataManager
from pygpe.spinhalf.wavefunction import SpinHalfWavefunction

FILENAME = "spinhalf_test.hdf5"
FILE_PATH = "data"
FILE_PATH = "."


def generate_wavefunction(
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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}"))
9 changes: 8 additions & 1 deletion tests/spinone/test_spinone_data_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import h5py
import numpy as np
from pathlib import Path

import pygpe.shared.data_manager_paths as dmp
from pygpe.shared.grid import Grid
from pygpe.spinone.data_manager import DataManager
from pygpe.spinone.wavefunction import SpinOneWavefunction

FILENAME = "spinone_test.hdf5"
FILE_PATH = "data"
FILE_PATH = "."


def generate_wavefunction(
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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}"))
9 changes: 8 additions & 1 deletion tests/spintwo/test_spintwo_data_manager.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import h5py
import numpy as np
from pathlib import Path

import pygpe.shared.data_manager_paths as dmp
from pygpe.shared.grid import Grid
from pygpe.spintwo.data_manager import DataManager
from pygpe.spintwo.wavefunction import SpinTwoWavefunction

FILENAME = "spintwo_test.hdf5"
FILE_PATH = "data"
FILE_PATH = "."


def generate_wavefunction(
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand Down Expand Up @@ -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}"))
Loading