CIME.tests.test_unit_cs_status.TestCsStatus
- class CIME.tests.test_unit_cs_status.TestCsStatus(methodName='runTest')[source]
Bases:
CustomAssertionsTestStatus
Methods
__init__
Create an instance of the class that will use the named test method when executed.
Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).
Add a function, with arguments, to be called when the test is completed.
Add a type specific assertEqual style function to compare a type.
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Asserts that two iterables have the same elements, the same number of times, without regard to order.
assertDictEqual
Fail if the two objects are unequal as determined by the '==' operator.
Check that the expression is false.
Just like self.assertTrue(a > b), but with a nicer default message.
Just like self.assertTrue(a >= b), but with a nicer default message.
Just like self.assertTrue(a in b), but with a nicer default message.
Just like self.assertTrue(a is b), but with a nicer default message.
Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
Same as self.assertTrue(obj is None), with a nicer default message.
Just like self.assertTrue(a is not b), but with a nicer default message.
Included for symmetry with assertIsNone.
Just like self.assertTrue(a < b), but with a nicer default message.
Just like self.assertTrue(a <= b), but with a nicer default message.
A list-specific equality assertion.
Fail unless a log message of level level or higher is emitted on logger_name or its children.
Assert that two multi-line strings are equal.
Fail unless no log messages of level level or higher are emitted on logger_name or its children.
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Fail if the two objects are equal as determined by the '!=' operator.
Just like self.assertTrue(a not in b), but with a nicer default message.
Included for symmetry with assertIsInstance.
Fail the test if the text matches the regular expression.
Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments.
Asserts that the message in a raised exception matches a regex.
Fail the test unless the text matches the regular expression.
An equality assertion for ordered sequences (like lists and tuples).
A set-specific equality assertion.
Check that the expression is true.
A tuple-specific equality assertion.
Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments.
Asserts that the message in a triggered warning matches a regexp.
Asserts that 'output' contains a line for each of the core test phases for the given test_name.
Asserts that the number of occurrences of expected and unexpected fails in 'output' matches the given numbers
Asserts that 'output' does not contain a status line for the given phase and test_name
Asserts that 'output' contains a line showing the given status for the given phase for the given test_name.
countTestCases
Creates the given test directory under testroot.
Creates a TestStatus file in the given path, with PASS status for all core phases
Run the test without collecting errors in a TestResult
defaultTestResult
Execute all class cleanup functions.
Execute all cleanup functions.
Same as enterContext, but class-wide.
Enters the supplied context manager.
Fail immediately, with the given message.
id
run
Hook method for setting up the test fixture before exercising it.
Hook method for setting up class fixture before running tests in the class.
Sets the last core phase to FAIL
Sets the given phase to the given status for this test
Returns a one-line description of the test, or None if no description has been provided.
Skip this test.
Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters.
Hook method for deconstructing the test fixture after testing it.
Hook method for deconstructing the class fixture after running all tests in the class.
Test the count of fails with three tests
With the expected_fails_file flag, expected failures should be flagged as such
With fails_only flag, only fails and pends should appear in the output
test_force_rebuild
cs_status for a single test should include some minimal expected output
cs_status for two tests (one with a FAIL) should include some minimal expected output
- classmethod addClassCleanup(function, /, *args, **kwargs)[source]
Same as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).
- addCleanup(function, /, *args, **kwargs)[source]
Add a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown).
- addTypeEqualityFunc(typeobj, function)[source]
Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages.
- Args:
- typeobj: The data type to call this function on when both values
are of the same type in assertEqual().
- function: The callable taking two arguments and an optional
msg= argument that raises self.failureException with a useful error message when the two arguments are not equal.
- assertAlmostEqual(first, second, places=None, msg=None, delta=None)[source]
Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
If the two objects compare equal then they will automatically compare almost equal.
- assertCountEqual(first, second, msg=None)[source]
Asserts that two iterables have the same elements, the same number of times, without regard to order.
- self.assertEqual(Counter(list(first)),
Counter(list(second)))
- Example:
[0, 1, 1] and [1, 0, 1] compare equal.
[0, 0, 1] and [0, 1] compare unequal.
- assertEqual(first, second, msg=None)[source]
Fail if the two objects are unequal as determined by the ‘==’ operator.
- assertGreater(a, b, msg=None)[source]
Just like self.assertTrue(a > b), but with a nicer default message.
- assertGreaterEqual(a, b, msg=None)[source]
Just like self.assertTrue(a >= b), but with a nicer default message.
- assertIn(member, container, msg=None)[source]
Just like self.assertTrue(a in b), but with a nicer default message.
- assertIs(expr1, expr2, msg=None)[source]
Just like self.assertTrue(a is b), but with a nicer default message.
- assertIsInstance(obj, cls, msg=None)[source]
Same as self.assertTrue(isinstance(obj, cls)), with a nicer default message.
- assertIsNone(obj, msg=None)[source]
Same as self.assertTrue(obj is None), with a nicer default message.
- assertIsNot(expr1, expr2, msg=None)[source]
Just like self.assertTrue(a is not b), but with a nicer default message.
- assertLess(a, b, msg=None)[source]
Just like self.assertTrue(a < b), but with a nicer default message.
- assertLessEqual(a, b, msg=None)[source]
Just like self.assertTrue(a <= b), but with a nicer default message.
- assertListEqual(list1, list2, msg=None)[source]
A list-specific equality assertion.
- Args:
list1: The first list to compare. list2: The second list to compare. msg: Optional message to use on failure instead of a list of
differences.
- assertLogs(logger=None, level=None)[source]
Fail unless a log message of level level or higher is emitted on logger_name or its children. If omitted, level defaults to INFO and logger defaults to the root logger.
This method must be used as a context manager, and will yield a recording object with two attributes: output and records. At the end of the context manager, the output attribute will be a list of the matching formatted log messages and the records attribute will be a list of the corresponding LogRecord objects.
Example:
with self.assertLogs('foo', level='INFO') as cm: logging.getLogger('foo').info('first message') logging.getLogger('foo.bar').error('second message') self.assertEqual(cm.output, ['INFO:foo:first message', 'ERROR:foo.bar:second message'])
- assertMultiLineEqual(first, second, msg=None)[source]
Assert that two multi-line strings are equal.
- assertNoLogs(logger=None, level=None)[source]
Fail unless no log messages of level level or higher are emitted on logger_name or its children.
This method must be used as a context manager.
- assertNotAlmostEqual(first, second, places=None, msg=None, delta=None)[source]
Fail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta.
Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
Objects that are equal automatically fail.
- assertNotEqual(first, second, msg=None)[source]
Fail if the two objects are equal as determined by the ‘!=’ operator.
- assertNotIn(member, container, msg=None)[source]
Just like self.assertTrue(a not in b), but with a nicer default message.
- assertNotRegex(text, unexpected_regex, msg=None)[source]
Fail the test if the text matches the regular expression.
- assertRaises(expected_exception, *args, **kwargs)[source]
Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertRaises(SomeException): do_something()
An optional keyword argument ‘msg’ can be provided when assertRaises is used as a context object.
The context manager keeps a reference to the exception as the ‘exception’ attribute. This allows you to inspect the exception after the assertion:
with self.assertRaises(SomeException) as cm: do_something() the_exception = cm.exception self.assertEqual(the_exception.error_code, 3)
- assertRaisesRegex(expected_exception, expected_regex, *args, **kwargs)[source]
Asserts that the message in a raised exception matches a regex.
- Args:
expected_exception: Exception class expected to be raised. expected_regex: Regex (re.Pattern object or string) expected
to be found in error message.
args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used
when assertRaisesRegex is used as a context manager.
- assertRegex(text, expected_regex, msg=None)[source]
Fail the test unless the text matches the regular expression.
- assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)[source]
An equality assertion for ordered sequences (like lists and tuples).
For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator.
- Args:
seq1: The first sequence to compare. seq2: The second sequence to compare. seq_type: The expected datatype of the sequences, or None if no
datatype should be enforced.
- msg: Optional message to use on failure instead of a list of
differences.
- assertSetEqual(set1, set2, msg=None)[source]
A set-specific equality assertion.
- Args:
set1: The first set to compare. set2: The second set to compare. msg: Optional message to use on failure instead of a list of
differences.
assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method).
- assertTupleEqual(tuple1, tuple2, msg=None)[source]
A tuple-specific equality assertion.
- Args:
tuple1: The first tuple to compare. tuple2: The second tuple to compare. msg: Optional message to use on failure instead of a list of
differences.
- assertWarns(expected_warning, *args, **kwargs)[source]
Fail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception.
If called with the callable and arguments omitted, will return a context object used like this:
with self.assertWarns(SomeWarning): do_something()
An optional keyword argument ‘msg’ can be provided when assertWarns is used as a context object.
The context manager keeps a reference to the first matching warning as the ‘warning’ attribute; similarly, the ‘filename’ and ‘lineno’ attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:
with self.assertWarns(SomeWarning) as cm: do_something() the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147)
- assertWarnsRegex(expected_warning, expected_regex, *args, **kwargs)[source]
Asserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches.
- Args:
expected_warning: Warning class expected to be triggered. expected_regex: Regex (re.Pattern object or string) expected
to be found in error message.
args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used
when assertWarnsRegex is used as a context manager.
- assert_core_phases(output, test_name, fails)[source]
Asserts that ‘output’ contains a line for each of the core test phases for the given test_name. All results should be PASS except those given by the fails list, which should be FAILS.
- assert_num_expected_unexpected_fails(output, num_expected, num_unexpected)[source]
Asserts that the number of occurrences of expected and unexpected fails in ‘output’ matches the given numbers
- assert_phase_absent(output, phase, test_name)[source]
Asserts that ‘output’ does not contain a status line for the given phase and test_name
- assert_status_of_phase(output, status, phase, test_name, xfail=None)[source]
Asserts that ‘output’ contains a line showing the given status for the given phase for the given test_name.
‘xfail’ should have one of the following values: - None (the default): assertion passes regardless of whether there is an
EXPECTED/UNEXPECTED string
‘no’: The line should end with the phase, with no additional text after that
‘expected’: After the phase, the line should contain ‘(EXPECTED FAILURE)’
‘unexpected’: After the phase, the line should contain ‘(UNEXPECTED’
- create_test_dir(test_dir)[source]
Creates the given test directory under testroot.
Returns the full path to the created test directory.
- static create_test_status_core_passes(test_dir_path, test_name)[source]
Creates a TestStatus file in the given path, with PASS status for all core phases
- classmethod doClassCleanups()[source]
Execute all class cleanup functions. Normally called for you after tearDownClass.
- enterContext(cm)[source]
Enters the supplied context manager.
If successful, also adds its __exit__ method as a cleanup function and returns the result of the __enter__ method.
- classmethod setUpClass()[source]
Hook method for setting up class fixture before running tests in the class.
- set_last_core_phase_to_fail(test_dir_path, test_name)[source]
Sets the last core phase to FAIL
Returns the name of this phase
- static set_phase_to_status(test_dir_path, test_name, phase, status)[source]
Sets the given phase to the given status for this test
- shortDescription()[source]
Returns a one-line description of the test, or None if no description has been provided.
The default implementation of this method returns the first line of the specified test method’s docstring.
- subTest(msg=<object object>, **params)[source]
Return a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed.
- classmethod tearDownClass()[source]
Hook method for deconstructing the class fixture after running all tests in the class.
- test_count_fails()[source]
Test the count of fails with three tests
For first phase of interest: First test FAILs, second PASSes, third FAILs; count should be 2, and this phase should not appear individually for each test.
For second phase of interest: First test PASSes, second PASSes, third FAILs; count should be 1, and this phase should not appear individually for each test.