Exemple #1
0
def test_avt_errors():
    for arg, in (
        ('{}', ),  # no expression is error
        ('{-{{"literal"}', ),  # '-{"literal"' is invalid Expr
        ('{"literal"}}-}', ),  # '{"literal"} is expr; '}-}' is error
        ('{{node()}', ),  # '{{node()' is literal, trailing '}' is error
        ('{node()}}', ),  # '{node()}' is expr; trailing '}' is error
        ('(id(@ref)/title}', ),  # missing leading '{'
        ('{(id(@ref)/title', ),  # missing trailing '{'
    ):
        try:
            avt_expression(arg)
            raise AssertionError("should not have allowed %r" % (arg, ))
        except XsltError:
            pass
Exemple #2
0
def test_avt_errors():
    for arg, in (
        ('{}',),                # no expression is error
        ('{-{{"literal"}',),    # '-{"literal"' is invalid Expr
        ('{"literal"}}-}',),    # '{"literal"} is expr; '}-}' is error
        ('{{node()}',),         # '{{node()' is literal, trailing '}' is error
        ('{node()}}',),         # '{node()}' is expr; trailing '}' is error
        ('(id(@ref)/title}',),  # missing leading '{'
        ('{(id(@ref)/title',),  # missing trailing '{'
        ):
        try:
            avt_expression(arg)
            raise AssertionError("should not have allowed %r" % (arg,))
        except XsltError:
            pass
Exemple #3
0
    def xml_avt(self, expr, prefixes=None):
        prefixes = prefixes or self.xml_namespaces.copy()
        from amara.xslt.expressions import avt
        from amara.xpath import context

        v = avt.avt_expression(expr)
        return unicode(v.evaluate(context(self, namespaces=prefixes)))
Exemple #4
0
def test_avt():
    for arg, expected in (
        ('', ''),
        ('Senatus{{populisque}}romae', 'Senatus{populisque}romae'),
        ('Senatus{{{"populisque}}"}romae', 'Senatus{populisque}}romae'),
        ('{"{literal}"}', '{literal}'),
        ('{"{literal"}', '{literal'),
        ('{"literal}"}', 'literal}'),
        ('{"{{literal}}"}', '{{literal}}'),
        ('{"{{literal"}', '{{literal'),
        ('{"literal}}"}', 'literal}}'),
        ('{{{"literal"}', '{literal'),
        ('{{-{"literal"}', '{-literal'),
        ('{"literal"}}}', 'literal}'),
        ('{"literal"}-}}', 'literal-}'),
        ('{"100"}% {100}% {90+10}% 100% {"%"}1{0}0 %100', '100% 100% 100% 100% %100 %100'),
        ):
        result = avt_expression(arg).evaluate_as_string(DEFAULT_CONTEXT)
        assert isinstance(result, datatypes.string)
        assert result == expected, (result, expected)
Exemple #5
0
def test_avt():
    for arg, expected in (
        ('', ''),
        ('Senatus{{populisque}}romae', 'Senatus{populisque}romae'),
        ('Senatus{{{"populisque}}"}romae', 'Senatus{populisque}}romae'),
        ('{"{literal}"}', '{literal}'),
        ('{"{literal"}', '{literal'),
        ('{"literal}"}', 'literal}'),
        ('{"{{literal}}"}', '{{literal}}'),
        ('{"{{literal"}', '{{literal'),
        ('{"literal}}"}', 'literal}}'),
        ('{{{"literal"}', '{literal'),
        ('{{-{"literal"}', '{-literal'),
        ('{"literal"}}}', 'literal}'),
        ('{"literal"}-}}', 'literal-}'),
        ('{"100"}% {100}% {90+10}% 100% {"%"}1{0}0 %100',
         '100% 100% 100% 100% %100 %100'),
    ):
        result = avt_expression(arg).evaluate_as_string(DEFAULT_CONTEXT)
        assert isinstance(result, datatypes.string)
        assert result == expected, (result, expected)
Exemple #6
0
 def xml_avt(self, expr, prefixes=None):
     prefixes = prefixes or self.xml_namespaces.copy()
     from amara.xslt.expressions import avt
     from amara.xpath import context
     v = avt.avt_expression(expr)
     return unicode(v.evaluate(context(self, namespaces=prefixes)))