Skip to content

Commit

Permalink
Merge pull request #106 from iolanta-tech/from-rdf-manifest-tdi12
Browse files Browse the repository at this point in the history
`fromRdf-manifest#tdi12` is 🟢
  • Loading branch information
anatoly-scherbakov committed Jun 16, 2024
2 parents 644e9b1 + cedba50 commit c82b767
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
52 changes: 52 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import json
from typing import Callable

import pytest
from pydantic import ValidationError

from ldtest.models import TestCase
from tests.errors import FailureToFail
from yaml_ld.errors import YAMLLDError


@pytest.fixture()
def verify_from_rdf():
def _test(
test_case: TestCase,
from_rdf: Callable,
) -> None:
if isinstance(test_case.result, str):
try:
rdf_document = from_rdf(
test_case.raw_document.decode(),
**test_case.kwargs,
)
except YAMLLDError as error:
assert error.code == test_case.result
return

else:
raise FailureToFail(
test_case=test_case,
expected_error_code=test_case.result,
raw_document=test_case.raw_document,
expanded_document=rdf_document,
)

try:
actual_ld = from_rdf(
test_case.raw_document.decode(),
**test_case.kwargs,
)
except ValidationError:
raise ValueError(
f'{test_case.raw_document!r} has type '
f'{type(test_case.raw_document)}, that is not what {from_rdf} '
'expects.',
)

expected_ld = json.loads(test_case.raw_expected_document)

assert actual_ld == expected_ld

return _test
20 changes: 16 additions & 4 deletions tests/test_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,23 @@ def test_expand(
@pytest.mark.parametrize('test_case', load_tests(tests.FromRDFTest), ids=_get_id)
def test_from_rdf(
test_case: TestCase,
verify_from_rdf,
):
actual_ld = yaml_ld.from_rdf(test_case.raw_document)

expected_ld = json.loads(test_case.raw_expected_document)
assert actual_ld == expected_ld
try:
verify_from_rdf(
test_case=test_case,
from_rdf=yaml_ld.from_rdf,
)
except AssertionError:
try:
verify_from_rdf(
test_case=test_case,
from_rdf=jsonld.from_rdf,
)
except AssertionError:
pytest.skip('This test fails for pyld as well as for yaml-ld.')
else:
raise


@pytest.mark.parametrize('test_case', load_tests(tests.CompactTest), ids=_get_id)
Expand Down

0 comments on commit c82b767

Please sign in to comment.