示例#1
0
def main():
    # The app
    registry = InjectorRegistry()
    registry.scan()

    # Per "request"
    container = registry.create_injectable_container()
    result = render(html('<{Greeting}/>'), container)

    expected = '<h1>Hello Settings</h1>'
    return expected, result
示例#2
0
def test():
    registry = InjectorRegistry()
    registry.scan()  # Look for decorators in/below current package

    # Per "request"
    container = registry.create_injectable_container()
    view: View = container.get(View)
    result = view.name
    expected = 'View - My Site'

    return expected, result
示例#3
0
def test_injector_container_inject_props():
    # Instead of using .get, use .inject to pass props
    @dataclass
    class Heading:
        first_name: str = 'Default Name'

    registry = InjectorRegistry()
    registry.register_injectable(Heading, Heading, use_props=True)
    container = registry.create_injectable_container()
    heading: Heading = container.inject(Heading, first_name='Injected Name')
    assert 'Injected Name' == heading.first_name
示例#4
0
def test_injector_container_get():
    # Use .get and the wired factory that is stamped on the callable
    @dataclass
    class Heading:
        name: str = 'Default Name'

    registry = InjectorRegistry()
    registry.register_injectable(Heading, Heading, use_props=True)
    container = registry.create_injectable_container()
    heading: Heading = container.get(Heading)
    assert 'Default Name' == heading.name
示例#5
0
def test_wired_renderer_non_void(registry: InjectorRegistry):
    @dataclass
    class NonVoid:
        def __call__(self):
            return html('<i class="icon"></i>')

    registry.register_injectable(NonVoid, NonVoid)
    container = registry.create_injectable_container()
    expected = '<i class="icon"></i>'
    actual = render(html('<{NonVoid} />'), container=container)
    assert expected == actual
示例#6
0
def test():
    # The app
    registry = InjectorRegistry()
    registry.scan()

    # Per "request"
    container = registry.create_injectable_container()
    view = container.inject(View, view_name='Prop View')
    result = view.view_name
    expected = 'Prop View'

    return expected, result
示例#7
0
def test():
    registry = InjectorRegistry()
    registry.scan()  # Look for decorators in/below current package

    # Per "request"
    customer = Customer()
    container = registry.create_injectable_container(context=customer, )
    view: View = container.get(View)
    result = view.name
    expected = 'Hello Fred'

    return expected, result
示例#8
0
def main():
    # The app
    registry = InjectorRegistry()
    registry.scan()

    # Per "request"
    container = registry.create_injectable_container()
    first_name = "Prop"  # noqa: F841
    result = render(html('<{Greeting} first_name={first_name} />'), container)

    expected = '<h1>Hello Prop</h1>'
    return expected, result
示例#9
0
def test():
    # The app
    registry = InjectorRegistry()
    registry.scan()

    # Per "request"
    container = registry.create_injectable_container()
    view: View = container.get(View)
    result = view.name
    expected = 'View - My Site'

    return expected, result
示例#10
0
def main():
    # The app
    registry = InjectorRegistry()
    # Scan the app, then the plugins, then the site
    registry.scan()
    [registry.scan(plugin) for plugin in site.plugins]
    registry.scan(site)

    # Per "request"
    container = registry.create_injectable_container()
    LOGO_SRC = 'logo.png'  # noqa: F841
    result = render(html('<{Navbar} logo_src={LOGO_SRC} />'), container)

    expected = '<nav><img src="logo.png"/></nav>'
    return expected, result
示例#11
0
def main():
    # The app
    registry = InjectorRegistry()
    [registry.scan(plugin) for plugin in plugins]
    registry.scan()

    # Per "request"
    container = registry.create_injectable_container()
    result = render(html('<{Greeting}><span>Children</span><//>'), container)

    expected = '<h1>Hello Site</h1>'
    return expected, result
示例#12
0
def main():
    # The app
    registry = InjectorRegistry()
    [registry.scan(plugin) for plugin in plugins]
    registry.scan()

    # Per "request"
    customer = Customer(name='Mary')
    container = registry.create_injectable_container(context=customer, )
    result = render(html('<{Greeting}/>'), container)

    expected = '<h1>Hello Mary</h1>'
    return expected, result
def registry() -> InjectorRegistry:
    registry = InjectorRegistry()
    registry.scan()
    return registry
def test_wired_renderer_second(registry: InjectorRegistry):
    container = registry.create_injectable_container(context=SecondContext())
    expected = '<h1>Hello World... Second Context</h1>'
    actual = render(html('''<{Heading} person="World"/>'''), container)
    assert expected == actual
示例#15
0
def french_container() -> ServiceContainer:
    this_registry = InjectorRegistry()
    this_registry.scan(factories)
    c = this_registry.create_injectable_container(context=FrenchCustomer(), )
    return c
示例#16
0
def registry() -> InjectorRegistry:
    registry = InjectorRegistry()
    registry.scan()
    register_dataclass(registry, Settings)
    return registry
示例#17
0
def test_injector_registry_scan_caller():
    registry = InjectorRegistry()
    ds = DummyScan()
    registry.scanner.scan = ds
    registry.scan()
    assert 'tests' == ds.called_with.__name__  # type: ignore
示例#18
0
def test_injector_registry_scan_string():
    registry = InjectorRegistry()
    ds = DummyScan()
    registry.scanner.scan = ds
    registry.scan('examples.index')
    assert 'examples.index' == ds.called_with.__name__  # type: ignore
示例#19
0
def test_injector_registry_construction():
    registry = InjectorRegistry()
    assert hasattr(registry, 'scanner')
    assert hasattr(registry, 'scan')
示例#20
0
def registry() -> InjectorRegistry:
    r = InjectorRegistry()
    return r
示例#21
0
def test_wired_renderer_simplest_container(registry: InjectorRegistry):
    registry.register_injectable(Heading, Heading)
    container = registry.create_injectable_container()
    expected = '<h1>Hello</h1>'
    actual = render(html('''<{Heading}/>'''), container=container)
    assert expected == actual
示例#22
0
def test_wired_renderer_simplest_propoverride(registry: InjectorRegistry):
    registry.register_injectable(Heading, Heading)
    container = registry.create_injectable_container()
    expected = '<h1>Override</h1>'
    actual = render(html('<{Heading} name="Override"/>'), container=container)
    assert expected == actual