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: Union[str, pathlib.Path], schema: Dict[str, Any]) None ¶
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: Optional[str] = None, module_name: Optional[str] = None, package_name: Optional[str] = None, schema_name: Optional[str] = None, schema_subpath: Optional[str] = None, config_package_root: Optional[Union[str, pathlib.Path]] = None, config_dir: Optional[Union[str, pathlib.Path]] = None) None ¶
A wrapper around
check_config_files
that handles the most common case.Assumptions:
The module can be imported, if
module_name
specified, else environment variablef"{package_name.upper()}_DIR"
exists. If not, skip the test, because the package is not available.The schema is a module constant named
schema_name
, if provided, else the schema is a file found as follows:If
module_name
is provided, the module root is n+1 levels above the package, where n is the number of “.” inmodule_name
The schema is in
module root / "schema" / f"{sal_name}.yaml"
unless you override this withschema_subpath
.
- 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
orNone
, optional If
module_name
is None then specify this argument and get the CSC package root using environment variablef"{package_name.upper()}_DIR"
. This is useful for non-python packages or packages that need a special environment to be imported.- schema_name
str
orNone
, optional Name of schema constant in the module, typically “CONFIG_SCHEMA”. If None then look for a schema file instead of a schema constant.
- schema_subpath
str
orNone
Schema path relative to csc_package_root. If
None
then usef"schema/{sal_name}.yaml"
. Ignored ifschema_name
is specified.- 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
schema_name
orconfig_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.
- sal_name
- get_config_dir(config_package_root: Union[str, pathlib.Path], sal_name: str, schema: Dict[str, Any]) pathlib.Path ¶
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 / version
- Parameters
- 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.
- config_package_root
- Returns
- config_dir
pathlib.Path
Directory containing configuration files.
- config_dir
- get_module_dir(module_name: str) pathlib.Path ¶
Get the directory of a python module, by importing the module.
- Parameters
- module_name
str
Module name, e.g. “lsst.ts.salobj”.
- module_name
- Returns
- module_dir
pathlib.Path
Module directory, e.g.
<package_root>/lsst/ts/salobj
- module_dir
- Raises
- ModuleNotFoundError
If the module is not found.
- get_schema(csc_package_root: Union[str, pathlib.Path], sal_name: Optional[str] = None, schema_subpath: Optional[str] = None) Dict[str, str] ¶
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
.