def set_state_dict(self, state): """Reset the parser based on previous state""" self.parser.set_state_dict(state["parser"]) self.cmd_priors = OrderedDict(state["cmd_priors"]) self.file_priors = OrderedDict(state["file_priors"]) self.config_file_data = state["config_file_data"] self.config_prefix = state["config_prefix"] self.file_config_path = state["file_config_path"] if self.file_config_path: self.converter = infer_converter_from_file_type( self.file_config_path) self.converter.set_state_dict(state["converter"]) if "user_script" in state: self.user_script = state["user_script"] else: self.infer_user_script(self.parser.format(self.parser.arguments))
def test_unknown_file_ext(unknown_type_sample_path): """Check what happens if an unknown config type is given.""" converter = infer_converter_from_file_type(unknown_type_sample_path) assert isinstance(converter, GenericConverter)
def test_infer_a_json_converter(json_sample_path): """Infer a JSONConverter from file path string.""" json = infer_converter_from_file_type(json_sample_path) assert isinstance(json, JSONConverter)
def test_infer_a_yaml_converter(yaml_sample_path): """Infer a YAMLConverter from file path string.""" yaml = infer_converter_from_file_type(yaml_sample_path) assert isinstance(yaml, YAMLConverter)
def test_not_supported_file_ext(): """Check what happens if invalid ext is given.""" with pytest.raises(NotImplementedError) as exc: infer_converter_from_file_type("../naedw.py") assert "Supported" in str(exc.value)