Skip to content

Commit

Permalink
Fix: change DataManager file path in tests to current directory
Browse files Browse the repository at this point in the history
This is to ensure compatibility when running pytest from a fresh environment.
  • Loading branch information
wheelerMT committed Mar 23, 2024
1 parent 17a92c9 commit e6b712f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
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}"))

0 comments on commit e6b712f

Please sign in to comment.