ontolutils 0.2.23__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ontolutils-0.2.23 → ontolutils-0.3.0}/PKG-INFO +1 -1
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/thing.py +1 -1
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils.egg-info/PKG-INFO +1 -1
- {ontolutils-0.2.23 → ontolutils-0.3.0}/setup.cfg +1 -1
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_classes.py +27 -5
- {ontolutils-0.2.23 → ontolutils-0.3.0}/LICENSE +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/README.md +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/__init__.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/_version.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/cache.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/__init__.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/decorator.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/query_util.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/typing.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/classes/utils.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/__dev.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/__init__.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/_iana_utils.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/codemeta.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/m4i.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/obo.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/qudt_kind.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/qudt_unit.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/schema.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/namespacelib/ssno.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/utils/__init__.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils/utils/qudt_units.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils.egg-info/SOURCES.txt +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils.egg-info/dependency_links.txt +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils.egg-info/requires.txt +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/ontolutils.egg-info/top_level.txt +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/pyproject.toml +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/setup.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_decorator.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_namespaces.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_query.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_readme.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_typing.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_utils.py +0 -0
- {ontolutils-0.2.23 → ontolutils-0.3.0}/tests/test_version.py +0 -0
|
@@ -19,7 +19,7 @@ logger = logging.getLogger('ontolutils')
|
|
|
19
19
|
EXTRA = 'allow' # or 'forbid' or 'ignore'
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
class ThingModel(BaseModel, abc.ABC):
|
|
22
|
+
class ThingModel(BaseModel, abc.ABC, validate_assignment=True):
|
|
23
23
|
"""Abstract base model class to be used by model classes used within ontolutils"""
|
|
24
24
|
|
|
25
25
|
model_config = ConfigDict(extra=EXTRA, populate_by_name=True)
|
|
@@ -2,10 +2,13 @@ import datetime
|
|
|
2
2
|
import json
|
|
3
3
|
import logging
|
|
4
4
|
import unittest
|
|
5
|
-
from
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
6
7
|
import pydantic
|
|
7
8
|
import rdflib
|
|
8
|
-
from pydantic import EmailStr
|
|
9
|
+
from pydantic import EmailStr
|
|
10
|
+
from pydantic import field_validator, Field
|
|
11
|
+
from rdflib.plugins.shared.jsonld.context import Context
|
|
9
12
|
|
|
10
13
|
from ontolutils import Thing, urirefs, namespaces, get_urirefs, get_namespaces
|
|
11
14
|
from ontolutils import set_logging_level
|
|
@@ -45,6 +48,13 @@ class TestNamespaces(unittest.TestCase):
|
|
|
45
48
|
"""
|
|
46
49
|
name: str = Field(default=None, alias="lastName") # name is synonymous to lastName
|
|
47
50
|
age: int = None
|
|
51
|
+
special_field: Optional[str] = None
|
|
52
|
+
|
|
53
|
+
@field_validator('special_field', mode="before")
|
|
54
|
+
@classmethod
|
|
55
|
+
def _special_field(cls, value):
|
|
56
|
+
assert value == "special_string", f"Special field must be 'special_string' not {value}"
|
|
57
|
+
return value
|
|
48
58
|
|
|
49
59
|
agent = Agent(name='John Doe', age=23)
|
|
50
60
|
self.assertEqual(agent.name, 'John Doe')
|
|
@@ -59,6 +69,17 @@ class TestNamespaces(unittest.TestCase):
|
|
|
59
69
|
self.assertEqual(agent.name, None)
|
|
60
70
|
self.assertEqual(agent.age, 23)
|
|
61
71
|
|
|
72
|
+
# property assignment should fail:
|
|
73
|
+
with self.assertRaises(pydantic.ValidationError):
|
|
74
|
+
agent.age = "invalid"
|
|
75
|
+
|
|
76
|
+
with self.assertRaises(pydantic.ValidationError):
|
|
77
|
+
agent.special_field = "invalid"
|
|
78
|
+
self.assertEqual(agent.special_field, None)
|
|
79
|
+
|
|
80
|
+
agent.special_field = "special_string"
|
|
81
|
+
self.assertEqual(agent.special_field, "special_string")
|
|
82
|
+
|
|
62
83
|
def test_resolve_iri(self):
|
|
63
84
|
ret = resolve_iri('foaf:age', context=Context(source={'foaf': 'http://xmlns.com/foaf/0.1/'}))
|
|
64
85
|
self.assertEqual(ret, 'http://xmlns.com/foaf/0.1/age')
|
|
@@ -72,7 +93,8 @@ class TestNamespaces(unittest.TestCase):
|
|
|
72
93
|
ret = resolve_iri('label', context=Context(source={'age': 'http://xmlns.com/foaf/0.1/age'}))
|
|
73
94
|
self.assertEqual(ret, 'http://www.w3.org/2000/01/rdf-schema#label')
|
|
74
95
|
|
|
75
|
-
ret = resolve_iri('label',
|
|
96
|
+
ret = resolve_iri('label',
|
|
97
|
+
context=Context(source={'label': {'@id': 'http://www.w3.org/2000/01/rdf-schema#label'}}))
|
|
76
98
|
self.assertEqual(ret, 'http://www.w3.org/2000/01/rdf-schema#label')
|
|
77
99
|
|
|
78
100
|
ret = resolve_iri('prefix:label', Context(source={}))
|
|
@@ -93,6 +115,7 @@ class TestNamespaces(unittest.TestCase):
|
|
|
93
115
|
def test_thing_custom_prop(self):
|
|
94
116
|
"""It is helpful to have the properties equal to the urirefs keys,
|
|
95
117
|
however, this should not be required!"""
|
|
118
|
+
|
|
96
119
|
@namespaces(foaf='http://xmlns.com/foaf/0.1/',
|
|
97
120
|
schema='http://www.schema.org/')
|
|
98
121
|
@urirefs(Affiliation='prov:Affiliation',
|
|
@@ -110,7 +133,7 @@ class TestNamespaces(unittest.TestCase):
|
|
|
110
133
|
first_name: str = Field(default=None, alias='firstName')
|
|
111
134
|
lastName: str
|
|
112
135
|
age: int = None
|
|
113
|
-
affiliation: Affiliation=None
|
|
136
|
+
affiliation: Affiliation = None
|
|
114
137
|
|
|
115
138
|
p = Person(first_name='John', lastName='Doe', age=23)
|
|
116
139
|
person_json = p.model_dump_jsonld(resolve_keys=False)
|
|
@@ -341,7 +364,6 @@ class TestNamespaces(unittest.TestCase):
|
|
|
341
364
|
self.assertEqual(jsonld_dict['rdfs:label'], 'Person 1')
|
|
342
365
|
self.assertEqual(jsonld_dict['@type'], 'foaf:Person')
|
|
343
366
|
|
|
344
|
-
|
|
345
367
|
def test_prov(self):
|
|
346
368
|
@namespaces(prov="https://www.w3.org/ns/prov#",
|
|
347
369
|
foaf="http://xmlns.com/foaf/0.1/")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|