def test_parse_annotations(self, tmpdir): structure = { "base.yml": { "(finalized)": True, "counter": 1, "sub": { "?yes": "YES" } }, "file.yml": { "include": ["base.yml"], "finalized": False, "counter[add]": 3, "sub": { "?no": "NO", "?yes": "YES" } } } with file_structure(structure, tmpdir): loader = FileLoader(FancyDict, include_key="include") result = {"finalized": True, "counter": 4, "sub": {"yes": "YES"}} loaded = loader.load("file.yml", annotations_decoder=KeyAnnotationsConverter) assert result == loaded
def test_include_order(self, tmpdir): structure = { "file.yml": { "include": ["inc.yml"], "A": 0 }, "inc.yml": { "A": "1" } } with file_structure(structure, tmpdir): loader = FileLoader(FancyDict, include_key="include") assert {"A": 0} == loader.load("file.yml")
def test_include_file(self, tmpdir): structure = { "file.yml": { "include": ["inc.yml"], "key": "value" }, "inc.yml": { "inc_key": "value" } } with file_structure(structure, tmpdir): loader = FileLoader(FancyDict, include_key="include") result = {"key": "value", "inc_key": "value"} assert result == loader.load("file.yml")
def test_raise_file_not_found_but_in_bases(self, tmpdir): structure = { "inc": { "file.yml": { "include": ["inc.yml"], "key": "value" } } } with file_structure(structure, tmpdir): with pytest.raises(FileNotFoundError): FileLoader(FancyDict, include_paths=("inc", )).load("file.yml")
def test_raise_file_not_found(self, tmpdir): with file_structure({"file.yml": {"a": 1}}, tmpdir): with pytest.raises(FileNotFoundError): FileLoader(FancyDict).load("no_file.yml")
def test_single_file_in_directory(self, tmpdir): with file_structure({"dir": {"file.yml": {"a": 1}}}, tmpdir): assert {"a": 1} == FileLoader(FancyDict).load("dir/file.yml")
def test_can_load_false_if_os_error(self): with mock.patch("pathlib.Path.exists", side_effect=OSError): assert not FileLoader.can_load("os_error")
def test_can_load_false_if_url(self): assert not FileLoader.can_load("http://www.test.de")
def test_can_load(self, tmpdir): structure = {"base": {"file.yml": {"key": "value"}}} with file_structure(structure, tmpdir): assert FileLoader.can_load(Path("base", "file.yml")) assert not FileLoader.can_load("file.yml")
def test_no_include_key(self, tmpdir): structure = {"file.yml": {"include": "value"}} with file_structure(structure, tmpdir): loader = FileLoader(FancyDict, include_key=None) result = {"include": "value"} assert result == loader.load("file.yml")