Skip to content

Commit

Permalink
add warning
Browse files Browse the repository at this point in the history
  • Loading branch information
MBueschelberger committed Dec 1, 2024
1 parent ef975df commit c92de92
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions data2rdf/models/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from data2rdf.qudt.utils import _get_query_match
from data2rdf.utils import make_prefix
from data2rdf.warnings import ParserWarning

from data2rdf.models.utils import ( # isort:skip
apply_datatype,
Expand Down Expand Up @@ -141,6 +142,11 @@ def validate_value(
value = int(value)
elif isinstance(value, str) and is_float(value):
value = float(value)
elif isinstance(value, str):
warnings.warn(
f"Cannot type case value from str into float or int: {value}",
ParserWarning
)
return value

@field_validator("unit", mode="after")
Expand Down
31 changes: 21 additions & 10 deletions tests/abox/json_custom_relations/test_json_custom_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,28 @@ def test_pipeline_json_custom_relations_quantity_graph() -> None:
from rdflib import Graph

from data2rdf import Data2RDF, Parser
from data2rdf.warnings import ParserWarning

with pytest.warns(ParserWarning, match="Cannot") as warnings:

pipeline = Data2RDF(
raw_data=DATA_SUBGRAPHS,
mapping=MAPPING_SUBGRAPHS,
parser=Parser.json,
config={
"base_iri": BASE_IRI,
"separator": "#",
"suppress_file_description": True,
},
)

warnings = [
warning
for warning in warnings
if warning.category == ParserWarning
]
assert len(warnings) == 1

pipeline = Data2RDF(
raw_data=DATA_SUBGRAPHS,
mapping=MAPPING_SUBGRAPHS,
parser=Parser.json,
config={
"base_iri": BASE_IRI,
"separator": "#",
"suppress_file_description": True,
},
)
expected_graph = Graph()
expected_graph.parse(data=EXPECTED_SUBGRAPHS)

Expand Down

0 comments on commit c92de92

Please sign in to comment.