Пример #1
0
    def test_serialize(self):
        store = yaml.YAMLFile()
        store.parse('key: value')
        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == b'key: value\n'
Пример #2
0
    def test_parse_unicode_list(self):
        store = yaml.YAMLFile()
        store.parse(u'list:\n- zkouška')

        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == u'list:\n- zkouška\n'.encode('utf-8')
Пример #3
0
    def test_ordering(self):
        store = yaml.YAMLFile()
        store.parse('''
foo: foo
bar: bar
baz: baz
''')

        assert store.units[0].source == 'foo'
        assert store.units[2].source == 'baz'
Пример #4
0
    def test_edit_unicode(self):
        store = yaml.YAMLFile()
        store.parse('key: value')

        store.units[0].settarget(u'zkouška')

        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == u'key: zkouška\n'.encode('utf-8')
Пример #5
0
    def test_edit(self):
        store = yaml.YAMLFile()
        store.parse('key: value')

        store.units[0].settarget('second')

        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == b'key: second\n'
Пример #6
0
    def test_nested(self):
        store = yaml.YAMLFile()
        store.parse('''
foo:
    bar: bar
    baz:
        boo: booo
''')

        assert store.units[0].getid() == 'foo / bar'
        assert store.units[0].source == 'bar'
        assert store.units[1].getid() == 'foo / baz / boo'
        assert store.units[1].source == 'booo'

        out = BytesIO()
        store.serialize(out)

        assert out.getvalue() == b'''foo:
Пример #7
0
 def test_invalid_value(self):
     store = yaml.YAMLFile()
     with pytest.raises(base.ParseError):
         store.parse('val: "\\u string"')
Пример #8
0
 def test_invalid_key(self):
     store = yaml.YAMLFile()
     with pytest.raises(base.ParseError):
         store.parse('1: string')
Пример #9
0
 def test_invalid_value(self):
     store = yaml.YAMLFile()
     assert pytest.raises(base.ParseError, store.parse, 'val: "\\u string"')
Пример #10
0
 def test_invalid_key(self):
     store = yaml.YAMLFile()
     assert pytest.raises(base.ParseError, store.parse, 'yes: string')