Пример #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']}})