Skip to content

Commit 01838a0

Browse files
authored
Merge pull request #284 from linkml/fix-1701
test: improve coverage of curie validation
2 parents 1feeb08 + d45970a commit 01838a0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

linkml_runtime/utils/uri_validator.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
gen_delims = r"(?: : | / | \? | \# | \[ | \] | @ )"
4343

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

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

300300
# prefix := NCName
301301
# NCName := (Letter | '_') (NCNameChar)*
@@ -324,17 +324,17 @@
324324
#
325325
### Compile the regular expressions for better performance
326326

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

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

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

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

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

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

339339
# -----------------------------------------------------------------------------
340340
#
@@ -357,6 +357,5 @@ def validate_uri_reference(input):
357357

358358

359359
def validate_curie(input):
360-
# print(CURIE)
361360
return curie_validator.match(input)
362361

tests/test_utils/test_metamodelcore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def test_curie(self):
6464
self.assertFalse(Curie.is_valid("type"))
6565
self.assertEqual(":type", Curie(":type"))
6666
self.assertTrue(Curie.is_valid(':type'))
67+
self.assertTrue(Curie.is_valid('WIKIDATA_PROPERTY:P854'))
68+
self.assertTrue(Curie.is_valid('WIKIDATA.PROPERTY:P854'))
6769
with self.assertRaises(ValueError):
6870
Curie("1df:type")
6971
self.assertFalse(Curie.is_valid('1df:type'))

0 commit comments

Comments
 (0)