-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from effigies/doc/recommend-spec-name
test: Run construct a zip module and verify acres functionality
- Loading branch information
Showing
7 changed files
with
166 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
changelog.d/20241209_154150_effigies_recommend_spec_name.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
<!-- | ||
### Added | ||
- A bullet item for the Added category. | ||
--> | ||
### Changed | ||
|
||
- Update recommended usage from `Loader(__package__)` to `Loader(__spec__.name)`. | ||
|
||
<!-- | ||
### Fixed | ||
- A bullet item for the Fixed category. | ||
--> | ||
<!-- | ||
### Deprecated | ||
- A bullet item for the Deprecated category. | ||
--> | ||
<!-- | ||
### Removed | ||
- A bullet item for the Removed category. | ||
--> | ||
<!-- | ||
### Security | ||
- A bullet item for the Security category. | ||
--> | ||
<!-- | ||
### Infrastructure | ||
- A bullet item for the Infrastructure category. | ||
--> |
44 changes: 44 additions & 0 deletions
44
changelog.d/20241209_154445_effigies_recommend_spec_name.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
--> | ||
|
||
### Added | ||
|
||
- Tests exercise and demonstrate the usage of acres on zipped modules. | ||
|
||
<!-- | ||
### Changed | ||
- A bullet item for the Changed category. | ||
--> | ||
### Fixed | ||
|
||
- Resolve cache misses when caching the same file from different loaders. | ||
|
||
<!-- | ||
### Deprecated | ||
- A bullet item for the Deprecated category. | ||
--> | ||
<!-- | ||
### Removed | ||
- A bullet item for the Removed category. | ||
--> | ||
<!-- | ||
### Security | ||
- A bullet item for the Security category. | ||
--> | ||
<!-- | ||
### Infrastructure | ||
- A bullet item for the Infrastructure category. | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[scriv] | ||
format = md | ||
main_branches = main | ||
version = literal: deno.json: version | ||
categories = Added, Changed, Fixed, Deprecated, Removed, Security, Infrastructure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from acres import Loader | ||
|
||
load_resource = Loader(__package__) # type: ignore[reportArgumentType,unused-ignore] | ||
load_resource = Loader(__spec__.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import sys | ||
import zipfile | ||
from pathlib import Path | ||
|
||
from acres import Loader | ||
|
||
|
||
def test_zipimport(tmp_path: Path) -> None: | ||
# Setup... no need for a fixture for a single test | ||
target_file = tmp_path / 'mymodule.zip' | ||
with zipfile.ZipFile(target_file, mode='w') as mymod: | ||
mymod.writestr( | ||
'mypkg/__init__.py', | ||
'from . import data\n', | ||
) | ||
mymod.writestr( | ||
'mypkg/data/__init__.py', | ||
'from acres import Loader\nload_resource = Loader(__spec__.name)\n', | ||
) | ||
mymod.writestr( | ||
'mypkg/data/resource.txt', | ||
'some text\n', | ||
) | ||
|
||
sys.path.insert(0, str(target_file)) | ||
|
||
# Test | ||
import mypkg # type: ignore[import-not-found] | ||
|
||
assert mypkg.__file__.endswith(os.path.join('mymodule.zip', 'mypkg', '__init__.py')) | ||
|
||
loader = mypkg.data.load_resource | ||
|
||
readable = loader.readable('resource.txt') | ||
assert not isinstance(readable, Path) | ||
assert readable.read_text() == 'some text\n' | ||
|
||
with loader.as_path('resource.txt') as path: | ||
assert isinstance(path, Path) | ||
assert path.exists() | ||
assert path.read_text() == 'some text\n' | ||
assert not path.exists() | ||
|
||
cached = loader.cached('resource.txt') | ||
assert isinstance(cached, Path) | ||
assert cached.exists() | ||
assert cached.read_text() == 'some text\n' | ||
|
||
new_loader = Loader('mypkg.data') | ||
assert new_loader.cached('resource.txt') == cached | ||
|
||
# Teardown | ||
sys.path.pop(0) |