summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Arndt <arndtn@gmail.com>2020-04-17 22:46:46 +0200
committerGitHub <noreply@github.com>2020-04-17 22:46:46 +0200
commit972f76a4b82f8ed9194236e75415063612d9c635 (patch)
tree027118042d7a76773a58178f69815867802b90b0
parent91e94c85e59ad46f7d22d868274937f7a7e3ecde (diff)
parentf47f6e8f037cbe4ef77b508600155fb4c74878f9 (diff)
downloadrdflib-972f76a4b82f8ed9194236e75415063612d9c635.tar.gz
Merge pull request #1 from effigies/test/exponent_regex_tests
TEST: Stress test exponent regex
-rwxr-xr-xrdflib/plugins/parsers/notation3.py4
-rw-r--r--setup.py3
-rw-r--r--test/test_n3.py22
3 files changed, 24 insertions, 5 deletions
diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py
index 1c662cfa..c57f5bcf 100755
--- a/rdflib/plugins/parsers/notation3.py
+++ b/rdflib/plugins/parsers/notation3.py
@@ -349,9 +349,7 @@ ws = re.compile(r'[ \t]*') # Whitespace not including NL
signed_integer = re.compile(r'[-+]?[0-9]+') # integer
integer_syntax = re.compile(r'[-+]?[0-9]+')
decimal_syntax = re.compile(r'[-+]?[0-9]*\.[0-9]+')
-exponent_syntax = re.compile(r'[-+]?(?:[0-9]+\.[0-9]*(?:e|E)[-+]?[0-9]+|'+
- r'\.[0-9]+(?:e|E)[-+]?[0-9]+|'+
- r'[0-9]+(?:e|E)[-+]?[0-9]+)')
+exponent_syntax = re.compile(r'[-+]?(?:[0-9]+\.[0-9]*|\.[0-9]+|[0-9]+)(?:e|E)[-+]?[0-9]+')
digitstring = re.compile(r'[0-9]+') # Unsigned integer
interesting = re.compile(r"""[\\\r\n\"\']""")
langcode = re.compile(r'[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*')
diff --git a/setup.py b/setup.py
index d10513be..d611fe45 100644
--- a/setup.py
+++ b/setup.py
@@ -6,11 +6,12 @@ from setuptools import setup, find_packages
kwargs = {}
kwargs['install_requires'] = [ 'six', 'isodate', 'pyparsing']
-kwargs['tests_require'] = ['html5lib', 'networkx']
+kwargs['tests_require'] = ['html5lib', 'networkx', 'nose', 'doctest-ignore-unicode']
kwargs['test_suite'] = "nose.collector"
kwargs['extras_require'] = {
'html': ['html5lib'],
'sparql': ['requests'],
+ 'tests': kwargs['tests_require'],
'docs': ['sphinx < 3', 'sphinxcontrib-apidoc']
}
diff --git a/test/test_n3.py b/test/test_n3.py
index 250ef086..354bb073 100644
--- a/test/test_n3.py
+++ b/test/test_n3.py
@@ -1,7 +1,8 @@
from rdflib.graph import Graph, ConjunctiveGraph
import unittest
from rdflib.term import Literal, URIRef
-from rdflib.plugins.parsers.notation3 import BadSyntax
+from rdflib.plugins.parsers.notation3 import BadSyntax, exponent_syntax
+import itertools
from six import b
from six.moves.urllib.error import URLError
@@ -251,5 +252,24 @@ foo-bar:Ex foo-bar:name "Test" . """
g2), 'Document with declared empty prefix must match default #'
+class TestRegularExpressions(unittest.TestCase):
+ def testExponents(self):
+ signs = ("", "+", "-")
+ mantissas = ("1", "1.", ".1",
+ "12", "12.", "1.2", ".12",
+ "123", "123.", "12.3", "1.23", ".123")
+ es = "eE"
+ exps = ("1", "12", "+1", "-1", "+12", "-12")
+ for parts in itertools.product(signs, mantissas, es, exps):
+ expstring = "".join(parts)
+ self.assertRegex(expstring, exponent_syntax)
+
+ def testInvalidExponents(self):
+ # Add test cases as needed
+ invalid = (".e1",)
+ for expstring in invalid:
+ self.assertNotRegex(expstring, exponent_syntax)
+
+
if __name__ == '__main__':
unittest.main()