Skip to content

Commit

Permalink
Update to release v2.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Dec 2, 2020
1 parent ab454fb commit 3366e97
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG

`v2.0.5`_ (2020-12-02)
======================
* Increase the speed of path step selection on large trees
* More tests and small fixes to XSD builtin datatypes

`v2.0.4`_ (2020-10-30)
Expand Down
9 changes: 2 additions & 7 deletions elementpath/xpath2/xpath2_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
def evaluate(self, context=None):
if context is None:
raise self.missing_context()
elif context.item is None:
return context.root
else:
return context.item
return context.root if context.item is None else context.item


###
Expand Down Expand Up @@ -124,9 +121,7 @@ def select(self, context=None):
# For lxml returns Element's prefixes
if 'xml' not in elem.nsmap:
yield 'xml'
for prefix in elem.nsmap:
if prefix:
yield prefix
yield from filter(lambda x: x, elem.nsmap)
else:
# For ElementTree returns module registered prefixes
prefixes = {x for x in self.parser.namespaces if x}
Expand Down
18 changes: 15 additions & 3 deletions tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import math
import operator
import pickle
import platform
import random
from decimal import Decimal
from calendar import isleap
Expand Down Expand Up @@ -1241,8 +1242,14 @@ def test_initialization(self):
self.assertEqual(Base64Binary(Base64Binary(b'YWxwaGE=')), b'YWxwaGE=')
self.assertEqual(HexBinary(HexBinary(b'F859')), b'F859')

self.assertEqual(Base64Binary(HexBinary(b'F859')).decode(), HexBinary(b'F859').decode())
self.assertEqual(HexBinary(Base64Binary(b'YWxwaGE=')).decode(), b'alpha')
try:
self.assertEqual(Base64Binary(HexBinary(b'F859')).decode(),
HexBinary(b'F859').decode())
self.assertEqual(HexBinary(Base64Binary(b'YWxwaGE=')).decode(), b'alpha')
except TypeError:
# Issue #3001 of pypy3.6 with codecs.decode(), fixed with PyPy 7.2.0.
if platform.python_implementation() != 'PyPy':
raise

def test_string_representation(self):
self.assertEqual(repr(Base64Binary(b'YWxwaGE=')), "Base64Binary(b'YWxwaGE=')")
Expand Down Expand Up @@ -1292,7 +1299,12 @@ def test_encoder(self):
self.assertEqual(Base64Binary.encoder(b'alpha'), b'YWxwaGE=')

def test_decoder(self):
self.assertEqual(Base64Binary(b'YWxwaGE=').decode(), b'alpha')
try:
self.assertEqual(Base64Binary(b'YWxwaGE=').decode(), b'alpha')
except TypeError:
# Issue #3001 of pypy3.6 with codecs.decode(), fixed with PyPy 7.2.0.
if platform.python_implementation() != 'PyPy':
raise


class QNameTypesTest(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions tests/test_xpath1_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ def test_namespace_axis(self):
+ [('tst', 'http://xpath.test/ns')]
self.check_selector('/A/namespace::*', root, expected=set(namespaces),
namespaces=namespaces[-1:])
self.check_value('namespace::*', MissingContextError)

def test_parent_shortcut_and_axis(self):
root = self.etree.XML(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_xpath2_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,19 @@ def test_in_scope_prefixes_function(self):
self.assertNotIn('p1', prefixes)
self.assertIn('p2', prefixes)

# Provides namespaces through the dynamic context
selector = Selector("fn:in-scope-prefixes(.)", parser=type(self.parser))
prefixes = selector.select(root, namespaces=namespaces)

self.assertIn('p0', prefixes)
self.assertNotIn('p1', prefixes)
self.assertIn('p2', prefixes)

with self.assertRaises(TypeError):
select(root, "fn:in-scope-prefixes('')", namespaces, parser=type(self.parser))



if xmlschema is not None:
schema = xmlschema.XMLSchema("""
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
Expand Down
12 changes: 12 additions & 0 deletions tests/test_xpath_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ def test_get_parent(self):
id(context._parent_map), parent_map_id # LRU cache prevents parent map rebuild
)

document = ElementTree.ElementTree(root)
context = XPathContext(root=document)

self.assertEqual(context.get_parent(root[1]), root)
self.assertEqual(context.get_parent(root[2]), root)
self.assertEqual(context.get_parent(root[2][1]), root[2])

def test_get_path(self):
root = ElementTree.XML('<A><B1><C1/></B1><B2/><B3><C1/><C2 max="10"/></B3></A>')

Expand All @@ -119,6 +126,11 @@ def test_get_path(self):
context._elem = root[2][1]
self.assertEqual(context.get_path(AttributeNode('max', '10')), '/A/B3/C2/@max')

document = ElementTree.ElementTree(root)
context = XPathContext(root=document)

self.assertEqual(context.get_path(root[2][0]), '/A/B3/C1')

root = ElementTree.XML('<A><B1>10</B1><B2 min="1"/><B3/></A>')
context = XPathContext(root)
with patch.object(DummyXsdType(), 'is_simple', return_value=True) as xsd_type:
Expand Down

0 comments on commit 3366e97

Please sign in to comment.