Пример #1
0
    def test_identity(self):
        """
        Tests wether the input and the output match.
        """
        data = ('<html>\n'
                '<head></head>\n'
                '<body>\n'
                ' this is a <span style="color: red">test</span>\n'
                '</body>\n'
                '</html>')
        h1 = XMLFile(string=data)
        h2 = XMLFile(string=data)

        self.assertEqual(h1, h2)
Пример #2
0
 def test_if_not(self):
     handler = XMLFile(
         string='<img xmlns:stl="http://www.hforge.org/xml-namespaces/stl"'
         '  stl:if="not img" />')
     namespace = {'img': True}
     stream = stl(handler, namespace)
     # Assert
     events = list(stream)
     self.assertEqual(events, [])
Пример #3
0
 def test_repeat(self):
     handler = XMLFile(
         string='<option xmlns:stl="http://www.hforge.org/xml-namespaces/stl"'
         '  stl:repeat="option options" />')
     namespace = {'options': []}
     stream = stl(handler, namespace)
     # Assert
     events = list(stream)
     self.assertEqual(events, [])
Пример #4
0
 def test_attribute_accent(self):
     handler = XMLFile(string=
         '<input xmlns="http://www.w3.org/1999/xhtml" value="${name}" />')
     namespace = {'name': u'étoile'}
     stream = stl(handler, namespace)
     # Assert
     events = list(stream)
     value = events[0][1][2][(None, 'value')]
     self.assertEqual(value, 'étoile')
Пример #5
0
 def test_attribute(self):
     handler = XMLFile(string=
         '<img xmlns="http://www.w3.org/1999/xhtml" alt="${alt}" />')
     namespace = {'alt': 'My title'}
     stream = stl(handler, namespace)
     # Assert
     events = list(stream)
     value = events[0][1][2][(None, 'alt')]
     self.assertEqual(value, 'My title')
Пример #6
0
 def test_attribute(self):
     handler = XMLFile(
         string=
         '<img xmlns="http://www.w3.org/1999/xhtml" border="${border}" />')
     namespace = {'border': 5}
     stream = stl(handler, namespace)
     # Assert
     events = list(stream)
     value = events[0][1][2][(None, 'border')]
     self.assertEqual(value, '5')
Пример #7
0
    def test_surrounding(self):
        text = '<em>Hello World</em>'
        parser = XMLFile(string=text)

        messages = [unit[0] for unit in parser.get_units()]
        self.assertEqual(messages, [((srx_TEXT, u'Hello World'),)])