From 04258f5c43be0e5990fffc9197c4ae13b5db85c9 Mon Sep 17 00:00:00 2001 From: Davide Brunato Date: Mon, 9 Sep 2019 07:16:00 +0200 Subject: [PATCH] Fix '//' operator and text() function - '//' without a left token has to start from the document root, like an absolute path. --- CHANGELOG.rst | 6 ++++++ doc/conf.py | 2 +- elementpath/__init__.py | 2 +- elementpath/xpath1_parser.py | 5 ++--- setup.py | 2 +- tests/test_schema_proxy.py | 4 +++- tests/test_xpath1_parser.py | 7 ++++++- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3892347..fba3068 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ CHANGELOG ********* +`v1.2.2`_ (TBD) +=============== +* Fix descendant shortcut operator '//' +* Fix text() function + `v1.2.1`_ (2019-08-30) ====================== * Hashable XSD datatypes classes @@ -148,3 +153,4 @@ CHANGELOG .. _v1.1.9: https://github.com/brunato/elementpath/compare/v1.1.8...v1.1.9 .. _v1.2.0: https://github.com/brunato/elementpath/compare/v1.1.9...v1.2.0 .. _v1.2.1: https://github.com/brunato/elementpath/compare/v1.2.0...v1.2.1 +.. _v1.2.2: https://github.com/brunato/elementpath/compare/v1.2.1...v1.2.2 diff --git a/doc/conf.py b/doc/conf.py index 6be8790..086794a 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -31,7 +31,7 @@ author = 'Davide Brunato' # The short X.Y version version = '1.2' # The full version, including alpha/beta/rc tags -release = '1.2.1' +release = '1.2.2' # -- General configuration --------------------------------------------------- diff --git a/elementpath/__init__.py b/elementpath/__init__.py index 293df00..52fe050 100644 --- a/elementpath/__init__.py +++ b/elementpath/__init__.py @@ -8,7 +8,7 @@ # # @author Davide Brunato # -__version__ = '1.2.1' +__version__ = '1.2.2' __author__ = "Davide Brunato" __contact__ = "brunato@sissa.it" __copyright__ = "Copyright 2018-2019, SISSA" diff --git a/elementpath/xpath1_parser.py b/elementpath/xpath1_parser.py index b5360fb..c09952b 100644 --- a/elementpath/xpath1_parser.py +++ b/elementpath/xpath1_parser.py @@ -724,6 +724,7 @@ def select(self, context=None): if context is None: return elif len(self) == 1: + context.item = None for _ in context.iter_descendants(axis='descendant-or-self'): for result in self[0].select(context): yield result @@ -972,9 +973,7 @@ def evaluate(self, context=None): def select(self, context=None): if context is not None: for item in context.iter_children_or_self(): - if item is None: - yield context.root - elif is_text_node(item): + if is_text_node(item): yield item diff --git a/setup.py b/setup.py index 6f4fb9a..c7cd379 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ with open("README.rst") as readme: setup( name='elementpath', - version='1.2.1', + version='1.2.2', packages=['elementpath'], author='Davide Brunato', author_email='brunato@sissa.it', diff --git a/tests/test_schema_proxy.py b/tests/test_schema_proxy.py index b2532eb..1f80230 100644 --- a/tests/test_schema_proxy.py +++ b/tests/test_schema_proxy.py @@ -43,7 +43,9 @@ except ImportError: @unittest.skipIf(xmlschema is None, "xmlschema library required.") class XPath2ParserXMLSchemaTest(test_xpath2_parser.XPath2ParserTest): - schema = xmlschema.XMLSchema(''' + @classmethod + def setUpClass(cls): + cls.schema = xmlschema.XMLSchema(''' diff --git a/tests/test_xpath1_parser.py b/tests/test_xpath1_parser.py index efed458..f51cbe2 100644 --- a/tests/test_xpath1_parser.py +++ b/tests/test_xpath1_parser.py @@ -464,7 +464,12 @@ class XPath1ParserTest(unittest.TestCase): self.check_select("text()", [], context) # Selects the children self.check_selector("node()", self.etree.XML('Dickens'), ['Dickens']) self.check_selector("text()", self.etree.XML('Dickens'), ['Dickens']) - self.check_selector("//self::text()", self.etree.XML('Dickens'), ['Dickens']) + + root = self.etree.XML('Dickens') + if self.etree is not lxml_etree: + # Skip lxml test because lxml's XPath doesn't include document root + self.check_selector("//self::node()", root, [root, root, 'Dickens']) + self.check_selector("//self::text()", root, ['Dickens']) def test_node_set_id_function(self): # XPath 1.0 id() function: https://www.w3.org/TR/1999/REC-xpath-19991116/#function-id