Skip to content

Commit

Permalink
Merge pull request #284 from linkml/fix-1701
Browse files Browse the repository at this point in the history
test: improve coverage of curie validation
  • Loading branch information
sierra-moxon authored Nov 8, 2023
2 parents 1feeb08 + d45970a commit 01838a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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

0 comments on commit 01838a0

Please sign in to comment.