Skip to content

Commit

Permalink
Tests and a changenote for corrupted metadata fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMino committed Jul 18, 2024
1 parent 5b62859 commit c1a9494
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Unconstrained `packaging` requirement. At the time of writing this, all
versions up to `packaging==24.1` pass the tests on Linux.

### Fixed
- Lazy mode will no longer confuse corrupted wheeldata with metadata - if
`WHEEL` file is corrupted or wrong, the `.wheeldata` will be set to `None`,
as opposed to `.metadata` as was the case previously. Thanks to
[mboisson](https://github.com/mboisson) for spotting this and the fix.

## [0.0.8] - 2021-08-03
### Changed
- Since `WheelFile` write methods now have `skipdir=True` default (see below),
Expand Down
37 changes: 37 additions & 0 deletions tests/test_corrupted_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from wheelfile import WheelFile


def test_when_metadata_is_corrupted_sets_metadata_to_none(buf):
wf = WheelFile(buf, distname="_", version="0", mode="w")
wf.metadata = "This is not a valid metadata" # type: ignore
wf.close()

with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
assert broken_wf.metadata is None


def test_when_wheeldata_is_corrupted_sets_wheeldata_to_none(buf):
wf = WheelFile(buf, distname="_", version="0", mode="w")
wf.wheeldata = "This is not a valid wheeldata" # type: ignore
wf.close()

with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
assert broken_wf.wheeldata is None


def test_wheeldata_is_read_even_if_metadata_corrupted(buf):
wf = WheelFile(buf, distname="_", version="0", mode="w")
wf.metadata = "This is not a valid metadata" # type: ignore
wf.close()

with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
assert broken_wf.wheeldata is not None


def test_metadata_is_read_even_if_wheeldata_corrupted(buf):
wf = WheelFile(buf, distname="_", version="0", mode="w")
wf.wheeldata = "This is not a valid wheeldata" # type: ignore
wf.close()

with WheelFile(buf, distname="_", version="0", mode="rl") as broken_wf:
assert broken_wf.metadata is not None

0 comments on commit c1a9494

Please sign in to comment.