Skip to content

Commit

Permalink
Close release v2.1.2
Browse files Browse the repository at this point in the history
  - Update release info
  - Additional tests for XPathSchemaContext
  • Loading branch information
brunato committed Jan 22, 2021
1 parent 54504dd commit 1700377
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
CHANGELOG
*********

`v2.1.2`_ (2021-01-xx)
`v2.1.2`_ (2021-01-22)
======================
* Extend tests for XPath 1.0/2.0 with minor fixes
* Fix for +/- prefix operators
* Fix for regex patterns anchors and binary datatypes

`v2.1.1`_ (2021-01-06)
======================
Expand Down
4 changes: 1 addition & 3 deletions elementpath/xpath2/xpath2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,7 @@ def evaluate(self, context=None):
sequence_type = sequence_type[:-1]

if QName.pattern.match(sequence_type) is not None:
value = self.parser.get_atomic_value(sequence_type)
if value is not None:
return value
return self.parser.get_atomic_value(sequence_type)
return UntypedAtomic('')

raise self.missing_name('unknown variable %r' % str(varname))
Expand Down
2 changes: 1 addition & 1 deletion publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publiccodeYmlVersion: '0.2'
name: elementpath
url: 'https://github.com/sissaschool/elementpath'
landingURL: 'https://github.com/sissaschool/elementpath'
releaseDate: '2020-01-xx'
releaseDate: '2020-01-22'
softwareVersion: v2.1.2
developmentStatus: stable
platforms:
Expand Down
78 changes: 78 additions & 0 deletions tests/test_schema_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def setUpClass(cls):
<xs:element name="b3" type="xs:float"/>
</xs:schema>'''))

cls.schema2 = xmlschema.XMLSchema(dedent('''
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root"/>
</xs:schema>'''))

def test_name_token(self):
parser = XPath2Parser(default_namespace="http://xpath.test/ns")
context = XMLSchemaContext(self.schema1)
Expand Down Expand Up @@ -153,6 +158,79 @@ def test_wildcard_token(self):
'b2': elem_a.type.content[1].type,
'{http://xpath.test/ns}b3': elem_b3.type})

def test_dot_shortcut_token(self):
parser = XPath2Parser(default_namespace="http://xpath.test/ns")
context = XMLSchemaContext(self.schema1)

elem_a = self.schema1.elements['a']
elem_b3 = self.schema1.elements['b3']

token = parser.parse('.')
self.assertIsNone(token.xsd_types)
result = token.evaluate(context)
self.assertListEqual(result, [self.schema1])
self.assertEqual(token.xsd_types, {"{http://xpath.test/ns}a": elem_a.type,
"{http://xpath.test/ns}b3": elem_b3.type})

context = XMLSchemaContext(self.schema1, item=self.schema1)
token = parser.parse('.')
self.assertIsNone(token.xsd_types)
result = token.evaluate(context)
self.assertListEqual(result, [self.schema1])
self.assertEqual(token.xsd_types, {"{http://xpath.test/ns}a": elem_a.type,
"{http://xpath.test/ns}b3": elem_b3.type})

context = XMLSchemaContext(self.schema1, item=self.schema2)
token = parser.parse('.')
self.assertIsNone(token.xsd_types)
result = token.evaluate(context)
self.assertListEqual(result, [self.schema2])
self.assertIsNone(token.xsd_types)

def test_schema_variables(self):
variable_types = {'a': 'item()', 'b': 'xs:integer?', 'c': 'xs:string'}
parser = XPath2Parser(default_namespace="http://xpath.test/ns",
variable_types=variable_types)
context = XMLSchemaContext(self.schema1)

token = parser.parse('$a')
result = token.evaluate(context)
self.assertIsInstance(result, UntypedAtomic)
self.assertEqual(result.value, '')

token = parser.parse('$b')
result = token.evaluate(context)
self.assertIsInstance(result, int)
self.assertEqual(result, 1)

token = parser.parse('$c')
result = token.evaluate(context)
self.assertIsInstance(result, str)
self.assertEqual(result, ' alpha\t')

token = parser.parse('$z')
with self.assertRaises(NameError):
token.evaluate(context)

def test_not_applicable_functions(self):
parser = XPath2Parser(default_namespace="http://xpath.test/ns")
context = XMLSchemaContext(self.schema1)

token = parser.parse("fn:collection('filepath')")
self.assertIsNone(token.evaluate(context))

token = parser.parse("fn:doc-available('tns1')")
self.assertIsNone(token.evaluate(context))

token = parser.parse("fn:root(.)")
self.assertIsNone(token.evaluate(context))

token = parser.parse("fn:id('ID21256')")
self.assertListEqual(token.evaluate(context), [])

token = parser.parse("fn:idref('ID21256')")
self.assertListEqual(token.evaluate(context), [])


if __name__ == '__main__':
unittest.main()

0 comments on commit 1700377

Please sign in to comment.