示例#1
0
    def test_dump_dict(self):
        data = dumps({'a': {'d': 1}})
        loads(data)
        self.assertEquals(data, """\
a {
  d = 1
}
""")
示例#2
0
    def test_object_order_is_kept(self):
        """Verify that the items in objects are kept in order."""
        order = random.sample(range(100), 100)
        string = "\n".join("property%d = %d" % (i, i) for i in order)

        result = loads(string)
        for (key, value), i in zip(result.items(), order):
            self.assertEquals(value, i)

        new_string = dumps(result)
        self.assertEquals(string, str(new_string).rstrip())
示例#3
0
 def test_quoted_value(self):
     result = loads('key = "a#comment{}=#"')
     self.assertEquals(result['key'], 'a#comment{}=#')
示例#4
0
 def test_augment_object(self):
     result = loads('!include foo  #comment', handler)
     self.assertTrue('foo' in result)
     self.assertEquals(result['foo'], 'augmented')
示例#5
0
 def test_augment_value(self):
     result = loads('a = { !include foo }', handler)
     self.assertTrue(u'foo.value' in result['a'])
示例#6
0
 def test_false_bool(self):
     result = loads('a = false')
     self.assertFalse(result['a'])
示例#7
0
 def test_inline_comment(self):
     result = loads('key = value  #comment')
     self.assertEquals(result['key'], 'value')
示例#8
0
 def test_object_key_value(self):
     result = loads("a { key = value }")
     self.assertEquals(result['a']['key'], 'value')
示例#9
0
 def test_nested_objects(self):
     result = loads(u"a = { { b = c } { d = e } def abc }")
     self.assertEquals(len(result), 1)
     self.assertEquals(len(result['a']), 4)
     self.assertEquals(result['a'][2], 'def')
     self.assertEquals(result['a'][3], 'abc')
示例#10
0
 def test_object_key_value(self):
     result = loads("a { key = value }")
     self.assertEquals(result['a']['key'], 'value')
示例#11
0
 def test_comment_before_data(self):
     result = loads(u"#xxx\na { key = value }")
     self.assertEquals(result['a']['key'], 'value')
示例#12
0
 def test_quoted_key(self):
     result = loads('"key abc" = value')
     self.assertEquals(result['key abc'], 'value')
示例#13
0
 def test_empty_object(self):
     result = loads("a {}")
     self.assertEquals(result['a'], {})
示例#14
0
 def test_quoted_value(self):
     result = loads('key = "a#comment{}=#"')
     self.assertEquals(result['key'], 'a#comment{}=#')
示例#15
0
 def test_augment_value(self):
     result = loads('a = { !include foo }', handler)
     self.assertTrue(u'foo.value' in result['a'])
示例#16
0
 def test_augment_object(self):
     result = loads('!include foo  #comment', handler)
     self.assertTrue('foo' in result)
     self.assertEquals(result['foo'], 'augmented')
示例#17
0
 def test_quoted_key(self):
     result = loads('"key abc" = value')
     self.assertEquals(result['key abc'], 'value')
示例#18
0
 def test_nested_objects(self):
     result = loads(u"a = { { b = c } { d = e } def abc }")
     self.assertEquals(len(result), 1)
     self.assertEquals(len(result['a']), 4)
     self.assertEquals(result['a'][2], 'def')
     self.assertEquals(result['a'][3], 'abc')
示例#19
0
 def test_empty_object(self):
     result = loads("a {}")
     self.assertEquals(result['a'], {})
示例#20
0
    def test_escape_space(self):
        data = dumps({'a b': 1})
        loads(data)
        self.assertEquals(data, """\
"a b" = 1
""")
示例#21
0
 def test_comment_before_data(self):
     result = loads(u"#xxx\na { key = value }")
     self.assertEquals(result['a']['key'], 'value')
示例#22
0
    def test_dump_true_bool(self):
        data = dumps({'a': True})
        loads(data)
        self.assertEquals(data, """\
a = true
""")
示例#23
0
 def test_true_bool(self):
     result = loads('a = true')
     self.assertTrue(result['a'])
示例#24
0
    def test_escape_space(self):
        data = dumps({'a b': 1})
        loads(data)
        self.assertEquals(data, """\
"a b" = 1
""")
示例#25
0
 def test_key_value(self):
     result = loads('key = value')
     self.assertEquals(result['key'], 'value')
示例#26
0
 def test_key_value(self):
     result = loads('key = value')
     self.assertEquals(result['key'], 'value')
示例#27
0
    def test_dump_false_bool(self):
        data = dumps({'a': False})
        loads(data)
        self.assertEquals(data, """\
a = false
""")
示例#28
0
 def test_inline_comment(self):
     result = loads('key = value  #comment')
     self.assertEquals(result['key'], 'value')