diff --git a/prez/config.py b/prez/config.py index 567cd5c1..4f252769 100755 --- a/prez/config.py +++ b/prez/config.py @@ -5,7 +5,7 @@ import toml from pydantic import field_validator from pydantic_settings import BaseSettings -from rdflib import DCTERMS, RDFS, SDO, URIRef +from rdflib import DCTERMS, RDFS, SDO, Graph, URIRef from rdflib.namespace import SKOS from prez.reference_data.prez_ns import EP, REG @@ -130,14 +130,20 @@ def get_version(cls, v): "other_predicates", ) def validate_predicates(cls, v): + nm = Graph().namespace_manager + predicates = [] try: - v = [URIRef(predicate) for predicate in v] + for predicate in v: + if predicate.startswith("http"): + predicates.append(URIRef(predicate)) + else: + predicates.append(URIRef(nm.expand_curie(predicate))) except ValueError as e: raise ValueError( - "Could not parse predicates. predicates must be valid URIs no prefixes allowed " + "Could not parse predicates. All predicates must be valid URIs\n" f"original message: {e}" ) - return v + return predicates settings = Settings() diff --git a/tests/test_predicates.py b/tests/test_predicates.py index c4259e61..27e1ad1e 100644 --- a/tests/test_predicates.py +++ b/tests/test_predicates.py @@ -1,4 +1,5 @@ import pytest +from pydantic import ValidationError from prez.config import Settings @@ -7,8 +8,8 @@ "label_predicates, error", [ [["https://schema.org/name"], None], - [["1", "2", "3"], None], - [[1], TypeError], + [["1", "2", "3"], ValidationError], + [[1], AttributeError], ["not a list", ValueError], ], ) @@ -24,8 +25,8 @@ def test_label_predicates(label_predicates, error): "description_predicates, error", [ [["https://schema.org/description"], None], - [["1", "2", "3"], None], - [[1], TypeError], + [["1", "2", "3"], ValidationError], + [[1], AttributeError], ["not a list", ValueError], ], ) @@ -41,8 +42,8 @@ def test_description_predicates(description_predicates, error): "provenance_predicates, error", [ [["https://schema.org/provenance"], None], - [["1", "2", "3"], None], - [[1], TypeError], + [["1", "2", "3"], ValidationError], + [[1], AttributeError], ["not a list", ValueError], ], ) @@ -58,8 +59,8 @@ def test_provenance_predicates(provenance_predicates, error): "search_predicates, error", [ [["https://schema.org/search"], None], - [["1", "2", "3"], None], - [[1], TypeError], + [["1", "2", "3"], ValidationError], + [[1], AttributeError], ["not a list", ValueError], ], ) @@ -75,8 +76,8 @@ def test_search_predicates(search_predicates, error): "other_predicates, error", [ [["https://schema.org/other"], None], - [["1", "2", "3"], None], - [[1], TypeError], + [["1", "2", "3"], ValidationError], + [[1], AttributeError], ["not a list", ValueError], ], )