def test_dump_missing_stream(self): from srsly.ruamel_yaml import YAML yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 with pytest.raises(TypeError): yaml.dump(data)
def test_dump_too_many_args(self, tmpdir): from srsly.ruamel_yaml import YAML fn = Path(str(tmpdir)) / "test.yaml" yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 with pytest.raises(TypeError): yaml.dump(data, fn, True)
def test_dump_path(self, tmpdir): from srsly.ruamel_yaml import YAML fn = Path(str(tmpdir)) / "test.yaml" yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 yaml.dump(data, fn) assert fn.read_text() == "a: 1\nb: 2\n"
def test_print(self, capsys): from srsly.ruamel_yaml import YAML yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 yaml.dump(data, sys.stdout) out, err = capsys.readouterr() assert out == "a: 1\nb: 2\n"
def test_dump_file(self, tmpdir): from srsly.ruamel_yaml import YAML fn = Path(str(tmpdir)) / "test.yaml" yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 with open(str(fn), "w") as fp: yaml.dump(data, fp) assert fn.read_text() == "a: 1\nb: 2\n"
def test_flow_style(self, capsys): # https://stackoverflow.com/questions/45791712/ from srsly.ruamel_yaml import YAML yaml = YAML() yaml.default_flow_style = None data = yaml.map() data["b"] = 1 data["a"] = [[1, 2], [3, 4]] yaml.dump(data, sys.stdout) out, err = capsys.readouterr() assert out == "b: 1\na:\n- [1, 2]\n- [3, 4]\n"
def test_transform(self, tmpdir): from srsly.ruamel_yaml import YAML def tr(s): return s.replace(" ", " ") fn = Path(str(tmpdir)) / "test.yaml" yaml = YAML() data = yaml.map() data["a"] = 1 data["b"] = 2 yaml.dump(data, fn, transform=tr) assert fn.read_text() == "a: 1\nb: 2\n"