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)
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)
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)
def xtest_direct3(self): doc = Elem() doc.a[0] expected = {'a':[None]} out = doc.to_dict() self.assertDictEqual(expected, out)
def xtest_indirect1(self): doc = Elem() doc.a.b[0] = '000' expected = {'a': {'b': ['000']}} out = doc.to_dict() self.assertDictEqual(expected, out)
def test_append_to_list1(self): doc = Elem() doc.a.append(123) expected = {"a": [123]} out = doc.to_dict() self.assertDictEqual(expected, out)
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)
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)
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)
def xtest_top_level_list_value1(self): doc = Elem() doc.a[0] = 'a0' expected = {'a':['a0']} out = doc.to_dict() self.assertDictEqual(expected, out)
def xtest_top_level_list_simple1(self): doc = Elem() doc.a[0] expected = {'a':[None]} out = doc.to_dict() self.assertDictEqual(expected, out)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
def xtest_ns_elems_attrs_default_nested(self): doc = Elem() doc.ns_map += {'x':'example.com/1'} doc.a = 123 doc.a.q.x_b = 456 doc.a.q._x_b = 789 expected = {'a': {'q': {'b': 456, '#b': 789}, 'text': 123}} out = doc.to_dict() self.assertDictEqual(expected, out)