generator#

class AbstractTestGenerator(root: str, path: str | None = None)#

Bases: ABC

The AbstractTestCaseGenerator is an abstract object representing a test file that can generate test cases

Parameters:
  • root – The base test directory, or file path if path is not given

  • path – The file path, relative to root

To create a test generator, simply subclass AbstractTestGenerator and register the containing file as an canary plugin. The subclass will be added to the command registry and added to the set of available test generators.

All canary builtin generators are implemented as plugins.

Examples:

from typing import Optional

import canary

class MyGenerator(canary.AbstractTestGenerator):
    file_patterns = ["*.suffix"]

    def describe(self, on_options: list[str] | None = None) -> str:
        ...

    def lock(self, on_options: list[str] | None = None) -> list[canary.TestCase]:
        ...
file_patterns: ClassVar[tuple[str, ...]] = ()#
classmethod factory(root: str, path: str | None = None) Self | None#
classmethod matches(path: str) str | None#

Is the file at path a test file?

describe(on_options: list[str] | None = None) str#

Return a description of the test

abstractmethod lock(on_options: list[str] | None = None) Sequence[UnresolvedSpec | ResolvedSpec]#

Expand parameters and instantiate concrete test cases

Parameters:

on_options – User specified options used to filter tests. Test cases not matching on_options should be masked.

Notes

For further discussion on filtering tests see Filtering tests.

asdict() dict[str, Any]#
static validate(data) Any#
static reconstruct(serialized: str) AbstractTestGenerator#
serialize() str#
static create(root: str, path: str | None = None) AbstractTestGenerator#
info() dict[str, Any]#