3
3
import argparse
4
4
import lzma
5
5
import zipfile
6
+ import zlib
6
7
from pathlib import Path
7
8
8
9
import pytest
@@ -44,7 +45,7 @@ def test_environment_action(
44
45
assert expected == args .PLAT
45
46
46
47
47
- def test_environment_action_invalid_env (monkeypatch : pytest .MonkeyPatch ) -> None :
48
+ def test_environment_action_invalid_plat_env (monkeypatch : pytest .MonkeyPatch ) -> None :
48
49
choices = ["linux" , "manylinux1" , "manylinux2010" ]
49
50
monkeypatch .setenv ("AUDITWHEEL_PLAT" , "foo" )
50
51
p = argparse .ArgumentParser ()
@@ -59,6 +60,39 @@ def test_environment_action_invalid_env(monkeypatch: pytest.MonkeyPatch) -> None
59
60
)
60
61
61
62
63
+ def test_environment_action_invalid_zip_env (monkeypatch : pytest .MonkeyPatch ) -> None :
64
+ choices = list (range (zlib .Z_NO_COMPRESSION , zlib .Z_BEST_COMPRESSION + 1 ))
65
+ monkeypatch .setenv ("AUDITWHEEL_ZIP_LEVEL" , "foo" )
66
+ p = argparse .ArgumentParser ()
67
+ with pytest .raises (argparse .ArgumentError ):
68
+ p .add_argument (
69
+ "-z" ,
70
+ "--zip-level" ,
71
+ action = EnvironmentDefault ,
72
+ metavar = "zip" ,
73
+ env = "AUDITWHEEL_ZIP_LEVEL" ,
74
+ dest = "zip" ,
75
+ type = int ,
76
+ help = "Compress level to be used to create zip file." ,
77
+ choices = choices ,
78
+ default = zlib .Z_DEFAULT_COMPRESSION ,
79
+ )
80
+ monkeypatch .setenv ("AUDITWHEEL_ZIP_LEVEL" , "10" )
81
+ with pytest .raises (argparse .ArgumentError ):
82
+ p .add_argument (
83
+ "-z" ,
84
+ "--zip-level" ,
85
+ action = EnvironmentDefault ,
86
+ metavar = "zip" ,
87
+ env = "AUDITWHEEL_ZIP_LEVEL" ,
88
+ dest = "zip" ,
89
+ type = int ,
90
+ help = "Compress level to be used to create zip file." ,
91
+ choices = choices ,
92
+ default = zlib .Z_DEFAULT_COMPRESSION ,
93
+ )
94
+
95
+
62
96
def _write_test_permissions_zip (path : Path ) -> None :
63
97
source_zip_xz = Path (__file__ ).parent / "test-permissions.zip.xz"
64
98
with lzma .open (source_zip_xz ) as f :
0 commit comments