Ejemplo n.º 1
0
    def test_dump_path(self, tmpdir):
        from 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'
Ejemplo n.º 2
0
    def test_dump_file(self, tmpdir):
        from 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'
Ejemplo n.º 3
0
    def test_transform(self, tmpdir):
        from 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'