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 3ce0880
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ python:
- "3.7"
- "3.8"
- "3.9"
- "pypy3"
- "pypy3.7"
before_install:
- sudo apt-get update && sudo apt-get --reinstall install -qq language-pack-en language-pack-de language-pack-it
install:
Expand Down
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
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 3ce0880

Please sign in to comment.