Ejemplo n.º 1
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_attr_equality(self):
     xml = XML('<root><item/><item important="notso"/></root>')
     path = Path('item[@important="very"]')
     self.assertEqual('', path.select(xml).render())
     path = Path('item[@important!="very"]')
     self.assertEqual('<item/><item important="notso"/>',
                      path.select(xml).render())
Ejemplo n.º 2
0
 def test_predicate_attr_equality(self):
     xml = XML('<root><item/><item important="notso"/></root>')
     path = Path('item[@important="very"]')
     self.assertEqual('', path.select(xml).render())
     path = Path('item[@important!="very"]')
     self.assertEqual('<item/><item important="notso"/>',
                      path.select(xml).render())
Ejemplo n.º 3
0
 def test_predicate_number_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[number("3.0")=3]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[number("3.0")=3.0]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[number("0.1")=.1]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 4
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_number_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[number("3.0")=3]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[number("3.0")=3.0]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[number("0.1")=.1]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 5
0
    def test_1step_self(self):
        xml = XML('<root><elem/></root>')

        path = Path('.')
        self.assertEqual('<Path "self::node()">', repr(path))
        self.assertEqual('<root><elem/></root>', path.select(xml).render())

        path = Path('self::node()')
        self.assertEqual('<Path "self::node()">', repr(path))
        self.assertEqual('<root><elem/></root>', path.select(xml).render())
Ejemplo n.º 6
0
Archivo: path.py Proyecto: alon/polinax
    def test_1step_self(self):
        xml = XML('<root><elem/></root>')

        path = Path('.')
        self.assertEqual('<Path "self::node()">', repr(path))
        self.assertEqual('<root><elem/></root>', path.select(xml).render())

        path = Path('self::node()')
        self.assertEqual('<Path "self::node()">', repr(path))
        self.assertEqual('<root><elem/></root>', path.select(xml).render())
