Skip to content

testing_utils

get_Project

get_Project()

A pytest fixture that gets a clean version of the Project class, with caches and other class attributes appropriately reset.

Source code in cassini/testing_utils.py
19
20
21
22
23
24
25
26
27
28
29
30
31
@pytest.fixture
def get_Project():
    """
    A pytest fixture that gets a clean version of the Project class, with caches and other class attributes appropriately reset.
    """
    env._reset()

    Project.__before_setup_files__ = []
    Project.__after_setup_files__ = []
    Project.__before_launch__ = []
    Project.__after_launch__ = []

    return Project

patch_project

patch_project(get_Project, tmp_path)

A pytest fixture that returns a simple preconfigured project.

Source code in cassini/testing_utils.py
34
35
36
37
38
39
40
41
42
43
44
45
@pytest.fixture
def patch_project(get_Project, tmp_path):
    """
    A pytest fixture that returns a simple preconfigured `project`.
    """
    Project = get_Project

    class Tier(NotebookTierBase):
        pretty_type = "Tier"

    project = Project([Home, Tier], tmp_path)
    return Tier, project

patched_default_project

patched_default_project(get_Project, tmp_path)

A pytest fixture that provides a factory for setting up a project with the default configuration.

Returns:

Name Type Description
project Project

The fresh project instance.

create_tiers Callable[[Sequence[str]], Sequence[TierABC]]

function for creating tiers by a list of names. Returns each pre-setup tier in order.

Example
def test_something(patched_default_project):
    project, make_tiers = patched_default_project
    WP1, = make_tiers(['WP1'])
Source code in cassini/testing_utils.py
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
@pytest.fixture
def patched_default_project(
    get_Project, tmp_path
) -> Tuple[Project, Callable[[Sequence[str]], Sequence[TierABC]]]:
    """
    A pytest fixture that provides a factory for setting up a project with the default configuration.

    Returns
    -------
    project: Project
        The fresh project instance.
    create_tiers: Callable[[Sequence[str]], Sequence[TierABC]]
        function for creating tiers by a list of names. Returns each pre-setup tier in order.

    Example
    -------
    ```python

    def test_something(patched_default_project):
        project, make_tiers = patched_default_project
        WP1, = make_tiers(['WP1'])
    ```
    """
    Project = get_Project

    project = Project(DEFAULT_TIERS, tmp_path)
    project.setup_files()

    def create_tiers(names: Sequence[str]) -> Sequence[TierABC]:
        """
        Provide a list of tiers.

        These tiers will be created in order and all their files will be setup.
        """
        tiers = []

        for name in names:
            tier = project[name]

            parent = tier

            parents = []

            while parent:
                parents.append(parent)
                parent = parent.parent

            for child in reversed(parents):  # work from top down
                try:
                    child.setup_files()
                except FileExistsError:
                    pass

            tiers.append(tier)

        return tiers

    return project, create_tiers