Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xpath tests #12

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions test/xpath/test_union.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-

'''
Tests about comparing attributes with or / and connectors

It has to do with this ticket: https://github.com/zepheira/amara/issues/8

@lmorillas
'''

import amara

XML = '''<?xml version="1.0" encoding="utf-8"?>
<school>
<teacher lang="es" date="1998">
<name>Luis</name>
</teacher>
<student date="1990">
<name>María</name>
</student>
<student lang="es" date="1992">
<name>Jesús</name>
</student>
<student lang="en" date="2002">
<name>Peter</name>
</student>
<student lang="es" date="2001">
<name>Mary</name>
</student>
<student lang="en ni">
<name>Uche</name>
</student>
<student>
<name>Anonymous</name>
</student>

</school>
'''


doc = amara.parse(XML)

# Testing attributes

def test_or_attributes_exist():
assert len(doc.xml_select(u'//student[@lang or @date]')) == 5

def test_or_attributes_equal():
assert len(doc.xml_select(u'//student[@lang="en" or @lang="es"]')) == 3

def test_or_attributes_gt_integer():
# compares as integer
assert len(doc.xml_select(u'//student[@lang="es" or @date>2000]')) == 5

def test_and_attributes_exist():
assert len(doc.xml_select(u'//student[@lang and @date]')) == 3

def test_and_attributes_equal():
assert len(doc.xml_select(u'//student[@lang="en" and @date>2000]')) == 1

# tests with elements
def test_or_nodes():
assert len(doc.xml_select(u'//student | //teacher')) == 7



if __name__ == '__main__':
raise SystemExit('Use nosetests')
108 changes: 108 additions & 0 deletions test/xslt/test_strip_space.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python

'''
These new tests complete the test_basics.py tests

I want to test the xsl:strip-space command that is failing now with Amara

The expected results are the ones I'm getting with saxon.
'''

import sys
from nose import with_setup

from amara.xslt.processor import processor
from amara.lib import inputsource

xslt_proc = None
source = None
trans = None

def setup_blank_text():
global source
global trans
global xslt_proc

_source1 = '''<?xml version="1.0"?>
<test>
<item/>
<item/>
<item/>
</test>
'''

_trans1 = '''<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<test>
<xsl:apply-templates/>
</test>
</xsl:template>
<xsl:template match="item">
<no>
<xsl:value-of select="position()"/>
</no>
</xsl:template>
</xsl:stylesheet>
'''

xslt_proc = processor()

source = inputsource(_source1, None)
trans = inputsource(_trans1, None)


@with_setup(setup_blank_text)
def test_blank_text():
'''
testing blank text nodes, most by indentations and so.
'''
xslt_proc.append_transform(trans)
res = xslt_proc.run(source)
#print >> sys.stderr, res
assert (res == '<?xml version="1.0" encoding="UTF-8"?><test><no>1</no><no>2</no><no>3</no></test>')


def setup_blank_node():
global source
global trans
global xslt_proc

_source1 = '''<?xml version="1.0"?>
<document>
<text> </text>
</document>'''

_trans1 = '''<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:apply-templates select="//text"/>
</xsl:template>

<xsl:template match="text">
Chars: <xsl:value-of select="string-length(text())"/>
</xsl:template>

</xsl:stylesheet>'''

xslt_proc = processor()

source = inputsource(_source1, None)
trans = inputsource(_trans1, None)


@with_setup(setup_blank_node)
def test_blank_node():
'''
Testing elment nodes that only have spaces.
'''
xslt_proc.append_transform(trans)
res = xslt_proc.run(source)
#print >> sys.stderr, res
assert (res == '\nChars: 0')