def instantiate_node( env: Environment, graph: Graph, declared_node: DeclaredNode, ): if isinstance(declared_node.function, str): function = env.get_function(declared_node.function) else: function = make_function(declared_node.function) interface = function.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, function=function, params=declared_node.params, interface=interface, declared_inputs=declared_inputs, declared_schema_translation=schema_translations, output_alias=declared_node.output_alias, ) return n
def test_default_module(): DEFAULT_LOCAL_MODULE.library.functions = {} @datafunction def s1(): pass assert len(DEFAULT_LOCAL_MODULE.library.functions) == 1 assert DEFAULT_LOCAL_MODULE.get_function("s1") is s1 env = Environment() env.add_function(s1) assert env.get_function("s1") is s1
def env_init(env: Environment): from ._test_module import module as _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().namespace, _test_module.namespace, ] assert env.get_schema("TestSchema") is _test_module.schemas.TestSchema assert (env.get_function("test_sql_function") is _test_module.functions.test_sql_function) # Test runtime / storage env.add_storage("postgresql://test") assert len(env.storages) == 2 # added plus default local memory