UnitTests¶
This module provides a base set of utilities for creating unittests for Pavilion.
-
class
pavilion.unittest.
ColorResult
(*args, **kwargs)¶ Provides colorized results for the python unittest library.
-
class
pavilion.unittest.
PavTestCase
(*args, **kwargs)¶ Bases:
unittest.case.TestCase
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.
-
ONLY
= []¶
-
PAV_CONFIG_PATH
= PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/2.1.1/test/data/pav_config_dir/pavilion.yaml')¶
-
PAV_LIB_DIR
= PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/2.1.1/lib/pavilion')¶
-
PAV_ROOT_DIR
= PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/2.1.1')¶
-
QUICK_TEST_BASE_CFG
= {'build': {'timeout': '30', 'verbose': 'false'}, 'run': {'cmds': ['echo "Hello World."'], 'timeout': '300', 'verbose': 'false'}, 'scheduler': 'raw', 'slurm': {}, 'suite': 'unittest'}¶
-
SKIP
= []¶
-
TEST_DATA_ROOT
= PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/pavilion2/checkouts/2.1.1/test/data')¶
-
TEST_URL
= 'https://github.com/lanl/Pavilion/archive/master.zip'¶
-
WORKING_DIRS
= ['builds', 'test_runs', 'series', 'users', 'downloads']¶
-
_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.
-
_quick_test
(cfg=None, name='quick_test', build=True, finalize=True, sched_vars=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.
- sched_vars (dict) – Add these scheduler variables to our var set.
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'}, 'run': {'cmds': ['echo "Hello World."'], 'timeout': '300', 'verbose': 'false'}, 'scheduler': 'raw', 'slurm': {}, '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
-
classmethod
set_only
(globs)¶ Only run tests whos names match the given globs.
-
classmethod
set_skip
(globs)¶ Skip tests whose names match the given globs.