Skip to content

Commit

Permalink
Refactor tests to use monkeypatch for setting SYSTEM
Browse files Browse the repository at this point in the history
Replaced `with patch` context managers with `monkeypatch.setattr` in all
TestModules test cases to improve code readability and consistency.

Added new test for "salish" system to ensure future-proofing and full coverage
of available systems.
  • Loading branch information
douglatornell committed Nov 12, 2024
1 parent 732f56d commit 7b0a114
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3121,10 +3121,19 @@ def test_unknown_system(self):
modules = salishsea_cmd.run._modules()
assert modules == ""

def test_salish(self, monkeypatch):
monkeypatch.setattr(salishsea_cmd.run, "SYSTEM", "salish")

modules = salishsea_cmd.run._modules()

assert modules == ""

@pytest.mark.parametrize("system", ["beluga", "cedar", "graham"])
def test_beluga_cedar_graham(self, system):
with patch("salishsea_cmd.run.SYSTEM", system):
modules = salishsea_cmd.run._modules()
def test_beluga_cedar_graham(self, system, monkeypatch):
monkeypatch.setattr(salishsea_cmd.run, "SYSTEM", system)

modules = salishsea_cmd.run._modules()

expected = textwrap.dedent(
"""\
module load StdEnv/2020
Expand All @@ -3134,9 +3143,11 @@ def test_beluga_cedar_graham(self, system):
assert modules == expected

@pytest.mark.parametrize("system", ("orcinus", "seawolf1", "seawolf2", "seawolf3"))
def test_orcinus(self, system):
with patch("salishsea_cmd.run.SYSTEM", system):
modules = salishsea_cmd.run._modules()
def test_orcinus(self, system, monkeypatch):
monkeypatch.setattr(salishsea_cmd.run, "SYSTEM", system)

modules = salishsea_cmd.run._modules()

expected = textwrap.dedent(
"""\
module load intel
Expand All @@ -3151,19 +3162,23 @@ def test_orcinus(self, system):
assert modules == expected

@pytest.mark.parametrize("system", ["delta", "sigma", "omega"])
def test_optimum(self, system):
with patch("salishsea_cmd.run.SYSTEM", system):
modules = salishsea_cmd.run._modules()
def test_optimum(self, system, monkeypatch):
monkeypatch.setattr(salishsea_cmd.run, "SYSTEM", system)

modules = salishsea_cmd.run._modules()

expected = textwrap.dedent(
"""\
module load OpenMPI/2.1.6/GCC/SYSTEM
"""
)
assert modules == expected

def test_sockeye(self):
with patch("salishsea_cmd.run.SYSTEM", "sockeye"):
modules = salishsea_cmd.run._modules()
def test_sockeye(self, monkeypatch):
monkeypatch.setattr(salishsea_cmd.run, "SYSTEM", "sockeye")

modules = salishsea_cmd.run._modules()

expected = textwrap.dedent(
"""\
module load gcc/5.5.0
Expand Down

0 comments on commit 7b0a114

Please sign in to comment.