Skip to content

Commit

Permalink
octopus: old to new test API (spack#45143)
Browse files Browse the repository at this point in the history
* octopus: old to new test API
* Minor simplifications and cleanup

---------

Co-authored-by: Tamara Dahlgren <[email protected]>
  • Loading branch information
AcriusWinter and tldahlgren authored Jul 10, 2024
1 parent aa911ec commit b237ee3
Showing 1 changed file with 34 additions and 54 deletions.
88 changes: 34 additions & 54 deletions var/spack/repos/builtin/packages/octopus/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,79 +316,66 @@ 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",
"DISCLAIMER: The authors do not " "guarantee that the implementation",
"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.",
Expand All @@ -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)

0 comments on commit b237ee3

Please sign in to comment.