onyo.conftest module

class onyo.conftest.AnnotatedGitRepo(path, find_root=False)[source]

Bases: GitRepo

Annotate a GitRepo object to ease testing.

Populated files and directories are stored in .test_annotation.

__init__(path, find_root=False)[source]

Instantiate an AnnotatedGitRepo object with path as the root directory.

Parameters:
  • path (Path) – Absolute Path of a git repository.

  • find_root (bool (default: False)) – Replace path with the results of onyo.lib.git.GitRepo.find_root(). Thus any directory of a git repository can be passed as path, not just the repo root.

class onyo.conftest.AnnotatedOnyoRepo(path, init=False, find_root=False)[source]

Bases: OnyoRepo

Annotate an OnyoRepo object to ease testing.

Populated inventory items are stored in .test_annotation.

__init__(path, init=False, find_root=False)[source]

Instantiate an AnnotatedOnyoRepo object with path as the root directory.

Parameters:
  • path (Path) – Absolute path to the root of the Onyo Repository.

  • init (bool (default: False)) – Initialize path as a git repo and create/populate the subdir .onyo/. Cannot be used with find_root=True.

  • find_root (bool (default: False)) – Replace path with the results of onyo.lib.onyo.OnyoRepo.find_root(). Thus any directory of a git repository can be passed as path, not just the repo root. Cannot be used with init==True.

class onyo.conftest.Helpers[source]

Bases: object

A collection of helper utilities for tests.

static flatten(xs)[source]

Yield a flattened Iterable.

Flatten a multidimensional list into a single dimension.

Return type:

Generator

static onyo_flags()[source]

Return a List of all top level flags.

Return type:

List[Union[List[List[str]], List[str]]]

static powerset(iterable)[source]

Yield the powerset.

Each subset is returned as its own Tuple. For example:

powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)
Return type:

chain[Tuple]

onyo.conftest.clean_env(request)[source]

Ensure that $EDITOR is unset.

Makes sure that the $EDITOR environment variable is not inherited from the user environment nor other tests.

Return type:

None

onyo.conftest.clean_locale(request)[source]

Ensure that the locale is set to ‘en_US.UTF-8’.

Tests that involve sorting can be impacted by the locale. This sets it to a known, static target.

Return type:

None

onyo.conftest.fake_class_scope()[source]

Scope the fake parameter fixture for classes.

Return type:

Generator

onyo.conftest.fake_function_scope()[source]

Scope the fake parameter fixture for functions.

Return type:

Generator

onyo.conftest.fake_module_scope()[source]

Scope the fake parameter fixture for modules.

Return type:

Generator

onyo.conftest.fake_session_scope()[source]

Scope the fake parameter fixture for sessions.

Return type:

Generator

onyo.conftest.fixture_fake()[source]

Yield a Faker object with the Onyo provider loaded.

Return type:

Generator

onyo.conftest.fixture_gitrepo(tmp_path, request)[source]

Yield an AnnotatedGitRepo object, populated from fixtures.

A fresh repository is created in a unique temporary directory. It is populated via the following marker (which is then stored in .test_annotation for later reference by tests):

  • gitrepo_contents()

Parent directories of all items are automatically created.

Example markers:

gitrepo_contents((Path('.gitignore'), "dir_to_ignore/"),
                 (Path("dir_to_ignore/some.pdf"), "0xDEADBEEF"),
                 (Path("a/b/c/"), ""),
                 (Path("1/2/3/"), ""),
                 )

Example annotations:

for dir_path in onyorepo.test_annotation['directories']:
    assert dir_path.is_dir() is True
Return type:

Generator[AnnotatedGitRepo, None, None]

onyo.conftest.fixture_helpers()[source]

Return a Helper object with various helper utilities.

See also

Helpers

Return type:

Generator[Type[Helpers], None, None]

onyo.conftest.fixture_inventory(repo)[source]

Yield a populated Inventory object.

The inventory is populated with the following directories:

  • different/place/

  • empty/

  • somewhere/nested/

And the following asset:

  • somewhere/nested/TYPE_MAKER_MODEL.SERIAL

Return type:

Generator[Inventory, None, None]

onyo.conftest.fixture_onyorepo(gitrepo, request)[source]

Yield an AnnotatedOnyoRepo object, populated from fixtures.

A fresh repository is created in a unique temporary directory. It is populated via these markers (which are then stored in .test_annotation for later reference by tests):

  • inventory_assets()

  • inventory_dirs()

  • inventory_templates()

Parent directories of all items are automatically created.

Example markers:

inventory_assets()
inventory_assets(Item(type="type", make="make", model="model", serial=1,
                      onyo.path.parent=Path("here/")),
                 Item(type="type", make="make", model="model", serial=2,
                      onyo.path.parent=Path("there/")),
                 )
inventory_dirs(Path('a/b/c/'),
               Path('1/2/3/'),
               )
inventory_templates()
inventory_templates((onyo.lib.consts.TEMPLATE_DIR / "generic" / "laptop",
                     "---\ntype: laptop\n"),
                    (onyo.lib.consts.TEMPLATE_DIR / "generic" / "display",
                     "---\ntype: display\n"),
                    )

