UnitTests
This module provides a base set of utilities for creating unittests for Pavilion.
- class pavilion.unittest.PavTestCase(*args, **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_ROOT (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.
- PAV_CONFIG_PATH = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/data/pav_config_dir/pavilion.yaml')
- PAV_LIB_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/lib/pavilion')
- PAV_ROOT_DIR = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest')
- 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_ROOT = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/latest/test/data')
- 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']
- _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.
- _is_softlink_dir(path)
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, op_sys: str = 'this', host: str = 'this', modes: Optional[List[str]] = 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)
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
- _quick_test_cfg()
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
- make_pav_config(config_dirs: Optional[List[Path]] = None)
Create a pavilion config for use with tests. By default uses the data/pav_config_dir as the config directory.
- set_up()
By default, initialize plugins before every test.
- tear_down()
By default, reset plugins after every test.
- 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.