Ejemplo n.º 1
0
 def test_nested_semi_structured(self):
     self.assertEqual(
         parse('<a>abc<b>123<c/>456</b>def</a>'),
         {'a': {
             '#text': 'abcdef',
             'b': {
                 '#text': '123456',
                 'c': None
             }
         }})
Ejemplo n.º 2
0
 def test_skip_whitespace(self):
     xml = """
     <root>
       <emptya>           </emptya>
       <emptyb attr="attrvalue">
       </emptyb>
       <value>hello</value>
     </root>
     """
     self.assertEqual(
         parse(xml),
         {'root': {'emptya': None,
                   'emptyb': {'@attr': 'attrvalue'},
                   'value': 'hello'}})
Ejemplo n.º 3
0
 def test_skip_whitespace(self):
     xml = """
     <root>
       <emptya>           </emptya>
       <emptyb attr="attrvalue">
       </emptyb>
       <value>hello</value>
     </root>
     """
     self.assertEqual(
         parse(xml), {
             'root': {
                 'emptya': None,
                 'emptyb': {
                     '@attr': 'attrvalue'
                 },
                 'value': 'hello'
             }
         })
Ejemplo n.º 4
0
 def test_namespace_ignore(self):
     xml = """
     <root xmlns="http://defaultns.com/"
           xmlns:a="http://a.com/"
           xmlns:b="http://b.com/">
       <x>1</x>
       <a:y>2</a:y>
       <b:z>3</b:z>
     </root>
     """
     d = {
         'root': {
             '@xmlns': 'http://defaultns.com/',
             '@xmlns:a': 'http://a.com/',
             '@xmlns:b': 'http://b.com/',
             'x': '1',
             'a:y': '2',
             'b:z': '3',
         },
     }
     self.assertEqual(parse(xml), d)
Ejemplo n.º 5
0
 def test_namespace_ignore(self):
     xml = """
     <root xmlns="http://defaultns.com/"
           xmlns:a="http://a.com/"
           xmlns:b="http://b.com/">
       <x>1</x>
       <a:y>2</a:y>
       <b:z>3</b:z>
     </root>
     """
     d = {
         'root': {
             '@xmlns': 'http://defaultns.com/',
             '@xmlns:a': 'http://a.com/',
             '@xmlns:b': 'http://b.com/',
             'x': '1',
             'a:y': '2',
             'b:z': '3',
         },
     }
     self.assertEqual(parse(xml), d)
Ejemplo n.º 6
0
 def test_attrib_and_text(self):
     obj = {'a': {'@href': 'x', '#text': 'y'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 7
0
 def test_list(self):
     self.assertEqual(parse('<a><b>1</b><b>2</b><b>3</b></a>'),
                      {'a': {
                          'b': ['1', '2', '3']
                      }})
Ejemplo n.º 8
0
 def test_attrib(self):
     obj = {'a': {'@href': 'x'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 9
0
 def test_attrib(self):
     self.assertEqual(parse('<a href="xyz"/>'),
                      {'a': {'@href': 'xyz'}})
Ejemplo n.º 10
0
 def test_semi_structured(self):
     self.assertEqual(parse('<a>abc<b/>def</a>'),
                      {'a': {'b': None, '#text': 'abcdef'}})
Ejemplo n.º 11
0
 def test_attrib_and_text(self):
     self.assertEqual(parse('<a href="xyz">123</a>'),
                      {'a': {'@href': 'xyz', '#text': '123'}})
Ejemplo n.º 12
0
 def test_attrib_and_text(self):
     self.assertEqual(parse('<a href="xyz">123</a>'),
                      {'a': {
                          '@href': 'xyz',
                          '#text': '123'
                      }})
Ejemplo n.º 13
0
 def test_simple_text(self):
     obj = {'a': 'b'}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 14
0
 def test_simple(self):
     self.assertEqual(parse('<a>data</a>'), {'a': 'data'})
Ejemplo n.º 15
0
 def test_root(self):
     obj = {'a': None}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 16
0
 def test_with_mismatched_tag(self):
     with self.assertRaises(ValueError):
         parse('<root attr="val">text</wrong>')
Ejemplo n.º 17
0
 def test_with_broken_attribute(self):
     with self.assertRaises(ValueError):
         parse('<root attr>foo</root>')
Ejemplo n.º 18
0
 def test_minimal(self):
     self.assertEqual(parse('<a/>'), {'a': None})
Ejemplo n.º 19
0
 def test_list(self):
     obj = {'a': {'b': ['1', '2', '3']}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 20
0
 def test_minimal(self):
     self.assertEqual(parse('<a/>'), {'a': None})
Ejemplo n.º 21
0
 def test_attrib(self):
     self.assertEqual(parse('<a href="xyz"/>'), {'a': {'@href': 'xyz'}})
Ejemplo n.º 22
0
 def test_simple(self):
     self.assertEqual(parse('<a>data</a>'), {'a': 'data'})
Ejemplo n.º 23
0
 def test_semi_structured(self):
     self.assertEqual(parse('<a>abc<b/>def</a>'),
                      {'a': {
                          'b': None,
                          '#text': 'abcdef'
                      }})
Ejemplo n.º 24
0
 def test_with_mismatched_tag(self):
     with self.assertRaises(ValueError):
         parse('<root attr="val">text</wrong>')
Ejemplo n.º 25
0
 def test_attrib(self):
     obj = {'a': {'@href': 'x'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 26
0
 def test_nested_semi_structured(self):
     self.assertEqual(parse('<a>abc<b>123<c/>456</b>def</a>'),
                      {'a': {'#text': 'abcdef', 'b': {
                          '#text': '123456', 'c': None}}})
Ejemplo n.º 27
0
 def test_attrib_and_text(self):
     obj = {'a': {'@href': 'x', '#text': 'y'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 28
0
 def test_list(self):
     obj = {'a': {'b': ['1', '2', '3']}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 29
0
 def test_with_broken_attribute(self):
     with self.assertRaises(ValueError):
         parse('<root attr>foo</root>')
Ejemplo n.º 30
0
 def test_simple_text(self):
     obj = {'a': 'b'}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 31
0
 def test_root(self):
     obj = {'a': None}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
Ejemplo n.º 32
0
 def test_list(self):
     self.assertEqual(parse('<a><b>1</b><b>2</b><b>3</b></a>'),
                      {'a': {'b': ['1', '2', '3']}})