octopus: old to new test API (#45143)

* octopus: old to new test API
* Minor simplifications and cleanup

---------

Co-authored-by: Tamara Dahlgren <dahlgren1@llnl.gov>
This commit is contained in:
AcriusWinter 2024-07-09 19:02:36 -07:00 committed by GitHub
parent aa911eca40
commit b237ee3689
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -316,54 +316,38 @@ def configure_args(self):
@run_after("install")
@on_package_attributes(run_tests=True)
def smoke_tests_after_install(self):
def benchmark_tests_after_install(self):
"""Function stub to run tests after install if desired
(for example through `spack install --test=root octopus`)
"""
self.smoke_tests()
self.test_version()
self.test_example()
self.test_he()
def test(self):
"""Entry point for smoke tests run through `spack test run octopus`."""
self.smoke_tests()
def smoke_tests(self):
"""Actual smoke tests for Octopus."""
#
# run "octopus --version"
#
exe = join_path(self.spec.prefix.bin, "octopus")
options = ["--version"]
purpose = "Check octopus can execute (--version)"
def test_version(self):
"""Check octopus can execute (--version)"""
# Example output:
#
# spack-v0.17.2$ octopus --version
# octopus 11.3 (git commit )
expected = ["octopus "]
self.run_test(
exe,
options=options,
expected=expected,
status=[0],
installed=False,
purpose=purpose,
skip_missing=False,
)
exe = which(self.spec.prefix.bin.octopus)
out = exe("--version", output=str.split, error=str.split)
assert "octopus " in out
def test_recipe(self):
"""run recipe example"""
# Octopus expects a file with name `inp` in the current working
# directory to read configuration information for a simulation run from
# that file. We copy the relevant configuration file in a dedicated
# subfolder for each test.
# subfolder for the test.
#
# As we like to be able to run these tests also with the
# `spack install --test=root` command, we cannot rely on
# self.test_suite.current_test_data_dir, and need to copy the test
# input files manually (see below).
#
# run recipe example
#
expected = [
"Running octopus",
"CalculationMode = recipe",
@ -371,24 +355,27 @@ def smoke_tests(self):
"recipe leads to an edible dish, " 'for it is clearly "system-dependent".',
"Calculation ended on",
]
options = []
purpose = "Run Octopus recipe example"
with working_dir("example-recipe", create=True):
print("Current working directory (in example-recipe)")
fs.copy(join_path(os.path.dirname(__file__), "test", "recipe.inp"), "inp")
self.run_test(
exe,
options=options,
expected=expected,
status=[0],
installed=False,
purpose=purpose,
skip_missing=False,
)
exe = which(self.spec.prefix.bin.octopus)
out = exe(output=str.split, error=str.split)
check_outputs(expected, out)
def test_he(self):
"""run He example"""
# Octopus expects a file with name `inp` in the current working
# directory to read configuration information for a simulation run from
# that file. We copy the relevant configuration file in a dedicated
# subfolder for the test.
#
# run He example
#
# As we like to be able to run these tests also with the
# `spack install --test=root` command, we cannot rely on
# self.test_suite.current_test_data_dir, and need to copy the test
# input files manually (see below).
expected = [
"Running octopus",
"Info: Starting calculation mode.",
@ -397,17 +384,10 @@ def smoke_tests(self):
"Info: Writing states.",
"Calculation ended on",
]
options = []
purpose = "Run tiny calculation for He"
with working_dir("example-he", create=True):
print("Current working directory (in example-he)")
fs.copy(join_path(os.path.dirname(__file__), "test", "he.inp"), "inp")
self.run_test(
exe,
options=options,
expected=expected,
status=[0],
installed=False,
purpose=purpose,
skip_missing=False,
)
exe = which(self.spec.prefix.bin.octopus)
out = exe(output=str.split, error=str.split)
check_outputs(expected, out)