CIME.tests package

Submodules

CIME.tests.case_fake module

This module contains a fake implementation of the Case class that can be used for testing the tests.

class CIME.tests.case_fake.CaseFake(case_root, create_case_root=True)[source]

Bases: object

case_setup(clean=False, test_mode=False, reset=False)[source]
copy(newcasename, newcaseroot)[source]

Create and return a copy of self, but with CASE and CASEBASEID set to newcasename, CASEROOT set to newcaseroot, and RUNDIR set appropriately.

Args:

newcasename (str): new value for CASE newcaseroot (str): new value for CASEROOT

create_clone(newcase, keepexe=False, mach_dir=None, project=None, cime_output_root=None, exeroot=None, rundir=None)[source]

Create a clone of the current case. Also creates the CASEROOT directory for the clone case (given by newcase).

Args:
newcase (str): full path to the new case. This directory should not

already exist; it will be created

keepexe (bool, optional): Ignored mach_dir (str, optional): Ignored project (str, optional): Ignored cime_output_root (str, optional): New CIME_OUTPUT_ROOT for the clone exeroot (str, optional): New EXEROOT for the clone rundir (str, optional): New RUNDIR for the clone

Returns the clone case object

flush()[source]
get_value(item)[source]

Get the value of the given item

Returns None if item isn’t set for this case

Args:

item (str): variable of interest

load_env(reset=False)[source]
make_rundir()[source]

Make directory given by RUNDIR

set_exeroot()[source]

Assumes CASEROOT is already set; sets an appropriate EXEROOT (nested inside CASEROOT)

set_rundir()[source]

Assumes CASEROOT is already set; sets an appropriate RUNDIR (nested inside CASEROOT)

set_value(item, value)[source]

Set the value of the given item to the given value

Args:

item (str): variable of interest value (any type): new value for item

CIME.tests.custom_assertions_test_status module

This module contains a class that extends unittest.TestCase, adding custom assertions that can be used when testing TestStatus.

class CIME.tests.custom_assertions_test_status.CustomAssertionsTestStatus(methodName='runTest')[source]

Bases: unittest.case.TestCase

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’

CIME.tests.test_case_fake module

This module contains unit tests of CaseFake

class CIME.tests.test_case_fake.TestCaseFake(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_create_clone()[source]

CIME.tests.test_cs_status module

class CIME.tests.test_cs_status.TestCsStatus(methodName='runTest')[source]

Bases: CIME.tests.custom_assertions_test_status.CustomAssertionsTestStatus

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

setUp()[source]

Hook method for setting up the test fixture before exercising it.

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

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

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.

test_expected_fails()[source]

With the expected_fails_file flag, expected failures should be flagged as such

test_fails_only()[source]

With fails_only flag, only fails and pends should appear in the output

test_single_test()[source]

cs_status for a single test should include some minimal expected output

test_two_tests()[source]

cs_status for two tests (one with a FAIL) should include some minimal expected output

CIME.tests.test_custom_assertions_test_status module

This module contains unit tests of CustomAssertionsTestStatus

class CIME.tests.test_custom_assertions_test_status.TestCustomAssertions(methodName='runTest')[source]

Bases: CIME.tests.custom_assertions_test_status.CustomAssertionsTestStatus

static output_line(status, test_name, phase, extra='')[source]
test_assertCorePhases_missingPhase_fails()[source]

assert_core_phases fails if there is a missing phase

test_assertCorePhases_passes()[source]

assert_core_phases passes when it should

test_assertCorePhases_wrongName_fails()[source]

assert_core_phases fails if the test name is wrong

test_assertCorePhases_wrongStatus_fails()[source]

assert_core_phases fails if a phase has the wrong status

test_assertPhaseAbsent_fails()[source]

assert_phase_absent should fail when the phase is present for the given test_name

test_assertPhaseAbsent_passes()[source]

assert_phase_absent should pass when the phase is absent for the given test_name

test_assertStatusOfPhase_withExtra_passes()[source]

Make sure assert_status_of_phase passes when there is some extra text at the end of the line

test_assertStatusOfPhase_xfailExpected_fails()[source]

assert_status_of_phase should fail when xfail=’expected’ but the line does NOT contain the EXPECTED comment

test_assertStatusOfPhase_xfailExpected_passes()[source]

assert_status_of_phase should pass when xfail=’expected’ and the line contains the EXPECTED comment

test_assertStatusOfPhase_xfailNo_fails()[source]

assert_status_of_phase should fail when xfail=’no’ but the line contains the EXPECTED comment

test_assertStatusOfPhase_xfailNo_passes()[source]

assert_status_of_phase should pass when xfail=’no’ and there is no EXPECTED/UNEXPECTED on the line

test_assertStatusOfPhase_xfailUnexpected_fails()[source]

assert_status_of_phase should fail when xfail=’unexpected’ but the line does NOT contain the UNEXPECTED comment

test_assertStatusOfPhase_xfailUnexpected_passes()[source]

assert_status_of_phase should pass when xfail=’unexpected’ and the line contains the UNEXPECTED comment

CIME.tests.test_test_status module

class CIME.tests.test_test_status.TestTestStatus(methodName='runTest')[source]

Bases: CIME.tests.custom_assertions_test_status.CustomAssertionsTestStatus

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_psdump_corePhasesPass()[source]
test_psdump_oneCorePhaseFails()[source]
test_psdump_oneCorePhaseFailsAbsentFromXFails()[source]

One phase fails. There is an expected fails list, but that phase is not in it.

test_psdump_oneCorePhaseFailsInXFails()[source]

One phase fails. That phase is in the expected fails list.

test_psdump_oneCorePhasePassesInXFails()[source]

One phase passes despite being in the expected fails list.

test_psdump_skipPasses()[source]

With the skip_passes argument, only non-passes should appear

test_psdump_unexpectedPass_shouldBePresent()[source]

Even with the skip_passes argument, an unexpected PASS should be present

CIME.tests.test_user_mod_support module

class CIME.tests.test_user_mod_support.TestUserModSupport(methodName='runTest')[source]

Bases: unittest.case.TestCase

assertResults(expected_user_nl_cpl, expected_shell_commands_result, expected_sourcemod, msg='')[source]

Asserts that the contents of the files in self._caseroot match expectations

If msg is provided, it is printed for some failing assertions

createUserMod(name, include_dirs=None)[source]

Create a user_mods directory with the given name.

This directory is created within self._user_mods_parent_dir

For name=’foo’, it will contain:

  • A user_nl_cpl file with contents: foo

  • A shell_commands file with contents: echo foo >> /PATH/TO/CASEROOT/shell_commands_result

  • A file in _SOURCEMODS named myfile.F90 with contents: foo

If include_dirs is given, it should be a list of strings, giving names of other user_mods directories to include. e.g., if include_dirs is [‘foo1’, ‘foo2’], then this will create a file ‘include_user_mods’ that contains paths to the ‘foo1’ and ‘foo2’ user_mods directories, one per line.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_basic()[source]
test_duplicate_includes()[source]

Test multiple includes, where both include the same base mod.

The base mod should only be included once.

test_include()[source]

If there is an included mod, the main one should appear after the included one so that it takes precedence.

test_keepexe()[source]
test_two_applications()[source]

If apply_user_mods is called twice, the second should appear after the first so that it takes precedence.

CIME.tests.test_utils module

class CIME.tests.test_utils.TestIndentStr(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the indent_string function.

test_indent_string_multiline()[source]

Test the indent_string function with a multi-line string

test_indent_string_singleline()[source]

Test the indent_string function with a single-line string

Module contents