BaseConfigTestCase¶
-
class
lsst.ts.salobj.
BaseConfigTestCase
¶ Bases:
object
Base class for testing configuration files.
Subclasses must:
- Inherit both from this and
unittest.TestCase
.
Also we suggest:
- Add a method
test_<foo>
which callscheck_config_files
.
Methods Summary
check_config_files
(config_dir, schema)Check all configuration files for a given package. check_standard_config_files
(sal_name[, …])A wrapper around check_config_files
that handles the most common case.get_config_dir
(config_package_root, …)Get the directory of config files, assuming the standard ts_config_x package layout. get_module_dir
(module_name)Get the directory of a python module, by importing the module. get_schema
(csc_package_root[, sal_name, …])Get the config schema for a package, as a dict. Methods Documentation
-
check_config_files
(config_dir, schema)¶ Check all configuration files for a given package.
Parameters: - config_dir :
str
orpathlib.Path
Directory containing config files and
_labels.yaml
.- schema :
dict
Configuration schema.
- config_dir :
-
check_standard_config_files
(sal_name, module_name=None, package_name=None, schema_subpath=None, config_package_root=None, config_dir=None)¶ A wrapper around
check_config_files
that handles the most common case.Assumptions:
- The module can be imported, else the test is skipped
- The module root is n+1 levels above the package
where n is the number of “.” in
module_name
. - The schema is in
module root / "schema" / f"{sal_name}.yaml"
Parameters: - sal_name :
str
SAL component name, e.g. “Watcher”.
- module_name :
str
orNone
, optional Module name, e.g. “lsst.ts.salobj”. If not None then get the CSC package root by importing the module and ignore
package_name
.- package_name :
str
, optional If
module_name
is None then specify this argument and get the CSC package root using environment variable<PACKAGE_NAME>_DIR
. This is useful for non-python packages or packages that need a special environment to be imported.- schema_subpath :
str
orNone
Schema path relative to csc_package_root. If
None
then usef"schema/{sal_name}.yaml"
- config_package_root :
str
orpathlib.Path
orNone
Root directory of configuration package. Within the unit test this will work:
config_package_root = pathlib.Path(__file__).parents[1]
Ignored if
config_dir
is specified.- config_dir :
str
orpathlib.Path
orNone
Directory containing config files and
_labels.yaml
. IfNone
then a reasonable value is computed; this is primarily intended to support unit testing in ts_salobj.
-
get_config_dir
(config_package_root, sal_name, schema)¶ Get the directory of config files, assuming the standard ts_config_x package layout.
The config dir is assumed to be as follows, where
version
comes from the title field of the schema:config_package_root / sal_name / versionParameters: - config_package_root :
str
orpathlib.Path
Root directory of configuration package. For unit tests in a config package, this will work:
config_package_root = pathlib.Path(__file__).parents[1]
- sal_name :
str
SAL component name, e.g. “Watcher”.
- schema :
dict
Configuration schema. Used to determine the version.
Returns: - config_dir :
pathlib.Path
Directory containing configuration files.
- config_package_root :
-
get_module_dir
(module_name)¶ Get the directory of a python module, by importing the module.
Parameters: - module_name :
str
Module name, e.g. “lsst.ts.salobj”.
Returns: - module_dir :
pathlib.Path
Module directory, e.g.
<package_root>/lsst/ts/salobj
Raises: - ModuleNotFoundError
If the module is not found.
- module_name :
-
get_schema
(csc_package_root, sal_name=None, schema_subpath=None)¶ Get the config schema for a package, as a dict.
The schema is expected to be:
csc_package_root / “schema” / f”{sal_name}.yaml”Parameters: Raises: - AssertionError
If csc_package_root is not an existing directory. If the schema file is not an existing file.
- jsonschema.exceptions.SchemaError
If the file cannot be interpreted as a
dict
.
- Inherit both from this and