33import argparse
44import lzma
55import zipfile
6+ import zlib
67from pathlib import Path
78
89import pytest
@@ -44,7 +45,7 @@ def test_environment_action(
4445 assert expected == args .PLAT
4546
4647
47- def test_environment_action_invalid_env (monkeypatch : pytest .MonkeyPatch ) -> None :
48+ def test_environment_action_invalid_plat_env (monkeypatch : pytest .MonkeyPatch ) -> None :
4849 choices = ["linux" , "manylinux1" , "manylinux2010" ]
4950 monkeypatch .setenv ("AUDITWHEEL_PLAT" , "foo" )
5051 p = argparse .ArgumentParser ()
@@ -59,6 +60,39 @@ def test_environment_action_invalid_env(monkeypatch: pytest.MonkeyPatch) -> None
5960 )
6061
6162
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+
6296def _write_test_permissions_zip (path : Path ) -> None :
6397 source_zip_xz = Path (__file__ ).parent / "test-permissions.zip.xz"
6498 with lzma .open (source_zip_xz ) as f :
0 commit comments