Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Jan 14, 2025
1 parent 301cba0 commit 10fc3b0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 90 deletions.
90 changes: 0 additions & 90 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,96 +150,6 @@ def test_cartesian_and_surface_flux_warning(quantity, sys):
my_model.initialise()


@pytest.mark.parametrize(
"quantity",
[
F.AverageSurfaceCylindrical(field="solute", surface=1),
F.AverageVolumeCylindrical(field="solute", volume=1),
],
)
@pytest.mark.parametrize("sys", ["cartesian", "spherical"])
def test_cylindrical_quantities_warning(quantity, sys):
"""
Creates a Simulation object and checks that, if either a cartesian
or spherical meshes are given with a AverageSurfaceCylindrical, a warning is raised.
Args:
sys (str): type of the coordinate system
"""
# build
my_model = F.Simulation()
my_model.mesh = F.MeshFromVertices([1, 2, 3], type=sys)
my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = F.Temperature(100)
my_model.dt = F.Stepsize(initial_value=3)
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=4
)

derived_quantities = F.DerivedQuantities([quantity])
my_model.exports = [derived_quantities]

# test
with pytest.warns(UserWarning, match=f"may not work as intended for {sys} meshes"):
my_model.initialise()


def test_avg_surf_spherical_quantities_warning():
"""
Creates a Simulation object and checks that, if a cylindrical
mesh is given with a AverageSurfaceSpherical, a warning is raised.
"""
# build
my_model = F.Simulation()
my_model.mesh = F.MeshFromVertices([1, 2, 3], type="cylindrical")
my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = F.Temperature(100)
my_model.dt = F.Stepsize(initial_value=3)
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=4
)

derived_quantities = F.DerivedQuantities(
[F.AverageSurfaceSpherical(field="solute", surface=1)]
)
my_model.exports = [derived_quantities]

# test
with pytest.warns(
UserWarning, match=f"may not work as intended for cylindrical meshes"
):
my_model.initialise()


@pytest.mark.parametrize("sys", ["cartesian", "cylindrical"])
def test_avg_volume_spherical_quantities_warning(sys):
"""
Creates a Simulation object and checks that, if either a cylindrical or
cartesian meshes are given with a AverageVolumeSpherical, a warning is raised.
Args:
sys (str): type of the coordinate system
"""
# build
my_model = F.Simulation()
my_model.mesh = F.MeshFromVertices([1, 2, 3], type=sys)
my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = F.Temperature(100)
my_model.dt = F.Stepsize(initial_value=3)
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=4
)

derived_quantities = F.DerivedQuantities(
[F.AverageVolumeSpherical(field="solute", volume=1)]
)
my_model.exports = [derived_quantities]

# test
with pytest.warns(UserWarning, match=f"may not work as intended for {sys} meshes"):
my_model.initialise()


@pytest.mark.parametrize(
"value",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,21 @@ def test_average_surface_spherical_title_no_units_temperature():

my_export = AverageSurfaceSpherical("T", 9)
assert my_export.title == "Average T surface 9 (K)"


def test_avg_surf_cylindrical_allow_meshes():
"""A simple test to check cylindrical meshes are the only
meshes allowed when using AverageSurfaceCylindrical"""

my_export = AverageSurfaceCylindrical("solute", 2)

assert my_export.allowed_meshes == ["cylindrical"]


def test_avg_surf_spherical_allow_meshes():
"""A simple test to check spherical meshes are one of the
meshes allowed when using AverageSurfaceSpherical"""

my_export = AverageSurfaceSpherical("T", 6)

assert "spherical" in my_export.allowed_meshes
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,21 @@ def test_average_volume_spherical_title_no_units_temperature():

my_export = AverageVolumeSpherical("T", 9)
assert my_export.title == "Average T volume 9 (K)"


def test_avg_vol_cylindrical_allow_meshes():
"""A simple test to check cylindrical meshes are the only
meshes allowed when using AverageVolumeCylindrical"""

my_export = AverageVolumeCylindrical("solute", 3)

assert my_export.allowed_meshes == ["cylindrical"]


def test_avg_vol_spherical_allow_meshes():
"""A simple test to check cylindrical meshes are the only
meshes allowed when using AverageVolumeSpherical"""

my_export = AverageVolumeSpherical("solute", 5)

assert my_export.allowed_meshes == ["spherical"]

0 comments on commit 10fc3b0

Please sign in to comment.