BaseConfigTestCase

class lsst.ts.salobj.BaseConfigTestCase

Bases: object

Base class for testing configuration files.

Subclasses must:

Also we suggest:

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_dirstr or pathlib.Path

Directory containing config files and _labels.yaml.

schemadict

Configuration schema.

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 variable f"{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 “.” in module_name

    • The schema is in module root / "schema" / f"{sal_name}.yaml" unless you override this with schema_subpath.

Parameters
sal_namestr

SAL component name, e.g. “Watcher”.

module_namestr or None, 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_namestr or None, optional

If module_name is None then specify this argument and get the CSC package root using environment variable f"{package_name.upper()}_DIR". This is useful for non-python packages or packages that need a special environment to be imported.

schema_namestr or None, 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_subpathstr or None

Schema path relative to csc_package_root. If None then use f"schema/{sal_name}.yaml". Ignored if schema_name is specified.

config_package_rootstr or pathlib.Path or None

Root directory of configuration package. Within the unit test this will work:

config_package_root = pathlib.Path(__file__).parents[1]

Ignored if schema_name or config_dir is specified.

config_dirstr or pathlib.Path or None

Directory containing config files and _labels.yaml. If None then a reasonable value is computed; this is primarily intended to support unit testing in ts_salobj.

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_rootstr or pathlib.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_namestr

SAL component name, e.g. “Watcher”.

schemadict

Configuration schema. Used to determine the version.

Returns
config_dirpathlib.Path

Directory containing configuration files.

get_module_dir(module_name: str) pathlib.Path

Get the directory of a python module, by importing the module.

Parameters
module_namestr

Module name, e.g. “lsst.ts.salobj”.

Returns
module_dirpathlib.Path

Module directory, e.g. <package_root>/lsst/ts/salobj

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
csc_package_rootstr or pathlib.Path

Root directory of CSC package.

sal_namestr

SAL component name, e.g. “Watcher”. Ignored if schema_subpath is specified.

schema_subpathstr or None

Schema path relative to csc_package_root. If None then use f"schema/{sal_name}.yaml"

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.