def test_empty_list_val(self): """Defining an empty list value is not allowed""" text = dedent(""" --- test_name: Test cannot send a set stages: - name: match top level request: url: "{host}/fake_dictionary" method: GET json: - a - - b response: status_code: 200 json: top: !anything """) with TestBadSchemaAtCollect.wrapfile_nondict(text) as filename: with pytest.raises(BadSchemaError): load_single_document_yaml(filename)
def test_load_utf8(self, value): """if yaml has utf8 char , may load error""" content = f"""a: {value}""" "" with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as f: f.write(content.encode("utf8")) try: load_single_document_yaml(f.name) finally: os.remove(f.name)
def test_load_multiple_fails(self): example = [{"a": "b"}, {"c": "d"}] with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as wrapped_tmp: # put into a file dumped = yaml.dump_all(example) wrapped_tmp.write(dumped.encode("utf8")) wrapped_tmp.close() try: with pytest.raises(exceptions.UnexpectedDocumentsError): load_single_document_yaml(wrapped_tmp.name) finally: os.remove(wrapped_tmp.name)
def _load_base_schema(self, schema_filename): try: return self._loaded[schema_filename] except KeyError: self._loaded[schema_filename] = load_single_document_yaml(schema_filename) logger.debug("Loaded schema from %s", schema_filename) return self._loaded[schema_filename]
def load_global_config(global_cfg_paths): """Given a list of file paths to global config files, load each of them and return the joined dictionary. This does a deep dict merge. Args: global_cfg_paths (list(str)): List of filenames to load from Returns: dict: joined global configs """ global_cfg = {} if global_cfg_paths: logger.debug("Loading global config from %s", global_cfg_paths) for filename in global_cfg_paths: contents = load_single_document_yaml(filename) global_cfg = deep_dict_merge(global_cfg, contents) return global_cfg
def test_load_one(self): example = {"a": "b"} with wrapfile(example) as f: assert example == load_single_document_yaml(f)