Skip to content

Commit

Permalink
Update to release v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Mar 1, 2021
1 parent fccf27b commit 7dc408d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
CHANGELOG
*********

`v2.2.0`_ (2021-03-01)
======================
* Optimize TDOP parser's tokenizer
* Resolve ambiguities with operators and statements that are also names
* Merge with XPath 3.0/3.1 develop (to be completed)

`v2.1.4`_ (2021-02-09)
======================
* Add tests and apply small fixes to TDOP parser
Expand Down Expand Up @@ -292,3 +298,4 @@ CHANGELOG
.. _v2.1.2: https://github.com/sissaschool/elementpath/compare/v2.1.1...v2.1.2
.. _v2.1.3: https://github.com/sissaschool/elementpath/compare/v2.1.2...v2.1.3
.. _v2.1.4: https://github.com/sissaschool/elementpath/compare/v2.1.3...v2.1.4
.. _v2.2.0: https://github.com/sissaschool/elementpath/compare/v2.1.4...v2.2.0
4 changes: 2 additions & 2 deletions publiccode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ publiccodeYmlVersion: '0.2'
name: elementpath
url: 'https://github.com/sissaschool/elementpath'
landingURL: 'https://github.com/sissaschool/elementpath'
releaseDate: '2021-02-09'
softwareVersion: v2.1.4
releaseDate: '2021-03-01'
softwareVersion: v2.2.0
developmentStatus: stable
platforms:
- linux
Expand Down
18 changes: 18 additions & 0 deletions tests/test_tdop_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def test_symbol_to_classname_function(self):

def test_create_tokenizer_method(self):
FakeToken = namedtuple('Token', 'symbol pattern label')

tokens = {
FakeToken(symbol='(name)', pattern=None, label='literal'),
FakeToken('call', pattern=r'\bcall\b(?=\s+\()', label='function'),
}
pattern = Parser.create_tokenizer({t.symbol: t for t in tokens})
self.assertEqual(pattern.pattern,
'(\'[^\']*\'|"[^"]*"|(?:\\d+|\\.\\d+)(?:\\.\\d*)?(?:[Ee][+-]?\\d+)?)|'
'(\\bcall\\b(?=\\s+\\())|([A-Za-z0-9_]+)|(\\S)|\\s+')

tokens = {
FakeToken(symbol='(name)', pattern=None, label='literal'),
FakeToken('call', pattern=r'\bcall\b(?=\s+\()', label='function'),
Expand Down Expand Up @@ -162,6 +172,14 @@ def test_unknown_symbol(self):
self.parser.parse('UNKNOWN')
self.assertEqual(str(ec.exception), "unexpected name 'UNKNOWN'")

parser = self.parser.__class__()
parser.build()
parser.symbol_table.pop('+')

with self.assertRaises(ParseError) as ec:
parser.parse('+')
self.assertEqual(str(ec.exception), "unknown symbol '+'")

def test_invalid_source(self):
with self.assertRaises(ParseError) as ec:
self.parser.parse(10)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_xpath2_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def test_if_expressions(self):
self.check_selector("if (true()) then /A/B1 else /A/B2", root, root[:1])
self.check_selector("if (false()) then /A/B1 else /A/B2", root, root[1:2])

token = self.parser.parse("if")
self.assertEqual(token.symbol, '(name)')
self.assertEqual(token.value, 'if')

# Cases from XPath 2.0 examples
root = self.etree.XML('<part discounted="false"><wholesale/><retail/></part>')
self.check_selector(
Expand Down Expand Up @@ -323,6 +327,10 @@ def test_quantifier_expressions(self):
self.check_value('some $x in (1, 2, "cat") satisfies $x * 2 = 4', True, context)
self.check_value('every $x in (1, 2, "cat") satisfies $x * 2 = 4', False, context)

token = self.parser.parse("some")
self.assertEqual(token.symbol, '(name)')
self.assertEqual(token.value, 'some')

# From W3C XQuery/XPath tests
context = XPathContext(root=self.etree.XML('<dummy/>'),
variables={'result': [43, 44, 45]})
Expand Down
26 changes: 14 additions & 12 deletions tests/test_xpath3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import math
import pathlib
import platform
import xml.etree.ElementTree as ElementTree

try:
Expand Down Expand Up @@ -596,18 +597,19 @@ def test_unparsed_text_function(self):

self.assertIsNone(self.parser.parse('fn:unparsed-text(())').evaluate())

filepath = pathlib.Path(__file__).absolute().parent.joinpath('resources/sample.xml')
path = 'fn:unparsed-text("file://{}")'.format(str(filepath))
result = self.parser.parse(path).evaluate()
result = [x.strip() for x in result.strip().split('\n')]
self.assertListEqual(
result, ['<?xml version="1.0" encoding="UTF-8"?>', '<root>abc àèéìù</root>']
)

path = 'fn:unparsed-text("file://{}", "unknown")'.format(str(filepath))
with self.assertRaises(ValueError) as ctx:
self.parser.parse(path).evaluate()
self.assertIn('FOUT1190', str(ctx.exception))
if platform.system() != 'Windows':
filepath = pathlib.Path(__file__).absolute().parent.joinpath('resources/sample.xml')
path = 'fn:unparsed-text("file://{}")'.format(str(filepath))
result = self.parser.parse(path).evaluate()
result = [x.strip() for x in result.strip().split('\n')]
self.assertListEqual(
result, ['<?xml version="1.0" encoding="UTF-8"?>', '<root>abc àèéìù</root>']
)

path = 'fn:unparsed-text("file://{}", "unknown")'.format(str(filepath))
with self.assertRaises(ValueError) as ctx:
self.parser.parse(path).evaluate()
self.assertIn('FOUT1190', str(ctx.exception))

def test_environment_variable_function(self):
with self.assertRaises(MissingContextError):
Expand Down

0 comments on commit 7dc408d

Please sign in to comment.