Ejemplo n.º 1
0
def instantiate_node(
    env: Environment,
    graph: Graph,
    declared_node: DeclaredNode,
):
    if isinstance(declared_node.snap, str):
        snap = env.get_snap(declared_node.snap)
    else:
        snap = make_snap(declared_node.snap)
    interface = snap.get_interface()
    schema_translations = interface.assign_translations(
        declared_node.schema_translations
    )
    declared_inputs: Dict[str, DeclaredStreamInput] = {}
    if declared_node.inputs is not None:
        for name, stream_like in interface.assign_inputs(declared_node.inputs).items():
            declared_inputs[name] = DeclaredStreamInput(
                stream=ensure_stream(stream_like),
                declared_schema_translation=(schema_translations or {}).get(name),
            )
    n = Node(
        graph=graph,
        key=declared_node.key,
        snap=snap,
        params=declared_node.params,
        interface=interface,
        declared_inputs=declared_inputs,
        declared_schema_translation=schema_translations,
        output_alias=declared_node.output_alias,
    )
    return n
Ejemplo n.º 2
0
def test_default_module():
    DEFAULT_LOCAL_MODULE.library.snaps = {}

    @Snap
    def s1():
        pass

    assert len(DEFAULT_LOCAL_MODULE.library.snaps) == 1
    assert DEFAULT_LOCAL_MODULE.get_snap("s1") is s1

    env = Environment()
    env.add_snap(s1)
    assert env.get_snap("s1") is s1
Ejemplo n.º 3
0
def env_init(env: Environment):
    from . import _test_module

    # Test module / components
    with env.md_api.begin():
        assert len(env.get_module_order()) == 1
        env.add_module(_test_module)
        assert env.get_module_order() == [
            env.get_local_module().name,
            _test_module.name,
        ]
        assert env.get_schema("TestSchema") is _test_module.schemas.TestSchema
        assert env.get_snap("test_sql") is _test_module.snaps.test_sql
        # Test runtime / storage
        env.add_storage("postgresql://test")
        assert len(env.storages) == 2  # added plus default local memory
        assert len(env.runtimes) == 2  # added plus default local python