예제 #1
0
        def to_toml(self, filename: Union[str, PathLike] = None, encoding: str = "utf-8", errors: str = "strict"):
            """
            Transform the Box object into a toml string.

            :param filename: File to write toml object too
            :param encoding: File encoding
            :param errors: How to handle encoding errors
            :return: string of TOML (if no filename provided)
            """
            return _to_toml(self.to_dict(), filename=filename, encoding=encoding, errors=errors)
예제 #2
0
        def to_toml(
            self,
            filename: Union[str, PathLike] = None,
            key_name: str = "toml",
            encoding: str = "utf-8",
            errors: str = "strict",
        ):
            """
            Transform the BoxList object into a toml string.

            :param filename: File to write toml object too
            :param key_name: Specify the name of the key to store the string under
                (cannot directly convert to toml)
            :param encoding: File encoding
            :param errors: How to handle encoding errors
            :return: string of TOML (if no filename provided)
            """
            return _to_toml({key_name: self.to_list()}, filename=filename, encoding=encoding, errors=errors)
예제 #3
0
 def test_to_toml_file(self):
     out_file = Path(tmp_dir, "toml_test.tml")
     assert not out_file.exists()
     _to_toml(movie_data, filename=out_file)
     assert out_file.exists()
     assert out_file.read_text().startswith("[movies.Spaceballs]")
예제 #4
0
 def test_to_toml(self):
     formatted = _to_toml(movie_data)
     assert formatted.startswith("[movies.Spaceballs]")