Compare commits

...

2 Commits

Author SHA1 Message Date
Val Lorentz df975efcd3 Add tests for field id clashes 2023-05-21 14:33:53 +02:00
Val Lorentz c414514de3 Fix typo 2023-05-21 14:06:14 +02:00
2 changed files with 34 additions and 1 deletions

View File

@ -61,7 +61,7 @@ class Field(abc.ABC, Generic[_TFieldValue]):
to ``subject_var``.
For example, if this ``Field`` represents the `"CPU frequency"
<https://www.wikidata.org/wiki/Property:P2144>`, ``subject_var`` is ``a``, and
<https://www.wikidata.org/wiki/Property:P2144>`__, ``subject_var`` is ``a``, and
``object_var`` is `b``, this will return::
?subject_var <http://www.wikidata.org/prop/direct/P2144> ?object_var.

View File

@ -14,6 +14,7 @@
import textwrap
import pytest
import rdflib
from glowtables.table import Language, LiteralField, Table
@ -90,3 +91,35 @@ def test_default_value() -> None:
}
"""
)
def test_field_id_subject() -> None:
name_field = LiteralField(
"subject",
{Language("en"): "Name"},
rdflib.URIRef("http://example.org/display-name"),
)
with pytest.raises(ValueError, match="both subject and a field id"):
Table(
fields=[name_field],
constraints="",
)
def test_field_id_clash() -> None:
name_field = LiteralField(
"name",
{Language("en"): "Name"},
rdflib.URIRef("http://example.org/name"),
)
display_name_field = LiteralField(
"name",
{Language("en"): "Display Name"},
rdflib.URIRef("http://example.org/display-name"),
)
with pytest.raises(ValueError, match="has duplicate field ids: name"):
Table(
fields=[name_field, display_name_field],
constraints="",
)