|
1 | 1 | import json
|
2 | 2 |
|
3 | 3 | from referencing import Registry
|
4 |
| -from referencing.jsonschema import EMPTY_REGISTRY |
| 4 | +from referencing.jsonschema import DRAFT202012, EMPTY_REGISTRY |
5 | 5 |
|
6 | 6 | import referencing_loaders as loaders
|
7 | 7 |
|
@@ -44,6 +44,43 @@ def test_absolute_internally_identified(tmp_path):
|
44 | 44 | assert registry.crawl() == expected.crawl()
|
45 | 45 |
|
46 | 46 |
|
| 47 | +def test_schema_is_inherited_downwards(tmp_path): |
| 48 | + root_path, root = tmp_path / "schema.json", { |
| 49 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 50 | + "$id": "http://example.com/", |
| 51 | + } |
| 52 | + son_path, son = tmp_path / "child/son.json", { |
| 53 | + "$id": "http://example.com/son", |
| 54 | + } |
| 55 | + daughter_path, daughter = tmp_path / "child/daughter.json", { |
| 56 | + "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 57 | + "$id": "http://example.com/random/daughter", |
| 58 | + } |
| 59 | + grandchild_path, grandchild = tmp_path / "child/more/gc.json", { |
| 60 | + "$id": "http://example.com/also/a/grandchild", |
| 61 | + } |
| 62 | + |
| 63 | + tmp_path.joinpath("child/more").mkdir(parents=True) |
| 64 | + root_path.write_text(json.dumps(root)) |
| 65 | + son_path.write_text(json.dumps(son)) |
| 66 | + daughter_path.write_text(json.dumps(daughter)) |
| 67 | + grandchild_path.write_text(json.dumps(grandchild)) |
| 68 | + |
| 69 | + expected = Registry().with_resources( |
| 70 | + (each, DRAFT202012.create_resource(contents)) |
| 71 | + for each, contents in [ |
| 72 | + (root_path.as_uri(), root), |
| 73 | + (son_path.as_uri(), son), |
| 74 | + (daughter_path.as_uri(), daughter), |
| 75 | + (grandchild_path.as_uri(), grandchild), |
| 76 | + ] |
| 77 | + ) |
| 78 | + |
| 79 | + resources = loaders.from_path(tmp_path) |
| 80 | + registry = EMPTY_REGISTRY.with_resources(resources) |
| 81 | + assert registry.crawl() == expected.crawl() |
| 82 | + |
| 83 | + |
47 | 84 | def test_empty(tmp_path):
|
48 | 85 | registry = EMPTY_REGISTRY.with_resources(loaders.from_path(tmp_path))
|
49 | 86 | assert registry == EMPTY_REGISTRY
|
0 commit comments