def test_opt_dict_elem(): dict_value = {'blah': 'blahblah'} ddict = {'dictkey': dict_value, 'stringkey': 'A', 'nonekey': None} assert check.opt_dict_elem(ddict, 'dictkey') == dict_value assert check.opt_dict_elem(ddict, 'nonekey') == {} assert check.opt_dict_elem(ddict, 'nonexistantkey') == {} with pytest.raises(CheckError): check.opt_dict_elem(ddict, 'stringkey')
def test_opt_dict_elem(): dict_value = {"blah": "blahblah"} ddict = {"dictkey": dict_value, "stringkey": "A", "nonekey": None} assert check.opt_dict_elem(ddict, "dictkey") == dict_value assert check.opt_dict_elem(ddict, "nonekey") == {} assert check.opt_dict_elem(ddict, "nonexistantkey") == {} with pytest.raises(CheckError): check.opt_dict_elem(ddict, "stringkey")
def configurable_class_data(config_field): return ConfigurableClassData( check.str_elem(config_field, "module"), check.str_elem(config_field, "class"), yaml.dump(check.opt_dict_elem(config_field, "config"), default_flow_style=False), )
def from_dict(cls, d: Dict[str, Any]) -> "NodeResult": """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary. Args: d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult <dagster_dbt.NodeResult>`. Returns: NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`. """ node = check.dict_elem(d, "node") error = check.opt_str_elem(d, "error") execution_time = check.float_elem(d, "execution_time") thread_id = check.opt_str_elem(d, "thread_id") check.list_elem(d, "timing") step_timings = [ StepTiming( name=d["name"], started_at=parser.isoparse(d["started_at"]), completed_at=parser.isoparse(d["completed_at"]), ) for d in check.is_list(d["timing"], of_type=Dict) ] table = check.opt_dict_elem(d, "table") return cls( step_timings=step_timings, node=node, error=error, execution_time=execution_time, thread_id=thread_id, table=table, )
def _construct_context(yml_config_object): context_obj = check.opt_dict_elem(yml_config_object, 'context') if context_obj: return Context( check.opt_str_elem(context_obj, 'name'), context_obj.get('config'), ) else: return None
def from_dict(cls, d: Dict[str, Any]) -> "NodeResult": """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary. Args: d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult <dagster_dbt.NodeResult>`. Returns: NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`. """ check.dict_elem(d, "node") check.opt_str_elem(d, "error") check.float_elem(d, "execution_time") check.opt_str_elem(d, "thread_id") check.list_elem(d, "timing") check.is_list(d["timing"], of_type=Dict) check.opt_dict_elem(d, "table") return cls(step_timings=d.get("timing"), **d)
def _construct_solids(yml_config_object): solid_dict = check.opt_dict_elem(yml_config_object, 'solids') if solid_dict is None: return None solid_configs = {} for solid_name, solid_yml_object in solid_dict.items(): config_value = solid_yml_object['config'] solid_configs[solid_name] = Solid(config_value) return solid_configs
def entrypoint_from_yaml(file_path): check.str_param(file_path, 'file_path') config = load_yaml_from_path(file_path) repository_config = check.dict_elem(config, 'repository') module_name = check.opt_str_elem(repository_config, 'module') file_name = check.opt_str_elem(repository_config, 'file') fn_name = check.str_elem(repository_config, 'fn') kwargs = check.opt_dict_elem(repository_config, 'kwargs') if module_name: return entrypoint_from_module_target(module_name, fn_name, kwargs) else: # rebase file in config off of the path in the config file file_name = os.path.join(os.path.dirname(os.path.abspath(file_path)), file_name) return entrypoint_from_file_target(file_name, fn_name, kwargs)
def from_dict(cls, d: Dict[str, Any]) -> "NodeResult": """Constructs an instance of :class:`NodeResult <dagster_dbt.NodeResult>` from a dictionary. Args: d (Dict[str, Any]): A dictionary with key-values to construct a :class:`NodeResult <dagster_dbt.NodeResult>`. Returns: NodeResult: An instance of :class:`NodeResult <dagster_dbt.NodeResult>`. """ # When executing from the CLI in 0.19.x, we get unique_id as a top level attribute if "unique_id" in d: unique_id = check.str_elem(d, "unique_id") node = None # When executing via RPC server or via CLI in 0.18.x or lower, we get unique id within # "node" schema else: node = check.dict_elem(d, "node") unique_id = check.str_elem(node, "unique_id") error = check.opt_str_elem(d, "error") execution_time = check.float_elem(d, "execution_time") thread_id = check.opt_str_elem(d, "thread_id") check.list_elem(d, "timing") step_timings = [ StepTiming( name=d["name"], started_at=parser.isoparse(d["started_at"]), completed_at=parser.isoparse(d["completed_at"]), ) for d in check.is_list(d["timing"], of_type=Dict) ] table = check.opt_dict_elem(d, "table") return cls( node=node, unique_id=unique_id, step_timings=step_timings, error=error, execution_time=execution_time, thread_id=thread_id, table=table, )