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)
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)
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]")
def test_to_toml(self): formatted = _to_toml(movie_data) assert formatted.startswith("[movies.Spaceballs]")