Esempio n. 1
0
def test_find_resource_missing_slash(site: Site) -> None:
    """Missing slash at path beginning should give ValueError."""
    path = PurePosixPath("f1/XXX")
    with pytest.raises(ValueError) as exc:
        find_resource(site, path)
    expected = 'ResourceLike path "f1/XXX" must start with a slash'
    assert expected == exc.value.args[0]
Esempio n. 2
0
def test_resource_path(
    target: PurePosixPath, expected: PurePosixPath, site: Site
) -> None:
    """Check nested resource paths."""
    r = find_resource(site, target)
    path = resource_path(r)
    assert expected == path
Esempio n. 3
0
def test_parents(
    this_path: PurePosixPath,
    expected: tuple[tuple[str, PurePosixPath]],
    site: Site,
) -> None:
    """Ensure the lineage is setup correctly."""
    resource = find_resource(site, this_path)
    results = parents(resource)
    result = tuple((resource.name, resource_path(resource)) for resource in results)
    assert expected == result
Esempio n. 4
0
    def __call__(
        self,
        registry: Registry,
    ) -> PurePosixPath | str | None:
        """Run the operator."""
        if isinstance(self.lookup_key, str):
            # Make a PurePosixPath then look up
            site = registry.get(Site)
            target = find_resource(site, PurePosixPath(self.lookup_key))
        elif isinstance(self.lookup_key, PurePosixPath):
            # Get the resource from the root and make it the target
            site = registry.get(Site)
            target = find_resource(site, self.lookup_key)
        elif self.lookup_key is not None:
            # We were passed something to go look up
            target = registry.get(self.lookup_key)
        else:
            return None

        relative_path = self.get_path_function(registry)
        return relative_path(target)
Esempio n. 5
0
def test_find_resource_failed(path: PurePosixPath, expected: str, site: Site) -> None:
    """Provide a bogus path and get a LookupError."""
    with pytest.raises(KeyError) as exc:
        find_resource(site, path)
    assert expected == exc.value.args[0]
Esempio n. 6
0
def test_find_resource(path: PurePosixPath, expected: str, site: Site) -> None:
    """Use the site fixture to see if find_resource logic works."""
    resource = find_resource(site, path)
    assert resource.name == expected