Exemplo n.º 1
0
    def test_annotations(self):
        inp = '; one\n; two\n[foo]\n; three\nval1 = 123'
        w = parse_wax(inp)
        self.assertEquals(w._get_annotation('foo'), ' one\n two')
        self.assertEquals(w._annotations['foo'], ' one\n two')
        del w.foo.val1
        self.assertTrue('val1' not in w.foo._annotations)

        w = parse_wax(WELLFORMED)
        self.assertEquals(w.one._get_annotation('bar'), ' C 1\n C 2')
        self.assertEquals(w.one._annotations['bar'], ' C 1\n C 2')

        # make sure annotations are formatted in output
        out = str(w)
        self.assertTrue('; C 1\n; C 2\n' in out)

        # test for missing annotations
        self.assertEquals(w._get_annotation('xxxxxxx'), None)
        self.assertEquals(w._get_annotation('zzzzzzz', 'foo'), 'foo')

        # test for bad annotation type
        self.assertRaises(WaxError, w._set_annotation, 'foo', 123)

        # check removal
        w = Wax()
        w.a = 123
        w._set_annotation('a', 'hi there')
        self.assertEquals(w._get_annotation('a'), 'hi there')
        w._remove_annotation('a')
        self.assertEquals(w._annotations, {})
Exemplo n.º 2
0
    def test_annotations(self):
        inp = '; one\n; two\n[foo]\n; three\nval1 = 123'
        w = parse_wax(inp)
        self.assertEquals(w._get_annotation('foo'), ' one\n two')
        self.assertEquals(w._annotations['foo'], ' one\n two')
        del w.foo.val1
        self.assertTrue('val1' not in w.foo._annotations)

        w = parse_wax(WELLFORMED)
        self.assertEquals(w.one._get_annotation('bar'), ' C 1\n C 2')
        self.assertEquals(w.one._annotations['bar'], ' C 1\n C 2')

        # make sure annotations are formatted in output
        out = str(w)
        self.assertTrue('; C 1\n; C 2\n' in out)

        # test for missing annotations
        self.assertEquals(w._get_annotation('xxxxxxx'), None)
        self.assertEquals(w._get_annotation('zzzzzzz', 'foo'), 'foo')

        # test for bad annotation type
        self.assertRaises(WaxError, w._set_annotation, 'foo', 123)

        # check removal
        w = Wax()
        w.a = 123
        w._set_annotation('a', 'hi there')
        self.assertEquals(w._get_annotation('a'), 'hi there')
        w._remove_annotation('a')
        self.assertEquals(w._annotations, {})
Exemplo n.º 3
0
    def test_unicode_annotations(self):
        inp = u'; \u2018hi\u2019\nfoo = 123\n'.encode('utf-8')
        w = parse_wax(inp)
        exp = u' \u2018hi\u2019'
        self.assertEquals(w._get_annotation('foo'), exp)

        # check properly formatted utf-8 in output
        out = str(w)
        self.assertTrue(';' + exp.encode('utf-8') in out)
Exemplo n.º 4
0
    def test_unicode_annotations(self):
        inp = u'; \u2018hi\u2019\nfoo = 123\n'.encode('utf-8')
        w = parse_wax(inp)
        exp = u' \u2018hi\u2019'
        self.assertEquals(w._get_annotation('foo'), exp)

        # check properly formatted utf-8 in output
        out = str(w)
        self.assertTrue(';' + exp.encode('utf-8') in out)
Exemplo n.º 5
0
    def test_comments(self):
        inp = '# one\n# two\n[foo]\n# three\nbar = 123\n'
        w = parse_wax(inp)
        self.assertEquals(w._comments[0], ' one\n two')
        self.assertEquals(w.foo._comments[0], ' three')
        del w.bar
        self.assertEquals(w.foo._comments[0], ' three')
        w.foo._clear_comments()
        self.assertEquals(w.foo._comments, {})
        self.assertEquals(w._comments[0], ' one\n two')
        w._clear_comments()
        self.assertEquals(w._comments, {})

        # bad comments
        self.assertRaises(WaxError, w._add_comment, 123)
Exemplo n.º 6
0
    def test_comments(self):
        inp = '# one\n# two\n[foo]\n# three\nbar = 123\n'
        w = parse_wax(inp)
        self.assertEquals(w._comments[0], ' one\n two')
        self.assertEquals(w.foo._comments[0], ' three')
        del w.bar
        self.assertEquals(w.foo._comments[0], ' three')
        w.foo._clear_comments()
        self.assertEquals(w.foo._comments, {})
        self.assertEquals(w._comments[0], ' one\n two')
        w._clear_comments()
        self.assertEquals(w._comments, {})

        # bad comments
        self.assertRaises(WaxError, w._add_comment, 123)
Exemplo n.º 7
0
    def test_roundtrip(self):
        # construct
        w = Wax(foo=1, bar=[1, 2, 3])
        sub1 = Wax(state="AZ", city="Phoenix")
        sub2 = Wax(title=u"\u2018this is single quoted\u2019")
        sub3 = Wax(dict={"abc": {"key": "val", "float": 3.14159}})
        w.sub = sub1
        sub1.sub = sub2
        sub2.sub = sub3

        # serialize
        js = str(w)

        # parse and compare
        res = parse_wax(js)
        self.assertEquals(res, w)
