Beispiel #1
0
    def xtest_nested_basic_06(self):
        doc = Elem()

        doc.a = 1
        doc.a.bb = 2
        doc.a.b.cc = 3
        doc.a.b.c.dd = 4
        doc.a.b.c.d.e = 5
        doc.a.b.c.d.ee = 6

        out = bunchify(doc.to_dict())

        self.assertEquals(out.a.text, 1)
        self.assertEquals(getattr(out.a.b, 'text', does_not_exist), does_not_exist)
        self.assertEquals(out.a.bb, 2)
        self.assertEquals(out.a.b.cc, 3)
        self.assertEquals(out.a.b.c.dd, 4)
        self.assertEquals(out.a.b.c.d.e, 5)
        self.assertEquals(out.a.b.c.d.ee, 6)

        out = bunchify(doc.a.to_dict())

        self.assertEquals(out.a.text, 1)
        self.assertEquals(getattr(out.a.b, 'text', does_not_exist), does_not_exist)
        self.assertEquals(out.a.bb, 2)
        self.assertEquals(out.a.b.cc, 3)
        self.assertEquals(out.a.b.c.dd, 4)
        self.assertEquals(out.a.b.c.d.e, 5)
        self.assertEquals(out.a.b.c.d.ee, 6)
Beispiel #2
0
    def xtest_text_key_custom_03(self):
        doc = Elem()

        doc.a = 1
        doc.a.b = 2
        doc.a.b.c = 3
        doc.a.b.c.d = 4
        doc.a.b.c.d.e = 5

        # Integer rather than text
        text_key = 123

        expected = {'a': {'b': {'c': {'d': {text_key: 4, 'e': 5}, text_key: 3}, text_key: 2}, text_key: 1}}
        out = doc.to_dict(text_key)
        self.assertDictEqual(expected, out)

        expected = {'a': {'b': {'c': {'d': {'e': 5, text_key: 4}, text_key: 3}, text_key: 2}, text_key: 1}}
        out = doc.a.to_dict(text_key)
        self.assertDictEqual(expected, out)

        expected = {'b': {'c': {text_key: 3, 'd': {'e': 5, text_key: 4}}, text_key: 2}}
        out = doc.a.b.to_dict(text_key)
        self.assertDictEqual(expected, out)

        expected = {'c': {'d': {'e': 5, text_key: 4}, text_key: 3}}
        out = doc.a.b.c.to_dict(text_key)
        self.assertDictEqual(expected, out)

        expected = {'d': {text_key: 4, 'e': 5}}
        out = doc.a.b.c.d.to_dict(text_key)
        self.assertDictEqual(expected, out)

        expected = {'e': 5}
        out = doc.a.b.c.d.e.to_dict(text_key)
        self.assertDictEqual(expected, out)
Beispiel #3
0
    def xtest_text_key_default(self):
        doc = Elem()

        doc.a = 1
        doc.a.b = 2
        doc.a.b.c = 3
        doc.a.b.c.d = 4
        doc.a.b.c.d.e = 5

        expected = {'a': {'b': {'c': {'d': {'text': 4, 'e': 5}, 'text': 3}, 'text': 2}, 'text': 1}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)

        expected = {'a': {'b': {'c': {'d': {'e': 5, 'text': 4}, 'text': 3}, 'text': 2}, 'text': 1}}
        out = doc.a.to_dict()
        self.assertDictEqual(expected, out)

        expected = {'b': {'c': {'text': 3, 'd': {'e': 5, 'text': 4}}, 'text': 2}}
        out = doc.a.b.to_dict()
        self.assertDictEqual(expected, out)

        expected = {'c': {'d': {'e': 5, 'text': 4}, 'text': 3}}
        out = doc.a.b.c.to_dict()
        self.assertDictEqual(expected, out)

        expected = {'d': {'text': 4, 'e': 5}}
        out = doc.a.b.c.d.to_dict()
        self.assertDictEqual(expected, out)

        expected = {'e': 5}
        out = doc.a.b.c.d.e.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #4
