Skip to content

Commit

Permalink
test_expand.py::test_local_context is now 🟢
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-scherbakov committed Jun 16, 2024
1 parent 0428ffe commit 876f7c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 0 additions & 4 deletions tests/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ def test_empty_value():
assert not yaml_ld.expand(document)


@pytest.mark.xfail(
raises=JsonLdError,
reason='`pyld` does not handle `file://` paths.',
)
def test_local_context():
document = specifications_root / 'json-ld-api/tests/expand/0127-in.jsonld'
yaml_ld.expand(document)
Expand Down
17 changes: 17 additions & 0 deletions yaml_ld/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,29 @@ def except_json_ld_errors():
) from err


def construct_base_by_document(document: str) -> str | None:
if isinstance(document, list | str):
return None

if isinstance(document, str):
document = URL(document)

if isinstance(document, URL):
document = Path(document.path)

if isinstance(document, Path):
return f'file://{document.parent}/'


@validate_call(config=dict(arbitrary_types_allowed=True))
def expand( # noqa: C901, WPS211
document: SerializedDocument | Document,
options: ExpandOptions = ExpandOptions(),
) -> Document | list[Document]:
"""Expand a YAML-LD document."""
if not options.base:
options.base = construct_base_by_document(document)

with except_json_ld_errors():
return jsonld.expand(
input_=str(document) if (
Expand Down

0 comments on commit 876f7c0

Please sign in to comment.