Ejemplo n.º 7
0
Archivo: path.py Proyecto: alon/polinax
    def test_3step_complex(self):
        xml = XML('<root><foo><bar/></foo></root>')
        path = Path('*/bar')
        self.assertEqual('<Path "child::*/child::bar">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
        path = Path('//bar')
        self.assertEqual('<Path "descendant-or-self::node()/child::bar">',
                         repr(path))
        self.assertEqual('<bar id="1"/><bar id="2"/>',
                         path.select(xml).render())
Ejemplo n.º 8
0
    def test_predicate_termination(self):
        """
        Verify that a patch matching the self axis with a predicate doesn't
        cause an infinite loop. See <http://genshi.edgewall.org/ticket/82>.
        """
        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
        path = Path('.[@flag="1"]/*')
        self.assertEqual('<li>a</li><li>b</li>', path.select(xml).render())

        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
        path = Path('.[@flag="0"]/*')
        self.assertEqual('', path.select(xml).render())
Ejemplo n.º 9
0
Archivo: path.py Proyecto: alon/polinax
    def test_predicate_termination(self):
        """
        Verify that a patch matching the self axis with a predicate doesn't
        cause an infinite loop. See <http://genshi.edgewall.org/ticket/82>.
        """
        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
        path = Path('.[@flag="1"]/*')
        self.assertEqual('<li>a</li><li>b</li>', path.select(xml).render())

        xml = XML('<ul flag="1"><li>a</li><li>b</li></ul>')
        path = Path('.[@flag="0"]/*')
        self.assertEqual('', path.select(xml).render())
Ejemplo n.º 10
0
    def test_3step_complex(self):
        xml = XML('<root><foo><bar/></foo></root>')
        path = Path('*/bar')
        self.assertEqual('<Path "child::*/child::bar">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
        path = Path('//bar')
        self.assertEqual('<Path "descendant-or-self::node()/child::bar">',
                         repr(path))
        self.assertEqual('<bar id="1"/><bar id="2"/>',
                         path.select(xml).render())
Ejemplo n.º 11
0
Archivo: path.py Proyecto: alon/polinax
    def test_1step_attribute(self):
        path = Path('@foo')
        self.assertEqual('<Path "attribute::foo">', repr(path))

        xml = XML('<root/>')
        self.assertEqual('', path.select(xml).render())

        xml = XML('<root foo="bar"/>')
        self.assertEqual('bar', path.select(xml).render())

        path = Path('./@foo')
        self.assertEqual('<Path "self::node()/attribute::foo">', repr(path))
        self.assertEqual('bar', path.select(xml).render())
Ejemplo n.º 12
0
    def test_node_type_processing_instruction(self):
        xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>')

        path = Path('processing-instruction()')
        self.assertEqual('<Path "child::processing-instruction()">',
                         repr(path))
        self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>',
                         path.select(xml).render())

        path = Path('processing-instruction("php")')
        self.assertEqual('<Path "child::processing-instruction(\"php\")">',
                         repr(path))
        self.assertEqual('<?php echo("x") ?>', path.select(xml).render())
Ejemplo n.º 13
0
    def test_1step_attribute(self):
        path = Path('@foo')
        self.assertEqual('<Path "attribute::foo">', repr(path))

        xml = XML('<root/>')
        self.assertEqual('', path.select(xml).render())

        xml = XML('<root foo="bar"/>')
        self.assertEqual('bar', path.select(xml).render())

        path = Path('./@foo')
        self.assertEqual('<Path "self::node()/attribute::foo">', repr(path))
        self.assertEqual('bar', path.select(xml).render())
Ejemplo n.º 14
0
Archivo: path.py Proyecto: alon/polinax
    def test_node_type_processing_instruction(self):
        xml = XML('<?python x = 2 * 3 ?><root><?php echo("x") ?></root>')

        path = Path('processing-instruction()')
        self.assertEqual('<Path "child::processing-instruction()">',
                         repr(path))
        self.assertEqual('<?python x = 2 * 3 ?><?php echo("x") ?>',
                         path.select(xml).render())

        path = Path('processing-instruction("php")')
        self.assertEqual('<Path "child::processing-instruction(\"php\")">',
                         repr(path))
        self.assertEqual('<?php echo("x") ?>', path.select(xml).render())
Ejemplo n.º 15
0
    def _test_eval(self,
                   path,
                   equiv=None,
                   input=None,
                   output='',
                   namespaces=None,
                   variables=None):
        path = Path(path)
        if equiv is not None:
            self.assertEqual(equiv, repr(path))

        if input is None:
            return

        rendered = path.select(input,
                               namespaces=namespaces,
                               variables=variables).render(encoding=None)
        msg = 'Bad output using whole path'
        msg += '\nExpected:\t%r' % output
        msg += '\nRendered:\t%r' % rendered
        self.assertEqual(output, rendered, msg)

        if len(path.paths) == 1:
            self._test_strategies(input,
                                  path.paths[0],
                                  output,
                                  namespaces=namespaces,
                                  variables=variables)
Ejemplo n.º 16
0
 def test_attrwildcard_with_namespace(self):
     xml = XML('<root xmlns:f="FOO"><foo f:bar="baz"/></root>')
     path = Path('foo[@f:*]')
     self.assertEqual('<foo xmlns:ns1="FOO" ns1:bar="baz"/>',
                      path.select(xml, namespaces={
                          'f': 'FOO'
                      }).render())
Ejemplo n.º 17
0
Archivo: path.py Proyecto: alon/polinax
 def test_wildcard_with_namespace(self):
     xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
     path = Path('f:*')
     self.assertEqual('<Path "child::f:*">', repr(path))
     namespaces = {'f': 'FOO'}
     self.assertEqual('<foo xmlns="FOO">bar</foo>',
                      path.select(xml, namespaces=namespaces).render())
Ejemplo n.º 18
0
 def test_wildcard_with_namespace(self):
     xml = XML('<root xmlns:f="FOO"><f:foo>bar</f:foo></root>')
     path = Path('f:*')
     self.assertEqual('<Path "child::f:*">', repr(path))
     namespaces = {'f': 'FOO'}
     self.assertEqual('<foo xmlns="FOO">bar</foo>',
                      path.select(xml, namespaces=namespaces).render())
Ejemplo n.º 19
0
 def test_attr_selection(self):
     xml = XML('<root><foo bar="abc"></foo></root>')
     path = Path('foo/@bar')
     result = path.select(xml)
     self.assertEqual(list(result), [
         Attrs([(QName('bar'), u'abc')])
     ])
Ejemplo n.º 20
0
 def test_attr_selection_with_namespace(self):
     xml = XML('<root xmlns:ns1="http://example.com">'
               '<foo ns1:bar="abc"></foo>'
               '</root>')
     path = Path('foo/@ns1:bar')
     result = path.select(xml, namespaces={'ns1': 'http://example.com'})
     self.assertEqual(list(result),
                      [Attrs([(QName('http://example.com}bar'), 'abc')])])
Ejemplo n.º 21
0
    def test_2step_complex(self):
        xml = XML('<root><foo><bar/></foo></root>')

        path = Path('foo/bar')
        self.assertEqual('<Path "child::foo/child::bar">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        path = Path('./bar')
        self.assertEqual('<Path "self::node()/child::bar">', repr(path))
        self.assertEqual('', path.select(xml).render())

        path = Path('foo/*')
        self.assertEqual('<Path "child::foo/child::*">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
        path = Path('./bar')
        self.assertEqual('<Path "self::node()/child::bar">', repr(path))
        self.assertEqual('<bar id="2"/>', path.select(xml).render())
Ejemplo n.º 22
0
Archivo: path.py Proyecto: alon/polinax
    def test_1step_wildcard(self):
        xml = XML('<root><elem/></root>')

        path = Path('*')
        self.assertEqual('<Path "child::*">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::*')
        self.assertEqual('<Path "child::*">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::node()')
        self.assertEqual('<Path "child::node()">', repr(path))
        self.assertEqual('<elem/>', Path('child::node()').select(xml).render())

        path = Path('//*')
        self.assertEqual('<Path "descendant-or-self::node()/child::*">',
                         repr(path))
        self.assertEqual('<root><elem/></root>', path.select(xml).render())
Ejemplo n.º 23
0
 def test_attr_selection_with_namespace(self):
     xml = XML(
         '<root xmlns:ns1="http://example.com">'
         '<foo ns1:bar="abc"></foo>'
         '</root>')
     path = Path('foo/@ns1:bar')
     result = path.select(xml, namespaces={'ns1': 'http://example.com'})
     self.assertEqual(list(result), [
         Attrs([(QName('http://example.com}bar'), u'abc')])
     ])
Ejemplo n.º 24
0
Archivo: path.py Proyecto: alon/polinax
    def test_1step(self):
        xml = XML('<root><elem/></root>')

        path = Path('elem')
        self.assertEqual('<Path "child::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::elem')
        self.assertEqual('<Path "child::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('//elem')
        self.assertEqual('<Path "descendant-or-self::node()/child::elem">',
                         repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('descendant::elem')
        self.assertEqual('<Path "descendant::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())
Ejemplo n.º 25
0
    def test_1step(self):
        xml = XML('<root><elem/></root>')

        path = Path('elem')
        self.assertEqual('<Path "child::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::elem')
        self.assertEqual('<Path "child::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('//elem')
        self.assertEqual('<Path "descendant-or-self::node()/child::elem">',
                         repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('descendant::elem')
        self.assertEqual('<Path "descendant::elem">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())
Ejemplo n.º 26
0
    def test_1step_wildcard(self):
        xml = XML('<root><elem/></root>')

        path = Path('*')
        self.assertEqual('<Path "child::*">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::*')
        self.assertEqual('<Path "child::*">', repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())

        path = Path('child::node()')
        self.assertEqual('<Path "child::node()">', repr(path))
        self.assertEqual('<elem/>', Path('child::node()').select(xml).render())

        path = Path('//*')
        self.assertEqual('<Path "descendant-or-self::node()/child::*">',
                         repr(path))
        self.assertEqual('<elem/>', path.select(xml).render())
Ejemplo n.º 27
0
Archivo: path.py Proyecto: alon/polinax
    def test_2step_complex(self):
        xml = XML('<root><foo><bar/></foo></root>')

        path = Path('foo/bar')
        self.assertEqual('<Path "child::foo/child::bar">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        path = Path('./bar')
        self.assertEqual('<Path "self::node()/child::bar">', repr(path))
        self.assertEqual('', path.select(xml).render())

        path = Path('foo/*')
        self.assertEqual('<Path "child::foo/child::*">', repr(path))
        self.assertEqual('<bar/>', path.select(xml).render())

        xml = XML('<root><foo><bar id="1"/></foo><bar id="2"/></root>')
        path = Path('./bar')
        self.assertEqual('<Path "self::node()/child::bar">', repr(path))
        self.assertEqual('<bar id="2"/>', path.select(xml).render())
Ejemplo n.º 28
0
Archivo: path.py Proyecto: alon/polinax
    def test_1step_text(self):
        xml = XML('<root>Hey</root>')

        path = Path('text()')
        self.assertEqual('<Path "child::text()">', repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('./text()')
        self.assertEqual('<Path "self::node()/child::text()">', repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('//text()')
        self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('.//text()')
        self.assertEqual('<Path "self::node()/descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Hey', path.select(xml).render())
Ejemplo n.º 29
0
    def test_1step_text(self):
        xml = XML('<root>Hey</root>')

        path = Path('text()')
        self.assertEqual('<Path "child::text()">', repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('./text()')
        self.assertEqual('<Path "self::node()/child::text()">', repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('//text()')
        self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Hey', path.select(xml).render())

        path = Path('.//text()')
        self.assertEqual('<Path "self::node()/descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Hey', path.select(xml).render())
Ejemplo n.º 30
0
    def test_2step_text(self):
        xml = XML('<root><item>Foo</item></root>')

        path = Path('item/text()')
        self.assertEqual('<Path "child::item/child::text()">', repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('*/text()')
        self.assertEqual('<Path "child::*/child::text()">', repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('//text()')
        self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('./text()')
        self.assertEqual('<Path "self::node()/child::text()">', repr(path))
        self.assertEqual('', path.select(xml).render())

        xml = XML('<root><item>Foo</item><item>Bar</item></root>')
        path = Path('item/text()')
        self.assertEqual('<Path "child::item/child::text()">', repr(path))
        self.assertEqual('FooBar', path.select(xml).render())

        xml = XML('<root><item>Foo</item><item>Bar</item></root>')
        self.assertEqual('FooBar', path.select(xml).render())
Ejemplo n.º 31
0
Archivo: path.py Proyecto: alon/polinax
    def test_2step_text(self):
        xml = XML('<root><item>Foo</item></root>')

        path = Path('item/text()')
        self.assertEqual('<Path "child::item/child::text()">', repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('*/text()')
        self.assertEqual('<Path "child::*/child::text()">', repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('//text()')
        self.assertEqual('<Path "descendant-or-self::node()/child::text()">',
                         repr(path))
        self.assertEqual('Foo', path.select(xml).render())

        path = Path('./text()')
        self.assertEqual('<Path "self::node()/child::text()">', repr(path))
        self.assertEqual('', path.select(xml).render())

        xml = XML('<root><item>Foo</item><item>Bar</item></root>')
        path = Path('item/text()')
        self.assertEqual('<Path "child::item/child::text()">', repr(path))
        self.assertEqual('FooBar', path.select(xml).render())

        xml = XML('<root><item>Foo</item><item>Bar</item></root>')
        self.assertEqual('FooBar', path.select(xml).render())
Ejemplo n.º 32
0
    def _test_eval(self, path, equiv=None, input=None, output='',
                         namespaces=None, variables=None):
        path = Path(path)
        if equiv is not None:
            self.assertEqual(equiv, repr(path))

        if input is None:
            return

        rendered = path.select(input, namespaces=namespaces,
                               variables=variables).render(encoding=None)
        msg = 'Bad output using whole path'
        msg += '\nExpected:\t%r' % output
        msg += '\nRendered:\t%r' % rendered
        self.assertEqual(output, rendered, msg)

        if len(path.paths) == 1:
            self._test_strategies(input, path.paths[0], output,
                                  namespaces=namespaces, variables=variables)
Ejemplo n.º 33
0
 def test_predicate_boolean_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[boolean("")]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean("yo")]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[boolean(0)]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean(42)]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[boolean(false())]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean(true())]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 34
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_boolean_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[boolean("")]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean("yo")]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[boolean(0)]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean(42)]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[boolean(false())]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[boolean(true())]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 35
0
 def test_predicate_string_length_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[string-length(name())=3]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 36
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_string_length_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[string-length(name())=3]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 37
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_position_and_attr(self):
     xml = XML('<root><foo/><foo id="a1"/><foo id="a2"/></root>')
     path = Path('*[1][@id]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[2][@id]')
     self.assertEqual('<foo id="a1"/>', path.select(xml).render())
Ejemplo n.º 38
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_translate_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[translate(name(), "fo", "ba")="baa"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 39
0
 def test_predicate_position(self):
     xml = XML('<root><foo id="a1"/><foo id="a2"/><foo id="a3"/></root>')
     path = Path('*[2]')
     self.assertEqual('<foo id="a2"/>', path.select(xml).render())
Ejemplo n.º 40
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_position(self):
     xml = XML('<root><foo id="a1"/><foo id="a2"/><foo id="a3"/></root>')
     path = Path('*[2]')
     self.assertEqual('<foo id="a2"/>', path.select(xml).render())
Ejemplo n.º 41
0
 def test_predicate_true_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[true()]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 42
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_substring_before_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[substring-before(name(), "oo")="f"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 43
0
 def test_predicate_attr_or(self):
     xml = XML('<root><item/><item important="very"/></root>')
     path = Path('item[@urgent or @important]')
     self.assertEqual('<item important="very"/>', path.select(xml).render())
     path = Path('item[@urgent or @notso]')
     self.assertEqual('', path.select(xml).render())
Ejemplo n.º 44
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_floor_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[floor("4.5")=4]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 45
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_normalize_space_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[normalize-space(" foo   bar  ")="foo bar"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 46
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_round_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[round("4.4")=4]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[round("4.6")=5]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 47
0
 def test_predicate_substring_before_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[substring-before(name(), "oo")="f"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 48
0
 def test_predicate_contains_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[contains(name(), "oo")]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 49
0
 def test_predicate_translate_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[translate(name(), "fo", "ba")="baa"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 50
0
 def test_predicate_floor_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[floor("4.5")=4]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 51
0
 def test_predicate_variable(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[name()=$bar]')
     variables = {'bar': 'foo'}
     self.assertEqual('<foo>bar</foo>',
                      path.select(xml, variables=variables).render())
Ejemplo n.º 52
0
 def test_predicate_normalize_space_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[normalize-space(" foo   bar  ")="foo bar"]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 53
0
 def test_predicate_position_and_attr(self):
     xml = XML('<root><foo/><foo id="a1"/><foo id="a2"/></root>')
     path = Path('*[1][@id]')
     self.assertEqual('', path.select(xml).render())
     path = Path('*[2][@id]')
     self.assertEqual('<foo id="a1"/>', path.select(xml).render())
Ejemplo n.º 54
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_matches_function(self):
     xml = XML('<root><foo>bar</foo><bar>foo</bar></root>')
     path = Path('*[matches(name(), "foo|bar")]')
     self.assertEqual('<foo>bar</foo><bar>foo</bar>', path.select(xml).render())
Ejemplo n.º 55
0
Archivo: path.py Proyecto: alon/polinax
 def test_attrwildcard_with_namespace(self):
     xml = XML('<root xmlns:f="FOO"><foo f:bar="baz"/></root>')
     path = Path('foo[@f:*]')
     self.assertEqual('<foo xmlns:ns1="FOO" ns1:bar="baz"/>',
                      path.select(xml, namespaces={'f': 'FOO'}).render())
Ejemplo n.º 56
0
 def test_predicate_round_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[round("4.4")=4]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[round("4.6")=5]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 57
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_true_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[true()]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
Ejemplo n.º 58
0
 def test_predicate_starts_with_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[starts-with(name(), "f")]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[starts-with(name(), "b")]')
     self.assertEqual('', path.select(xml).render())
Ejemplo n.º 59
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_variable(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[name()=$bar]')
     variables = {'bar': 'foo'}
     self.assertEqual('<foo>bar</foo>',
                      path.select(xml, variables=variables).render())
Ejemplo n.º 60
0
Archivo: path.py Proyecto: alon/polinax
 def test_predicate_starts_with_function(self):
     xml = XML('<root><foo>bar</foo></root>')
     path = Path('*[starts-with(name(), "f")]')
     self.assertEqual('<foo>bar</foo>', path.select(xml).render())
     path = Path('*[starts-with(name(), "b")]')
     self.assertEqual('', path.select(xml).render())