def from_dict(cls, d: Dict[str, Any]) -> "DbtCliOutput": """Constructs an instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>` from a dictionary. Args: d (Dict[str, Any]): A dictionary with key-values to construct a :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`. Returns: DbtCliOutput: An instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`. """ return_code = check.int_elem(d, "return_code") raw_output = check.str_elem(d, "raw_output") num_pass = check.opt_int_elem(d, "num_pass") num_warn = check.opt_int_elem(d, "num_warn") num_error = check.opt_int_elem(d, "num_error") num_skip = check.opt_int_elem(d, "num_skip") num_total = check.opt_int_elem(d, "num_total") command = check.str_elem(d, "command") return cls( result=DbtResult.from_dict(d), return_code=return_code, raw_output=raw_output, num_pass=num_pass, num_warn=num_warn, num_error=num_error, num_skip=num_skip, num_total=num_total, command=command, )
def from_dict(cls, d: Dict[str, Any]) -> "DbtCliOutput": """Constructs an instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>` from a dictionary. Args: d (Dict[str, Any]): A dictionary with key-values to construct a :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`. Returns: DbtCliOutput: An instance of :class:`DbtCliOutput <dagster_dbt.DbtCliOutput>`. """ check.int_elem(d, "return_code") check.str_elem(d, "raw_output") check.opt_int_elem(d, "num_pass") check.opt_int_elem(d, "num_warn") check.opt_int_elem(d, "num_error") check.opt_int_elem(d, "num_skip") check.opt_int_elem(d, "num_total") d["result"] = DbtResult.from_dict(d) return cls(**d)
def test_opt_int_elem(): ddict = {"a_bool": True, "a_float": 1.0, "a_int": 1, "a_none": None, "a_str": "a"} assert check.opt_int_elem(ddict, "a_int") == 1 assert check.opt_int_elem(ddict, "a_none") == None assert check.opt_int_elem(ddict, "nonexistentkey") == None assert check.opt_int_elem(ddict, "a_bool") == True with pytest.raises(ElementCheckError): check.opt_int_elem(ddict, "a_float") with pytest.raises(ElementCheckError): check.opt_int_elem(ddict, "a_str")