| 1 |
""" |
| 2 |
Test conda-package-handling can work in `.tar.bz2`-only mode if zstd support is |
| 3 |
not available. |
| 4 |
""" |
| 5 |
|
| 6 |
import importlib |
| 7 |
import subprocess |
| 8 |
import sys |
| 9 |
import warnings |
| 10 |
|
| 11 |
|
| 12 |
def test_degraded(): |
| 13 |
try: |
| 14 |
sys.modules["backports.zstd"] = None # type: ignore |
| 15 |
sys.modules["compression.zstd"] = None # type: ignore |
| 16 |
sys.modules["conda_package_streaming.transmute"] = None # type: ignore |
| 17 |
sys.modules["conda_package_handling.conda_fmt"] = None # type: ignore |
| 18 |
|
| 19 |
# this is only testing conda_package_handling's code, and does not test |
| 20 |
# that conda_package_streaming works without zstd. |
| 21 |
|
| 22 |
with warnings.catch_warnings(record=True) as w: |
| 23 |
warnings.simplefilter("always") # Ensure warnings are sent |
| 24 |
import conda_package_handling.api |
| 25 |
|
| 26 |
importlib.reload(conda_package_handling.api) |
| 27 |
|
| 28 |
# Filter for warnings related to conda_package_handling |
| 29 |
cph_warnings = [ |
| 30 |
warning |
| 31 |
for warning in w |
| 32 |
if "backports.zstd" in str(warning.message) |
| 33 |
or "Python 3.14" in str(warning.message) |
| 34 |
] |
| 35 |
assert len(cph_warnings) >= 1 |
| 36 |
assert any(issubclass(w.category, UserWarning) for w in cph_warnings) |
| 37 |
assert conda_package_handling.api.libarchive_enabled is False |
| 38 |
|
| 39 |
finally: |
| 40 |
sys.modules.pop("compression.zstd", None) |
| 41 |
sys.modules.pop("backports.zstd", None) |
| 42 |
sys.modules.pop("conda_package_handling.conda_fmt", None) |
| 43 |
sys.modules.pop("conda_package_streaming.transmute", None) |
| 44 |
with warnings.catch_warnings(record=True) as w: |
| 45 |
warnings.simplefilter("always") # Ensure warnings are sent |
| 46 |
import conda_package_handling.api |
| 47 |
|
| 48 |
importlib.reload(conda_package_handling.api) |
| 49 |
assert len(w) == 0 |
| 50 |
assert conda_package_handling.api.libarchive_enabled is True |
| 51 |
|
| 52 |
|
| 53 |
def test_degraded_subprocess(): |
| 54 |
""" |
| 55 |
More reliable way to mock 'zstd not available' |
| 56 |
""" |
| 57 |
subprocess.check_call( |
| 58 |
[ |
| 59 |
sys.executable, |
| 60 |
"-c", |
| 61 |
"import sys; sys.modules['backports.zstd'] = None; sys.modules['compression.zstd'] = None; import conda_package_handling.api", |
| 62 |
] |
| 63 |
) |