Exemplo n.º 8
0
    def test_roundtrip(self):
        # construct
        w = Wax(foo=1, bar=[1,2,3])
        sub1 = Wax(state="AZ", city="Phoenix")
        sub2 = Wax(title=u"\u2018this is single quoted\u2019")
        sub3 = Wax(dict={"abc": {"key": "val", "float": 3.14159}})
        w.sub = sub1
        sub1.sub = sub2
        sub2.sub = sub3

        # serialize
        js = str(w)

        # parse and compare
        res = parse_wax(js)
        self.assertEquals(res, w)
Exemplo n.º 9
0
    def test_wellformed(self):
        w = parse_wax(WELLFORMED)
        self.assertEquals(w.str, "foo")
        self.assertEquals(w.num, 123)
        self.assertEquals(w.float, 3.14159)
        self.assertEquals(w.numexp, 300)
        self.assertEquals(w.true, True)
        self.assertEquals(w.false, False)
        self.assertEquals(w.null, None)
        self.assertEquals(w.dict, {"abc": 123, "list": [1, 2, 3]})
        self.assertEquals(w.list, ["this", "is", "json", "data"])
        self.assertEquals(w.unicode, u"\u2018this is quoted\u2019")

        # groups
        self.assertEquals(w.one.str, "foo")
        self.assertEquals(w.one.num, 123)
        self.assertEquals(w.one.two.str, "foo")

        self.assertEquals(w.a.b.c.d.e.f.g.num, 1)
        self.assertEquals(w.a.b.c.num, 1)
Exemplo n.º 10
0
    def test_wellformed(self):
        w = parse_wax(WELLFORMED)
        self.assertEquals(w.str, "foo")
        self.assertEquals(w.num, 123)
        self.assertEquals(w.float, 3.14159)
        self.assertEquals(w.numexp, 300)
        self.assertEquals(w.true, True)
        self.assertEquals(w.false, False)
        self.assertEquals(w.null, None)
        self.assertEquals(w.dict, {"abc": 123, "list": [1, 2, 3]})
        self.assertEquals(w.list, ["this", "is", "json", "data"])
        self.assertEquals(w.unicode, u"\u2018this is quoted\u2019")

        # groups
        self.assertEquals(w.one.str, "foo")
        self.assertEquals(w.one.num, 123)
        self.assertEquals(w.one.two.str, "foo")

        self.assertEquals(w.a.b.c.d.e.f.g.num, 1)
        self.assertEquals(w.a.b.c.num, 1)
Exemplo n.º 11
0
 def test_merge(self):
     w1 = Wax(foo=1)
     s = "bar=2\n[sub]\nbaz=3\n"
     parse_wax(s, w1)
     self.assertEquals(w1.bar, 2)
     self.assertEquals(w1.sub.baz, 3)
Exemplo n.º 12
0
 def test_dotted_keys(self):
     js = "foo.bar = 123\n"
     w = parse_wax(js)
     self.assertEquals(Wax(foo=Wax(bar=123)), w)
Exemplo n.º 13
0
 def test_parse_valid(self):
     for raw, expected in T_VALID:
         val = parse_wax(raw)
         self.assertEquals(val, expected)
Exemplo n.º 14
0
 def test_parse_append(self):
     w = Wax()
     w.foo = 1
     w += parse_wax('bar = 2\n[one.two]\nkey = "val"')
     self.assertEquals(w.bar, 2)
     self.assertEquals(w.one.two.key, "val")
Exemplo n.º 15
0
 def test_merge(self):
     w1 = Wax(foo=1)
     s = "bar=2\n[sub]\nbaz=3\n"
     parse_wax(s, w1)
     self.assertEquals(w1.bar, 2)
     self.assertEquals(w1.sub.baz, 3)
Exemplo n.º 16
0
 def test_unicode_comments(self):
     inp = u'# \u2018hi there\u2019\nfoo = 123\n'.encode('utf-8')
     w = parse_wax(inp)
     res = str(w)
     self.assertTrue(u'# \u2018hi there\u2019'.encode('utf-8') in res)
Exemplo n.º 17
0
 def test_unicode_comments(self):
     inp = u'# \u2018hi there\u2019\nfoo = 123\n'.encode('utf-8')
     w = parse_wax(inp)
     res = str(w)
     self.assertTrue(u'# \u2018hi there\u2019'.encode('utf-8') in res)
Exemplo n.º 18
0
 def test_dotted_keys(self):
     js = "foo.bar = 123\n"
     w = parse_wax(js)
     self.assertEquals(Wax(foo=Wax(bar=123)), w)
Exemplo n.º 19
0
 def test_parse_valid(self):
     for raw, expected in T_VALID:
         val = parse_wax(raw)
         self.assertEquals(val, expected)
Exemplo n.º 20
0
 def test_parse_append(self):
     w = Wax()
     w.foo = 1
     w += parse_wax('bar = 2\n[one.two]\nkey = "val"')
     self.assertEquals(w.bar, 2)
     self.assertEquals(w.one.two.key, "val")