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
(module_name[, ...])A wrapper around
check_config_files
to test salobj packages.get_config_dir
(config_package_root, ...)Get the directory of config files, assuming the standard ts_config_x package layout.
get_schema
(csc_package_root[, sal_name, ...])Get the config schema for a package, as a dict.
Methods Documentation
- check_config_files(config_dir: str | pathlib.Path, schema: dict[str, Any], exclude_glob: str | None = None) None ¶
Check all configuration files for a given package.
- Parameters:
- config_dir
str
orpathlib.Path
Directory containing config files.
- schema
dict
Configuration schema.
- exclude_override_glob
dict
Glob expression for files to exclude.
- config_dir
- Raises:
- AssertionError
If the files do not produce a valid schema.
- check_standard_config_files(module_name: str, schema_name: str = 'CONFIG_SCHEMA', sal_name: str | None = None, config_package_root: str | pathlib.Path | None = None, config_dir: str | pathlib.Path | None = None) None ¶
A wrapper around
check_config_files
to test salobj packages.- Parameters:
- module_name
str
Module name, e.g. “lsst.ts.salobj”.
- schema_name
str
Name of schema constant in the module, typically “CONFIG_SCHEMA”.
- sal_name
str
orNone
SAL component name, e.g. “Watcher”. Ignored if
config_dir
is not None. Used to determine config dir ifconfig_dir
is None.- config_package_root
str
orpathlib.Path
orNone
Root directory of configuration package. Used to determine config dir if
config_dir
is None. Within the unit test for a config package, 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. If
None
then a reasonable value is computed; this is primarily intended to support unit testing in ts_salobj.- exclude_globstr
Glob expression of override files to exclude. For use by salobj unit tests.
- module_name
- get_config_dir(config_package_root: str | pathlib.Path, sal_name: str, schema: dict[str, Any]) 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_schema(csc_package_root: str | pathlib.Path, sal_name: str | None = None, schema_subpath: str | None = 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
.