Skip to content

Commit a58749b

Browse files
committed
Merge branch 'wtf-importlib-resources'
* wtf-importlib-resources: Cover subdirectories in the traversable test. Ignore other Python junk.
2 parents 7f8b376 + 6f8a3d6 commit a58749b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

referencing_loaders/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def from_traversable(root: Traversable) -> Iterable[tuple[URI, Resource[Any]]]:
6262
return _from_walked(
6363
each
6464
for each in _walk_traversable(root)
65-
if not each.name.endswith(".py")
65+
if not each.name.endswith((".py", ".pyc", ".pyo"))
6666
)
6767

6868

@@ -75,4 +75,5 @@ def _from_walked(
7575
if specification is None:
7676
specification = Specification.detect(contents) # type: ignore[reportUnknownMemberType]
7777
resource = specification.detect(contents).create_resource(contents)
78-
yield getattr(path, "as_uri", lambda: "")(), resource
78+
uri = getattr(path, "as_uri", lambda: "")()
79+
yield uri, resource

referencing_loaders/tests/test_loaders.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ def test_traversable(tmp_path):
100100
"$schema": "https://json-schema.org/draft/2020-12/schema",
101101
"$id": "http://example.com/",
102102
}
103+
subpath, subschema = schemas / "more/child.json", {"foo": "bar"}
103104

104-
schemas.mkdir(parents=True)
105+
schemas.joinpath("more").mkdir(parents=True)
105106
package.joinpath("__init__.py").touch()
106107
path.write_text(json.dumps(schema))
108+
subpath.write_text(json.dumps(subschema))
107109

108110
# ?!?! -- without this, importlib.resources.files fails on 3.9 and no other
109111
# version!?!?
@@ -114,13 +116,14 @@ def test_traversable(tmp_path):
114116
resources = loaders.from_traversable(files("foo.schemas"))
115117
registry = EMPTY_REGISTRY.with_resources(resources)
116118

117-
assert (
118-
registry.crawl()
119-
== Registry()
120-
.with_contents(
121-
[(path.as_uri(), schema)],
122-
)
123-
.crawl()
119+
expected = Registry().with_resources(
120+
(each, DRAFT202012.create_resource(contents))
121+
for each, contents in [
122+
(path.as_uri(), schema),
123+
(subpath.as_uri(), subschema),
124+
]
124125
)
126+
127+
assert registry.crawl() == expected.crawl()
125128
finally:
126129
sys.path.pop()

0 commit comments

Comments
 (0)