mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
This is the first step toward bundling all assets related to a save game into a single item. That makes it easier to avoid clobbering "temporary" assets from other games like the state.json, but also makes it easier for players to file bug reports, since there's only a single asset to upload. This is only the first step because so far it only includes the various save files: start of turn, end of last turn before results processing, and "latest" (the game saved explicitly by the player).
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from pathlib import Path
|
|
from zipfile import ZipFile
|
|
|
|
import pytest
|
|
|
|
from game.zipfileext import ZipFileExt
|
|
|
|
|
|
def test_remove_member_does_nothing_if_member_is_not_present(tmp_zip: Path) -> None:
|
|
expect_mtime = tmp_zip.stat().st_mtime
|
|
ZipFileExt.remove_member(tmp_zip, "c", missing_ok=True)
|
|
assert tmp_zip.stat().st_mtime == expect_mtime
|
|
|
|
|
|
def test_remove_member_raises_if_missing_not_ok(tmp_zip: Path) -> None:
|
|
with pytest.raises(ValueError):
|
|
ZipFileExt.remove_member(tmp_zip, "c")
|
|
|
|
|
|
def test_remove_member(tmp_zip: Path) -> None:
|
|
with ZipFile(tmp_zip, "w") as zip_file:
|
|
zip_file.writestr("a", "foo")
|
|
zip_file.writestr("b", "bar")
|
|
|
|
ZipFileExt.remove_member(tmp_zip, "a")
|
|
|
|
with ZipFile(tmp_zip, "r") as zip_file:
|
|
with pytest.raises(KeyError):
|
|
zip_file.read("a")
|
|
# Yes, we wrote a str, but ZipFile.read always returns bytes, and ZipFile.write
|
|
# requires an intermediate file. It's hard to write bytes, and hard to read str.
|
|
# This is all the single-byte range of UTF-8 anyway, so it doesn't matter.
|
|
assert zip_file.read("b") == b"bar"
|