-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix n3 parser exponent syntax of floats with leading dot. #1012
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2d0c805
Add test for exponent floats with leading dot
white-gecko 8054daa
Fix exponent syntax with leading dot.
white-gecko 91e94c8
Update rdflib/plugins/parsers/notation3.py
white-gecko 545c9da
TEST: Stress test exponent regex
effigies 663f522
RF: Simplify exponent regex by separating mantissa from exponent
effigies f47f6e8
MNT: Update test requirements
effigies 972f76a
Merge pull request #1 from effigies/test/exponent_regex_tests
white-gecko 5b1a9d0
Fix for python 2.7
white-gecko File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 | ||||||
|
@@ -164,6 +165,31 @@ def testIssue156(self): | |||||
g = Graph() | ||||||
g.parse("test/n3/issue156.n3", format="n3") | ||||||
|
||||||
def testIssue999(self): | ||||||
""" | ||||||
Make sure the n3 parser does recognize exponent and leading dot in ".171e-11" | ||||||
""" | ||||||
data = """ | ||||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | ||||||
|
||||||
<http://qudt.org/vocab/unit/MilliM-PER-YR> | ||||||
a <http://qudt.org/schema/qudt/Unit> ; | ||||||
<http://qudt.org/schema/qudt/conversionMultiplier> .171e-11 ; | ||||||
<http://qudt.org/schema/qudt/conversionOffset> 0e+00 ; | ||||||
<http://qudt.org/schema/qudt/description> "0.001-fold of the SI base unit metre divided by the unit year" ; | ||||||
<http://qudt.org/schema/qudt/hasQuantityKind> <http://qudt.org/vocab/quantitykind/Velocity> ; | ||||||
<http://qudt.org/schema/qudt/iec61360Code> "0112/2///62720#UAA868" ; | ||||||
<http://qudt.org/schema/qudt/uneceCommonCode> "H66" ; | ||||||
rdfs:isDefinedBy <http://qudt.org/2.1/vocab/unit> ; | ||||||
rdfs:isDefinedBy <http://qudt.org/vocab/unit> ; | ||||||
rdfs:label "MilliM PER YR" ; | ||||||
<http://www.w3.org/2004/02/skos/core#prefLabel> "millimetre per year" ; | ||||||
. | ||||||
""" | ||||||
g = Graph() | ||||||
g.parse(data=data, format="n3") | ||||||
g.parse(data=data, format="turtle") | ||||||
|
||||||
def testDotInPrefix(self): | ||||||
g = Graph() | ||||||
g.parse( | ||||||
|
@@ -226,5 +252,24 @@ def testEmptyPrefix(self): | |||||
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
if __name__ == '__main__': | ||||||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
assetTrue
andassertFalse
which are effectively doing the same.