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