UnitTests

This module provides a base set of utilities for creating unittests for Pavilion.

class pavilion.unittest.PavTestCase(*args, make_config_dir: bool = True, make_working_dir: bool = True, make_pav_src: bool = True, write_config: bool = True, setup_spack: bool = True, **kwargs)

Bases: TestCaseEx

A unittest.TestCase with a lot of useful Pavilion features baked in. All pavilion unittests (in test/tests) should use this as their base class.

Variables:
  • PAV_LIB_DIR (Path) – The Path to Pavilion’s lib directory (where this module resides).

  • PAV_ROOT_DIR (Path) – The Path to Pavilion’s root directory (the root of the git repo).

  • TEST_DATA_DIR (Path) – The unit test data directory.

  • PAV_CONFIG_PATH (Path) – The path to the configuration used by unit tests.

  • QUICK_TEST_BASE_CFG (dict) – The base configuration for tests generated by the _quick_test() and _quick_test_cfg() methods.

  • pav_cfg (yaml_config.ConfigDict) – A pavilion config setup properly for use by unit tests. Unit tests should always use this pav_cfg. If it needs to be modified, copy it using copy.deepcopy.

DEFAULT_LOCK_LIFETIME = 3
DEFAULT_PAV_CONFIG_PATH = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/data/pav_config_dir/pavilion.yaml.in')
DEFAULT_TIMEOUTS = {'build_docs': 30, 'lockfile': 1, 'log_cmd': 5, 'result_logger': 10, 'series_start': 10, 'series_wait': 10, 'test_cmd': 3, 'testrun_build': 5, 'testrun_cancel': 1, 'testrun_run': 10, 'testrun_start': 10, 'testrun_wait': 20, 'testset_wait': 10}
PAV_LIB_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/lib')
PAV_ROOT_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest')
PAV_TEST_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test')
QUICK_TEST_BASE_CFG = {'build': {'timeout': '30', 'verbose': 'false'}, 'cfg_label': 'test', 'result_evaluate': {}, 'result_parse': {}, 'run': {'cmds': ['echo "Hello World."'], 'timeout': '300', 'verbose': 'false'}, 'schedule': {}, 'scheduler': 'raw', 'suite': 'unittest'}
TEST_DATA_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/data')
TEST_DATA_PAV_CONFIG_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/data/pav_config_dir')
TEST_OUTPUT_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/output')
TEST_URL = 'https://raw.githubusercontent.com/hpc/pavilion2/2.1.1/README.md'
TEST_URL2 = 'https://raw.githubusercontent.com/hpc/pavilion2/2.1.1/RELEASE.txt'
TEST_URL_HASH = '0a3ad5bec7c8f6929115d33091e53819ecaca1ae'
WORKING_DIRS = ['builds', 'test_runs', 'series', 'users']
_classSetupFailed = False
_class_cleanups = []
_cmp_files(a_path, b_path)

Compare the contents of two files.

Parameters:
  • a_path (Path)

  • b_path (Path)

_cmp_tree(path_a, path_b)

Compare two directory trees, including the contents of all the files.

_get_lock_lifetime() None

Get the lock lifetime from the environment, if defined. Otherwise, use default values.

_get_timeouts() None

Get the various timeout values from the environment, if defined. Otherwise, use default values.

Verify that a directory contains nothing but softlinks whose files exist. Directories in a softlink dir should be real directories though.

_load_test(name: str, platform: str = 'this', host: str = 'this', modes: List[str] | None = None, build=True, finalize=True) List[TestRun]

Load the named test config from file. Returns a list of the resulting configs.

_quick_test(cfg=None, name='quick_test', build=True, finalize=True, test_id=None)

Create a test run object to work with. The default is a simple hello world test with the raw scheduler.

Parameters:
  • cfg (dict) – An optional config dict to create the test from.

  • name (str) – The name of the test.

  • build (bool) – Build this test, while we’re at it.

  • finalize (bool) – Finalize this test.

Return type:

TestRun

_quick_test_cfg() Dict[str, Any]

Return a pre-populated test config to use with self._quick_test. This can be used as is, or modified for desired effect.

The default config is:

{'build': {'timeout': '30', 'verbose': 'false'},
 'cfg_label': 'test',
 'result_evaluate': {},
 'result_parse': {},
 'run': {'cmds': ['echo "Hello World."'], 'timeout': '300', 'verbose': 'false'},
 'schedule': {},
 'scheduler': 'raw',
 'suite': 'unittest'}
static dbg_print(*args, color=33, file=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, end='', pformat=True, **kwargs)

A colored print statement for debug printing. Use when you want to print dbg statements and easily excise it later.

Parameters:
  • file – The file object to write to.

  • end – Default the ending to no newline (we do a pre-newline because of how unittest prints stuff.

  • color (int) – ANSI color code to print the string under.

  • pformat (bool) – Automatically apply pprint.pformat to args that are dicts or lists.

  • kwargs – Also accepts all print() kwargs.

static get_hash(filename)

Get a sha1 hash of the file at the given path.

Parameters:

filename (Path)

Returns:

The sha1 hexdigest of the file contents.

Return type:

str

Link a file from the test data directory into the specified config directory, or into the unit test suite’s main config directory, if no config directory is provided, using the file name specified by with_name. If no name is provided, the linked file retains its original name.

Link files from the test data directory into the specified config directory, or into the unit test suite’s main config directory, if no config directory is provided.

make_pav_config(setup_spack: bool = True, write: bool = True, **kwargs)

Create a pavilion config for the current test suite.

set_up()

By default, initialize plugins before every test.

setup_suite_output_dir(make_config_dir: bool = True, make_working_dir: bool = True, make_pav_src: bool = True, make_results_dir: bool = True, write_config: bool = True, setup_spack: bool = True) None

Make the main Pavilion config directory for the current test suite.

tear_down()

Nothing to do by default.

wait_tests(working_dir: Path, timeout=5)

Wait on all the tests under the given path to complete.

Parameters:
  • working_dir – The path to a working directory.

  • timeout – How long to wait before giving up.