Skip to content
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

test: improve coverage of curie validation #284

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions linkml_runtime/utils/uri_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
gen_delims = r"(?: : | / | \? | \# | \[ | \] | @ )"

# sub-delims = "!" / "$" / "&" / "'" / "("
sub_delims = r"(?: ! | \$ | & | ' | \( | \) | \* | \+ | , | ; | = )"
sub_delims = r"(?: ! | \$ | & | ' | \( | \) | \* | \+ | , | ; | = )"

# pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
pchar = rf"(?: {unreserved} | {pct_encoded} | {sub_delims} | : | @ )"
Expand Down Expand Up @@ -295,7 +295,7 @@
# As of now this module doesn't support NCNameChar IRI, but
# relative-refs as defined in URI,
# NCNameChar ::= Letter | Digit | '.' | '-' | '_'
NCNameChar = rf"(?: {ALPHA} | {DIGIT} | \. | \- | _ )"
NCNameChar = rf"(?: {ALPHA} | {DIGIT} | \. | \- | _ )"

# prefix := NCName
# NCName := (Letter | '_') (NCNameChar)*
Expand Down Expand Up @@ -324,17 +324,17 @@
#
### Compile the regular expressions for better performance

uri_validator = re.compile("^{}$".format(URI), re.VERBOSE)
uri_validator = re.compile(f"^{URI}$", re.VERBOSE)

#uri_ref_validator = re.compile("^{}$".format(URI_reference), re.VERBOSE)
#uri_ref_validator = re.compile(f"^{URI_reference}$", re.VERBOSE)

uri_relative_ref_validator = re.compile("^{}$".format(relative_ref), re.VERBOSE)
uri_relative_ref_validator = re.compile(f"^{relative_ref}$", re.VERBOSE)

abs_uri_validator = re.compile("^{}$".format(absolute_URI), re.VERBOSE)
abs_uri_validator = re.compile(f"^{absolute_URI}$", re.VERBOSE)

curie_validator = re.compile("^{}$".format(CURIE), re.VERBOSE)
curie_validator = re.compile(f"^{CURIE}$", re.VERBOSE)

safe_curie_validator = re.compile("^{}$".format(safe_CURIE), re.VERBOSE)
safe_curie_validator = re.compile(f"^{safe_CURIE}$", re.VERBOSE)

# -----------------------------------------------------------------------------
#
Expand All @@ -357,6 +357,5 @@ def validate_uri_reference(input):


def validate_curie(input):
# print(CURIE)
return curie_validator.match(input)

2 changes: 2 additions & 0 deletions tests/test_utils/test_metamodelcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def test_curie(self):
self.assertFalse(Curie.is_valid("type"))
self.assertEqual(":type", Curie(":type"))
self.assertTrue(Curie.is_valid(':type'))
self.assertTrue(Curie.is_valid('WIKIDATA_PROPERTY:P854'))
self.assertTrue(Curie.is_valid('WIKIDATA.PROPERTY:P854'))
with self.assertRaises(ValueError):
Curie("1df:type")
self.assertFalse(Curie.is_valid('1df:type'))
Expand Down