Пример #1
0
 def test_multiline_string():
     multiline_string = """this is just a
     multi line
     string
     """
     with pytest.raises(ValueError):
         deserialize(datasource=multiline_string)
Пример #2
0
 def test_yaml_scanner_error():
     not_yaml = """
     when not_yaml {
     yaml: false
     }
     """
     with pytest.raises(ValueError):
         deserialize(datasource=not_yaml)
Пример #3
0
    def test_yaml_scanner_error(fixture_mktmpfile):
        not_yaml_file = fixture_mktmpfile(data="""
        when not_yaml {
        yaml: false
        }
        """)

        with pytest.raises(ValueError):
            deserialize(datasource=not_yaml_file)
Пример #4
0
 def test_not_yaml_not_json():
     not_yaml_not_json = """
     {
     key: value
     array:
         - one
         - 2
         - "three"
     }
     """
     with pytest.raises(ValueError):
         deserialize(datasource=not_yaml_not_json)
Пример #5
0
    def test_yaml_from_file():
        result = deserialize(
            datasource="tests/testdata/functions/iterfiles/yaml/file.yaml")
        assert isinstance(result, dict)

        assert result["key"] == "value"
        assert result["array"][1] == "second"
    def _deserialize_includes(self,
                              includes: List[str],
                              register: bool = True) -> dict:
        """Iterates and expands over the list of includes and yields the deseriealized data.

        :param includes: List of include files
        :param register: Register include file to avoid double inclusion (Default: ``True``)
        """
        for include in includes:
            if not list(self._path_glob(include)):
                # Path().glob() didn't find any file
                raise AS3TemplateConfigurationError(
                    f"Include: {str(include)} doesn't exist or not a file (base_path:{self._base_path})."
                )

            # globbing potentially results in multiple files to include
            for include_file in sorted(self._path_glob(include)):
                if not include_file.is_file():
                    raise AS3TemplateConfigurationError(
                        f"Include: {str(include_file)} doesn't exist or not a file (base_path:{self._base_path})."
                    )
                # avoid including the same configuration template multiple times
                if register:
                    if str(include_file) in self._includes:
                        continue
                    self._includes.append(str(include_file))

                yield deserialize(str(include_file))
Пример #7
0
    def test_yaml():
        result = deserialize(datasource=yaml_str)
        assert isinstance(result, dict)

        assert result["key"] == "value"

        assert isinstance(result["array"][1], int)
        assert result["array"][1] == 2
Пример #8
0
    def test_non_standard_json():
        non_standard_json = "{ key: value,\n array:[one, 2, three] }"
        result = deserialize(datasource=non_standard_json)

        assert isinstance(result, dict)

        assert result["key"] == "value"

        assert isinstance(result["array"][1], int)
        assert result["array"][1] == 2
Пример #9
0
 def test_from_text_file_raises_ValueError():
     with pytest.raises(ValueError):
         deserialize(datasource="tests/testdata/functions/iterfiles/text/file.txt")
Пример #10
0
 def test_str_from_file():
     result = deserialize(
         datasource="tests/testdata/functions/iterfiles/text/file.txt", return_as=str
     )
     assert isinstance(result, str)
Пример #11
0
 def test_yaml_as_str():
     # TODO: fix test - see deserialize utils for more details
     # deserialze should not be used to read data from a str and return it as a str if the first isnt a file
     result = deserialize(datasource=yaml_str, return_as=str)
     assert isinstance(result, str)
     assert result == yaml_str
Пример #12
0
 def test_simple_string():
     with pytest.raises(ValueError):
         deserialize(datasource="simple string")
Пример #13
0
 def test_simple_string():
     with pytest.raises(FileNotFoundError):
         deserialize(datasource="does/not/exist.file")