0
    def test_contains_elem_parent_ns(self):
        doc = Elem()
        doc.ns_map = {'ee':'example.com'}
        doc.a.b.ee_c = '123'

        # Has NS map
        doc2 = Elem()
        doc2.ns_map = {'ee':'example.com'}
        doc2.zz.qq.ee_c = '456'
        doc2.zz.qq.d = '789'

        # No NS map yet the prefix is the same
        doc3 = Elem()
        doc3.zz.qq.ee_c = '456'
        doc3.zz.qq.d = '789'

        self.assertIn('ee_c', doc.a.b)
        self.assertNotIn('c', doc.a.b)
        self.assertNotIn('ee_d', doc.a.b)

        self.assertIn(doc2.zz.qq.ee_c, doc.a.b)
        self.assertNotIn(doc2.zz.qq.ee_d, doc.a.b)

        self.assertIn(doc3.zz.qq.ee_c, doc.a.b)
        self.assertNotIn(doc3.zz.qq.ee_d, doc.a.b)
Beispiel #5
0
    def test_append_to_list1(self):
        doc = Elem()
        doc.a.append(123)

        expected = {"a": [123]}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #6
0
    def xtest_direct3(self):
        doc = Elem()

        doc.a[0]

        expected = {'a':[None]}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #7
0
    def xtest_indirect1(self):
        doc = Elem()

        doc.a.b[0] = '000'

        expected = {'a': {'b': ['000']}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #8
0
    def xtest_attr_prefix_custom_len1(self):
        doc = Elem()
        doc.a = 123
        doc.a._b = 456

        expected = {'a': {'%b': 456, u'text': 123}}
        out = doc.to_dict(attr_prefix='%')
        self.assertDictEqual(expected, out)
Beispiel #9
0
    def xtest_simple_03(self):
        doc = Elem()

        doc.a = 123
        doc.a._b = 456

        expected = {'a': {'#b': 456, u'text': 123}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #10
0
    def xtest_nested_basic_03(self):
        doc = Elem()

        doc.a = 1
        doc.a.bb = 2
        doc.a.b.c = 3
        doc.a.b.c.d = 4
        doc.a.b.c.d.e = 5

        out = bunchify(doc.to_dict())

        self.assertEquals(out.a.text, 1)
        self.assertEquals(getattr(out.a.b, 'text', does_not_exist), does_not_exist)
        self.assertEquals(out.a.bb, 2)
        self.assertEquals(out.a.b.c.text, 3)
        self.assertEquals(out.a.b.c.d.text, 4)
        self.assertEquals(out.a.b.c.d.e, 5)

        out = bunchify(doc.a.to_dict())

        self.assertEquals(out.a.text, 1)
        self.assertEquals(out.a.bb, 2)
        self.assertEquals(out.a.b.c.text, 3)
        self.assertEquals(out.a.b.c.d.text, 4)
        self.assertEquals(out.a.b.c.d.e, 5)

        out = bunchify(doc.a.bb.to_dict())

        self.assertEquals(out.bb, 2)
        expected = {'bb': 2}
        self.assertDictEqual(expected, out)

        out = bunchify(doc.a.b.to_dict())

        self.assertEquals(getattr(out.b, 'text', does_not_exist), does_not_exist)
        self.assertEquals(out.b.c.text, 3)
        self.assertEquals(out.b.c.d.text, 4)
        self.assertEquals(out.b.c.d.e, 5)

        out = bunchify(doc.a.b.c.to_dict())

        self.assertEquals(out.c.text, 3)
        self.assertEquals(out.c.d.text, 4)
        self.assertEquals(out.c.d.e, 5)

        out = bunchify(doc.a.b.c.d.to_dict())

        self.assertEquals(out.d.text, 4)
        self.assertEquals(out.d.e, 5)
        expected = {'d': {'e': 5, 'text': 4}}
        self.assertDictEqual(expected, out)

        out = bunchify(doc.a.b.c.d.e.to_dict())

        self.assertEquals(out.e, 5)
        expected = {'e': 5}
        self.assertDictEqual(expected, out)
Beispiel #11
0
    def xtest_top_level_list_simple1(self):
        doc = Elem()

        doc.a[0]

        expected = {'a':[None]}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #12
0
    def xtest_top_level_attrs_no_ns(self):
        doc = Elem()

        doc._a = 'a'
        doc._b = 'b'

        expected = {'#a':'a', '#b':'b'}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #13
0
    def xtest_top_level_elems_no_ns(self):
        doc = Elem()

        doc.a = 'a'
        doc.b = 'b'

        expected = {'a':'a', 'b':'b'}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #14
0
    def xtest_indirect3(self):
        doc = Elem()
        doc.ns_map += {'ns0':'example.com'}

        doc.ns0_a.b[0]

        expected = {'ns0_a': {'b': [None]}}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #15
0
    def xtest_indirect1(self):
        doc = Elem()
        doc.ns_map += {'ns0':'example.com'}

        doc.a.ns0_b[0] = '000'

        expected = {'a': {'ns0_b': ['000']}}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #16
0
    def xtest_top_level_list_value1(self):
        doc = Elem()

        doc.a[0] = 'a0'

        expected = {'a':['a0']}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #17
0
    def xtest_attr_prefix_default(self):
        doc = Elem()

        doc.a = 123
        doc.a._b = 456

        expected = {'a': {'#b': 456, u'text': 123}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #18
0
    def xtest_indirect4(self):
        doc = Elem()

        doc.a.b[0]
        doc.a.b[1]

        expected = {'a': {'b': [None, None]}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #19
0
    def xtest_direct2(self):
        doc = Elem()

        doc.a[0] = '000'
        doc.a[1] = '111'

        expected = {'a':['000', '111']}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #20
0
    def test_append_to_list6(self):
        doc = Elem()
        doc.a[0] = 123
        doc.a.append(456)
        doc.a[2] = 789

        expected = {"a": [123, 456, 789]}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #21
0
    def test_append_to_list3(self):
        doc = Elem()
        doc.a[0] = 0
        doc.a[1] = 1
        doc.a.append(123)

        expected = {"a": [0, 1, 123]}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #22
0
    def xtest_direct4(self):
        doc = Elem()
        doc.ns_map += {'ns0':'example.com'}

        doc.ns0_a[0]
        doc.ns0_a[1]

        expected = {'ns0_a':[None, None]}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #23
0
    def test_append_to_list1(self):

        doc = Elem()
        doc.ns_map += {"ns0": "example.com"}
        doc.ns0_a[0] = 123

        expected = {"ns0_a": [123]}
        out = doc.to_dict(include_ns=True)

        self.assertDictEqual(expected, out)
Beispiel #24
0
    def xtest_nested_order1(self):
        doc = Elem()

        doc.a1.b1 = 'b1'
        doc.a2 = 'a2'

        expected = {'a1': {'b1': 'b1'}, 'a2':'a2'}
        out = doc.to_dict()

        self.assertDictEqual(expected, out)
Beispiel #25
0
    def xtest_direct2(self):
        doc = Elem()
        doc.ns_map += {'ns0':'example.com'}

        doc.ns0_a[0] = '000'
        doc.a[0] = '111'

        expected = {'ns0_a':['000'], 'a':['111']}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #26
0
    def xtest_ns_elems_default(self):
        doc = Elem()
        doc.ns_map += {'x':'example.com/1'}

        doc.a = 123
        doc.x_b = 456

        expected = {'a': 123, 'b': 456}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #27
0
    def xtest_ns_attrs_include_ns_true_nested(self):
        doc = Elem()
        doc.ns_map += {'x':'example.com/1'}

        doc.a = 123
        doc.a.q._x_b = 456

        expected = {'a': {'q': {'#x_b': 456}, 'text': 123}}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #28
0
    def xtest_ns_attrs_default_simple(self):
        doc = Elem()
        doc.ns_map += {'x':'example.com/1'}

        doc.a = 123
        doc.a._x_b = 456

        expected = {'a': {'#b': 456, 'text': 123}}
        out = doc.to_dict()
        self.assertDictEqual(expected, out)
Beispiel #29
0
    def xtest_ns_elems_include_ns_true(self):
        doc = Elem()
        doc.ns_map += {'x':'example.com/1'}

        doc.a = 123
        doc.x_b = 456

        expected = {'a': 123, 'x_b': 456}
        out = doc.to_dict(include_ns=True)
        self.assertDictEqual(expected, out)
Beispiel #30
0
    def test_append_to_list4(self):
        doc = Elem()
        doc.ns_map += {"ns0": "example.com"}

        doc.ns0_a.append(123)
        doc.ns0_a.append(456)

        expected = {"ns0_a": [123, 456]}
        out = doc.to_dict(include_ns=True)

        self.assertDictEqual(expected, out)