示例#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
             }
         }})
示例#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'}})
示例#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'
             }
         })
示例#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)
示例#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)
示例#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))))
示例#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']
                      }})
示例#8
0
 def test_attrib(self):
     obj = {'a': {'@href': 'x'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#9
0
 def test_attrib(self):
     self.assertEqual(parse('<a href="xyz"/>'),
                      {'a': {'@href': 'xyz'}})
示例#10
0
 def test_semi_structured(self):
     self.assertEqual(parse('<a>abc<b/>def</a>'),
                      {'a': {'b': None, '#text': 'abcdef'}})
示例#11
0
 def test_attrib_and_text(self):
     self.assertEqual(parse('<a href="xyz">123</a>'),
                      {'a': {'@href': 'xyz', '#text': '123'}})
示例#12
0
 def test_attrib_and_text(self):
     self.assertEqual(parse('<a href="xyz">123</a>'),
                      {'a': {
                          '@href': 'xyz',
                          '#text': '123'
                      }})
示例#13
0
 def test_simple_text(self):
     obj = {'a': 'b'}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#14
0
 def test_simple(self):
     self.assertEqual(parse('<a>data</a>'), {'a': 'data'})
示例#15
0
 def test_root(self):
     obj = {'a': None}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#16
0
 def test_with_mismatched_tag(self):
     with self.assertRaises(ValueError):
         parse('<root attr="val">text</wrong>')
示例#17
0
 def test_with_broken_attribute(self):
     with self.assertRaises(ValueError):
         parse('<root attr>foo</root>')
示例#18
0
 def test_minimal(self):
     self.assertEqual(parse('<a/>'), {'a': None})
示例#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))))
示例#20
0
 def test_minimal(self):
     self.assertEqual(parse('<a/>'), {'a': None})
示例#21
0
 def test_attrib(self):
     self.assertEqual(parse('<a href="xyz"/>'), {'a': {'@href': 'xyz'}})
示例#22
0
 def test_simple(self):
     self.assertEqual(parse('<a>data</a>'), {'a': 'data'})
示例#23
0
 def test_semi_structured(self):
     self.assertEqual(parse('<a>abc<b/>def</a>'),
                      {'a': {
                          'b': None,
                          '#text': 'abcdef'
                      }})
示例#24
0
 def test_with_mismatched_tag(self):
     with self.assertRaises(ValueError):
         parse('<root attr="val">text</wrong>')
示例#25
0
 def test_attrib(self):
     obj = {'a': {'@href': 'x'}}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#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}}})
示例#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))))
示例#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))))
示例#29
0
 def test_with_broken_attribute(self):
     with self.assertRaises(ValueError):
         parse('<root attr>foo</root>')
示例#30
0
 def test_simple_text(self):
     obj = {'a': 'b'}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#31
0
 def test_root(self):
     obj = {'a': None}
     self.assertEqual(obj, parse(unparse(obj)))
     self.assertEqual(unparse(obj), unparse(parse(unparse(obj))))
示例#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']}})