Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittest rook tester #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion developer_tools/rook.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[rook]
add_non_default_run_types = qsub
testers_dir = HERON/src/Testers
testers_dir = HERON/src/Testers, src/Testers
test_dir = tests
2 changes: 1 addition & 1 deletion run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ case $TEST_SET in
;;
esac

$PYTHON_COMMAND $SCRIPT_DIR/raven/rook/main.py --config-file=$SCRIPT_DIR/developer_tools/rook.ini --test-dir $TEST_DIR --testers-dir $RAVEN_DIR/scripts/TestHarness/testers,$RAVEN_DIR/../HERON/src/Testers "${ARGS[@]}"
$PYTHON_COMMAND $SCRIPT_DIR/raven/rook/main.py --config-file=$SCRIPT_DIR/developer_tools/rook.ini --test-dir $TEST_DIR --testers-dir $RAVEN_DIR/scripts/TestHarness/testers,$RAVEN_DIR/../HERON/src/Testers,$RAVEN_DIR/../src/Testers "${ARGS[@]}"

# store return codes individually (rc) and combined (ALL_PASS)
rc=$?
Expand Down
70 changes: 70 additions & 0 deletions src/Testers/UnittestTester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
import sys

FORCE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.append(FORCE_DIR)
from raven.scripts.TestHarness.testers.RavenPython import RavenPython
# clear scripts from path
sys.path.pop()

try:
import unittest
unittest_found = True
except ModuleNotFoundError or ImportError:
unittest_found = False

class Unittest(RavenPython):
"""
This class simplifies use of the unittest module for running unit tests through rook.
"""

@staticmethod
def get_valid_params():
"""
Return a list of valid parameters and their descriptions for this type
of test.
@ In, None
@ Out, params, _ValidParameters, the parameters for this class.
"""
params = RavenPython.get_valid_params()
# 'input' param can be test case or test suite; unittest will handle either when called
params.add_param('unittest_args', '', "Arguments to the unittest module")
return params

def __init__(self, name, params):
"""
Initializer for the class. Takes a String name and a dictionary params
@ In, name, string, name of the test.
@ In, params, dictionary, parameters for the class
@ Out, None.
"""
RavenPython.__init__(self, name, params)

def check_runnable(self):
"""
Checks if this test can be run.
@ In, None
@ Out, check_runnable, boolean, If True can run this test.
"""
if not unittest_found:
self.set_skip('skipped (required unittest module is not found)')
return False

return RavenPython.check_runnable(self)

def get_command(self):
"""
returns the command used by this tester.
@ In, None
@ Out, get_command, string, command to run.
"""
# If the test command has been specified, use it
if (command := self._get_test_command()) is not None:
return ' '.join([command, '-m unittest', self.specs["unittest_args"], self.specs["input"]])

# Otherwise, if the python command has been specified, use it
if len(self.specs["python_command"]) == 0:
pythonCommand = self._get_python_command()
else:
pythonCommand = self.specs["python_command"]
return ' '.join([pythonCommand, '-m unittest', self.specs["unittest_args"], self.specs["input"]])
36 changes: 18 additions & 18 deletions tests/unit_tests/tests
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
[Tests]
[./TestMinimalInput]
type = RavenPython
input = '-m unittest test_heron.TestMinimalInput'
type = Unittest
input = 'test_heron.TestMinimalInput'
[../]

[./TestExpandedInput1]
type = RavenPython
input = '-m unittest test_heron.TestExpandedInput1'
type = Unittest
input = 'test_heron.TestExpandedInput1'
[../]

[./TestExpandedInput2]
type = RavenPython
input = '-m unittest test_heron.TestExpandedInput2'
type = Unittest
input = 'test_heron.TestExpandedInput2'
[../]

[./TestNoComponentsNode]
type = RavenPython
input = '-m unittest test_heron.TestNoComponentsNode'
type = Unittest
input = 'test_heron.TestNoComponentsNode'
[../]

[./TestNoComponentNodes]
type = RavenPython
input = '-m unittest test_heron.TestNoComponentNodes'
type = Unittest
input = 'test_heron.TestNoComponentNodes'
[../]

[./TestMissingSubnodes]
type = RavenPython
input = '-m unittest test_heron.TestMissingSubnodes'
type = Unittest
input = 'test_heron.TestMissingSubnodes'
[../]

[./TestEmptyCompSetsFolder]
type = RavenPython
input = '-m unittest test_heron.TestEmptyCompSetsFolder'
type = Unittest
input = 'test_heron.TestEmptyCompSetsFolder'
[../]

[./TestCompSetsFolderWithBadJSON]
type = RavenPython
input = '-m unittest test_heron.TestCompSetsFolderWithBadJSON'
type = Unittest
input = 'test_heron.TestCompSetsFolderWithBadJSON'
[../]

[./TestCompSetsFolderMultFiles]
type = RavenPython
input = '-m unittest test_heron.TestCompSetsFolderMultFiles'
type = Unittest
input = 'test_heron.TestCompSetsFolderMultFiles'
[../]
[]
Loading