configurationengine/source/cone/public/tests/unittest_xml_parsing.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    16 #
    16 #
    17 
    17 
    18 import sys, os
    18 import sys, os
    19 import unittest
    19 import unittest
    20 import StringIO
    20 import StringIO
    21 import __init__
       
    22 
    21 
    23 from cone.public import utils, exceptions
    22 from cone.public import utils, exceptions
    24 
    23 
    25 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    24 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    26 
    25 
    60         if self.LINE_NUMBERS:
    59         if self.LINE_NUMBERS:
    61             self.assertEquals(actual, expected)
    60             self.assertEquals(actual, expected)
    62         else:
    61         else:
    63             self.assertEquals(actual, None)
    62             self.assertEquals(actual, None)
    64     
    63     
       
    64     def assert_elem_tag(self, actual, expected):
       
    65         if self.LINE_NUMBERS:
       
    66             self.assertEquals(actual.tag, expected)
       
    67         else:
       
    68             self.assertEquals(actual, None)
       
    69     
    65     def test_correct_parser_set(self):
    70     def test_correct_parser_set(self):
    66         self.assertEquals(utils.etree.get_backend_id(), self.BACKEND_ID)
    71         self.assertEquals(utils.etree.get_backend_id(), self.BACKEND_ID)
    67     
    72     
    68     def test_fromstring_successful(self):
    73     def test_fromstring_successful(self):
    69         root = utils.etree.fromstring(self.DATA)
    74         root = utils.etree.fromstring(self.DATA)
    77         
    82         
    78         self.assert_lineno_equals(utils.etree.get_lineno(root), 2)
    83         self.assert_lineno_equals(utils.etree.get_lineno(root), 2)
    79         self.assert_lineno_equals(utils.etree.get_lineno(children[0]), 4)
    84         self.assert_lineno_equals(utils.etree.get_lineno(children[0]), 4)
    80         self.assert_lineno_equals(utils.etree.get_lineno(children[1]), 5)
    85         self.assert_lineno_equals(utils.etree.get_lineno(children[1]), 5)
    81         self.assert_lineno_equals(utils.etree.get_lineno(children[2]), 6)
    86         self.assert_lineno_equals(utils.etree.get_lineno(children[2]), 6)
    82     
    87         self.assert_elem_tag(utils.etree.get_elem_from_lineno(root, 5), '{http://www.test.com/xml/1}elem2')
       
    88 
    83     def test_tostring_ascii(self):
    89     def test_tostring_ascii(self):
    84         root = utils.etree.fromstring(self.DATA)
    90         root = utils.etree.fromstring(self.DATA)
    85         output = utils.etree.tostring(root)
    91         output = utils.etree.tostring(root)
    86     
    92     
    87     def test_tostring_utf_8(self):
    93     def test_tostring_utf_8(self):
   100             </root>"""
   106             </root>"""
   101         try:
   107         try:
   102             etree = utils.etree.fromstring(data)
   108             etree = utils.etree.fromstring(data)
   103             self.fail("XmlParseError not raised!")
   109             self.fail("XmlParseError not raised!")
   104         except exceptions.XmlParseError, e:
   110         except exceptions.XmlParseError, e:
   105             self.assertEquals(e.lineno, 4)
   111             self.assertEquals(e.problem_lineno, 4)
   106 
   112 
   107 # ============================================================================
   113 # ============================================================================
   108 # Actual test cases
   114 # Actual test cases
   109 # ============================================================================
   115 # ============================================================================
   110 
   116