Skip to content

Commit c1a9494

Browse files
committed
Tests and a changenote for corrupted metadata fix
1 parent 5b62859 commit c1a9494

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).
1717
- Unconstrained `packaging` requirement. At the time of writing this, all
1818
versions up to `packaging==24.1` pass the tests on Linux.
1919

20+
### Fixed
21+
- Lazy mode will no longer confuse corrupted wheeldata with metadata - if
22+
`WHEEL` file is corrupted or wrong, the `.wheeldata` will be set to `None`,
23+
as opposed to `.metadata` as was the case previously. Thanks to
24+
[mboisson](https://github.com/mboisson) for spotting this and the fix.
25+
2026
## [0.0.8] - 2021-08-03
2127
### Changed
2228
- Since `WheelFile` write methods now have `skipdir=True` default (see below),

tests/test_corrupted_metadata.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from wheelfile import WheelFile
2+
3+
4+
def test_when_metadata_is_corrupted_sets_metadata_to_none(buf):
5+
wf = WheelFile(buf, distname="_", version="0", mode="w")
6+
wf.metadata = "This is not a valid metadata" # type: ignore
7+
wf.close()
8+
9+
with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
10+
assert broken_wf.metadata is None
11+
12+
13+
def test_when_wheeldata_is_corrupted_sets_wheeldata_to_none(buf):
14+
wf = WheelFile(buf, distname="_", version="0", mode="w")
15+
wf.wheeldata = "This is not a valid wheeldata" # type: ignore
16+
wf.close()
17+
18+
with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
19+
assert broken_wf.wheeldata is None
20+
21+
22+
def test_wheeldata_is_read_even_if_metadata_corrupted(buf):
23+
wf = WheelFile(buf, distname="_", version="0", mode="w")
24+
wf.metadata = "This is not a valid metadata" # type: ignore
25+
wf.close()
26+
27+
with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
28+
assert broken_wf.wheeldata is not None
29+
30+
31+
def test_metadata_is_read_even_if_wheeldata_corrupted(buf):
32+
wf = WheelFile(buf, distname="_", version="0", mode="w")
33+
wf.wheeldata = "This is not a valid wheeldata" # type: ignore
34+
wf.close()
35+
36+
with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
37+
assert broken_wf.metadata is not None

0 commit comments

Comments
 (0)