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
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)
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)
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
def hopscotch_setup(registry: Registry) -> None: """Setup this package.""" static_src = StaticSrc(here, source=Path("static")) registry.register(static_src)
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"
def nullster_config(nullster_registry: Registry) -> NullsterConfig: """Get the Nullster config instance.""" nullster_config = nullster_registry.get(Config) return cast(NullsterConfig, nullster_config)
def get_path_function(registry: Registry) -> StaticRelativePath: """Isolate this so PathTo and StaticPathTo can share.""" return registry.get(StaticRelativePath)
def test_config() -> None: """Lookup a registered configuration.""" registry = Registry() registry.scan() result = cast(SomeConfig, registry.get(Config)) assert "My Site" == result.title
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
def test_view1() -> None: """Lookup a registered view.""" registry = Registry() registry.scan() result = cast(View1, registry.get(View)) assert "View1" == result.title
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