Example annotations:

for asset_path in onyorepo.test_annotation['assets']:
    assert onyorepo.is_asset_path(asset_path) is True
Return type:

Generator[AnnotatedOnyoRepo, None, None]

onyo.conftest.fixture_repo(tmp_path, request)[source]

Yield an OnyoRepo object, populated from fixtures.

A fresh repository is created in a unique temporary directory. It is then populated via these markers:

  • repo_dirs()

  • repo_files() (parent directories of files are automatically created)

Example:

repo_dirs("a/b/c", "1/2/3")
repo_files("here/type_make_model.1", "there/type_make_model.2")
Return type:

Generator[OnyoRepo, None, None]

onyo.conftest.fixture_ui(request)[source]

Configure onyo.lib.ui.UI.

Applies values from a dict defined by the ui marker.

Supported keys are: 'yes', 'quiet', and 'debug'. All accept booleans.

See also

onyo.lib.ui.UI

Return type:

Generator

onyo.conftest.gitrepo_class_scope(tmp_path_class_scope, request)[source]

Scope the gitrepo parameter fixture for classes.

Return type:

Generator

onyo.conftest.gitrepo_function_scope(tmp_path, request)[source]

Scope the gitrepo parameter fixture for functions.

Return type:

Generator

onyo.conftest.gitrepo_module_scope(tmp_path_module_scope, request)[source]

Scope the gitrepo parameter fixture for modules.

Return type:

Generator

onyo.conftest.gitrepo_session_scope(tmp_path, request)[source]

Scope the gitrepo parameter fixture for sessions.

Return type:

Generator

onyo.conftest.helpers_class_scope()[source]

Scope the helpers parameter fixture for classes.

Return type:

Generator

onyo.conftest.helpers_function_scope()[source]

Scope the helpers parameter fixture for functions.

Return type:

Generator

onyo.conftest.helpers_module_scope()[source]

Scope the helpers parameter fixture for modules.

Return type:

Generator

onyo.conftest.helpers_session_scope()[source]

Scope the helpers parameter fixture for sessions.

Return type:

Generator

onyo.conftest.inventory_class_scope(repo_class_scope)[source]

Scope the inventory parameter fixture for classes.

Return type:

Generator

onyo.conftest.inventory_function_scope(repo)[source]

Scope the inventory parameter fixture for functions.

Return type:

Generator

onyo.conftest.inventory_module_scope(repo_module_scope)[source]

Scope the inventory parameter fixture for modules.

Return type:

Generator

onyo.conftest.inventory_session_scope(repo_session_scope)[source]

Scope the inventory parameter fixture for sessions.

Return type:

Generator

onyo.conftest.onyorepo_class_scope(gitrepo_class_scope, request)[source]

Scope the onyorepo parameter fixture for classes.

Return type:

Generator

onyo.conftest.onyorepo_function_scope(gitrepo, request)[source]

Scope the onyorepo parameter fixture for functions.

Return type:

Generator

onyo.conftest.onyorepo_module_scope(gitrepo_module_scope, request)[source]

Scope the onyorepo parameter fixture for modules.

Return type:

Generator

onyo.conftest.onyorepo_session_scope(gitrepo_session_scope, request)[source]

Scope the onyorepo parameter fixture for sessions.

Return type:

Generator

onyo.conftest.params(d)[source]

Parameterize a dictionary with human-friendly names.

Allows for meaningful variant names to be printed to the CLI when <variable> is not easily string-ify-able.

For example, to run tests with a variable variant with the value <variable> and <id> as the test ID:

{
    "<id>": {"variant": <variable>},
    ...
}
Return type:

MarkDecorator

onyo.conftest.repo_class_scope(tmp_path_class_scope, request)[source]

Scope the repo parameter fixture for classes.

Return type:

Generator

onyo.conftest.repo_function_scope(tmp_path, request)[source]

Scope the repo parameter fixture for functions.

Return type:

Generator

onyo.conftest.repo_module_scope(tmp_path_module_scope, request)[source]

Scope the repo parameter fixture for modules.

Return type:

Generator

onyo.conftest.repo_session_scope(tmp_path_session_scope, request)[source]

Scope the repo parameter fixture for sessions.

Return type:

Generator

onyo.conftest.tmp_path_class_scope(tmp_path_factory, request)[source]

Scope the tmp_path parameter fixture for classes.

onyo.conftest.tmp_path_module_scope(tmp_path_factory, request)[source]

Scope the tmp_path parameter fixture for modules.

onyo.conftest.tmp_path_session_scope(tmp_path_factory, request)[source]

Scope the tmp_path parameter fixture for sessions.

onyo.conftest.ui_class_scope(request)[source]

Scope the ui marker for classes.

Return type:

Generator

onyo.conftest.ui_function_scope(request)[source]

Scope the ui marker for functions.

Return type:

Generator

onyo.conftest.ui_module_scope(request)[source]

Scope the ui marker for modules.

Return type:

Generator

onyo.conftest.ui_session_scope(request)[source]

Scope the ui marker for sessions.

Return type:

Generator