示例#1
0
def site_registry(site: Site) -> Registry:
    """A fixture for a configured registry."""
    r = Registry()
    r.register(site)
    r.scan(url)
    current_resource = site["d1"]
    r.register(current_resource, kind=Resource)
    return r
示例#2
0
 def __call__(
     self,
     registry: Registry,
 ) -> dict[str, Any]:
     """Get the instance from the registry, convert to dict."""
     value = registry.get(self.lookup_type)
     return asdict(value)
示例#3
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)
示例#4
0
def nullster_registry(site_registry: Registry) -> Registry:
    """A registry configured for the Nullster theme."""
    r = Registry(parent=site_registry)
    r.setup(nullster)
    r.scan(nullster)
    return r
示例#5
0
def hopscotch_setup(registry: Registry) -> None:
    """Setup this package."""
    static_src = StaticSrc(here, source=Path("static"))
    registry.register(static_src)
示例#6
0
def test_index_view(nullster_registry: Registry) -> None:
    """Check the index view."""
    view = cast(IndexView, nullster_registry.get(View))
    assert view.page_title == "View"
    assert view.resource_title == "D1"
示例#7
0
def nullster_config(nullster_registry: Registry) -> NullsterConfig:
    """Get the Nullster config instance."""
    nullster_config = nullster_registry.get(Config)
    return cast(NullsterConfig, nullster_config)
示例#8
0
 def get_path_function(registry: Registry) -> StaticRelativePath:
     """Isolate this so PathTo and StaticPathTo can share."""
     return registry.get(StaticRelativePath)
示例#9
0
def test_config() -> None:
    """Lookup a registered configuration."""
    registry = Registry()
    registry.scan()
    result = cast(SomeConfig, registry.get(Config))
    assert "My Site" == result.title
示例#10
0
def test_view2() -> None:
    """Lookup a registered view for a context."""
    registry = Registry(context=SomeCustomer())
    registry.scan()
    result = cast(View2, registry.get(View))
    assert "Some Customer" == result.customer_title
示例#11
0
def test_view1() -> None:
    """Lookup a registered view."""
    registry = Registry()
    registry.scan()
    result = cast(View1, registry.get(View))
    assert "View1" == result.title
示例#12
0
def test_staticpathto_field(nullster_registry: Registry, site: Site) -> None:
    """See if the staticathto field helper for dataclass works."""
    nullster_registry.scan()
    target = nullster_registry.get(Target)
    assert PurePosixPath("/f1/d2") == target.this_static_path