|
1 |
| -def test_it_imports(tmp_path): |
2 |
| - import referencing.loaders # noqa: F401 |
| 1 | +import json |
| 2 | + |
| 3 | +from referencing import Registry, loaders |
| 4 | +from referencing.jsonschema import EMPTY_REGISTRY |
| 5 | + |
| 6 | + |
| 7 | +def test_absolute_internally_identified(tmp_path): |
| 8 | + root_path, root = tmp_path / "schema.json", { |
| 9 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 10 | + "$id": "http://example.com/", |
| 11 | + } |
| 12 | + son_path, son = tmp_path / "child/son.json", { |
| 13 | + "$schema": "https://json-schema.org/draft/2019-09/schema", |
| 14 | + "$id": "http://example.com/son", |
| 15 | + } |
| 16 | + daughter_path, daughter = tmp_path / "child/daughter.json", { |
| 17 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 18 | + "$id": "http://example.com/random/daughter", |
| 19 | + } |
| 20 | + grandchild_path, grandchild = tmp_path / "child/more/gc.json", { |
| 21 | + "$schema": "https://json-schema.org/draft/2019-09/schema", |
| 22 | + "$id": "http://example.com/also/a/grandchild", |
| 23 | + } |
| 24 | + |
| 25 | + tmp_path.joinpath("child/more").mkdir(parents=True) |
| 26 | + root_path.write_text(json.dumps(root)) |
| 27 | + son_path.write_text(json.dumps(son)) |
| 28 | + daughter_path.write_text(json.dumps(daughter)) |
| 29 | + grandchild_path.write_text(json.dumps(grandchild)) |
| 30 | + |
| 31 | + expected = Registry().with_contents( |
| 32 | + [ |
| 33 | + (root_path.as_uri(), root), |
| 34 | + (son_path.as_uri(), son), |
| 35 | + (daughter_path.as_uri(), daughter), |
| 36 | + (grandchild_path.as_uri(), grandchild), |
| 37 | + ], |
| 38 | + ) |
| 39 | + |
| 40 | + resources = loaders.from_path(tmp_path) |
| 41 | + registry = EMPTY_REGISTRY.with_resources(resources) |
| 42 | + assert registry.crawl() == expected.crawl() |
| 43 | + |
| 44 | + |
| 45 | +def test_empty(tmp_path): |
| 46 | + registry = EMPTY_REGISTRY.with_resources(loaders.from_path(tmp_path)) |
| 47 | + assert registry == EMPTY_REGISTRY |
| 48 | + |
| 49 | + |
| 50 | +def test_custom_loads(tmp_path): |
| 51 | + pass |
0 commit comments