| 1 |
""" |
| 2 |
Allow conda_package_streaming to work in .tar.bz2-only mode if zstd support is |
| 3 |
not available. |
| 4 |
""" |
| 5 |
|
| 6 |
import importlib |
| 7 |
import sys |
| 8 |
import tarfile |
| 9 |
import zipfile |
| 10 |
from pathlib import Path |
| 11 |
|
| 12 |
import pytest |
| 13 |
|
| 14 |
|
| 15 |
def test_degraded(tmpdir): |
| 16 |
try: |
| 17 |
sys.modules["backports.zstd"] = None # type: ignore |
| 18 |
sys.modules["compression.zstd"] = None # type: ignore |
| 19 |
|
| 20 |
import conda_package_streaming.extract |
| 21 |
import conda_package_streaming.package_streaming |
| 22 |
|
| 23 |
importlib.reload(conda_package_streaming.package_streaming) |
| 24 |
|
| 25 |
testconda = Path(tmpdir, "testconda.conda") |
| 26 |
with zipfile.ZipFile(testconda, "w"): |
| 27 |
pass |
| 28 |
|
| 29 |
testtar = Path(tmpdir, "test.tar.bz2") |
| 30 |
with tarfile.open(testtar, "w:bz2") as tar: |
| 31 |
tar.addfile(tarfile.TarInfo(name="jim")) |
| 32 |
|
| 33 |
for ( |
| 34 |
tar, |
| 35 |
_, |
| 36 |
) in conda_package_streaming.package_streaming.stream_conda_component(testtar): |
| 37 |
pass |
| 38 |
|
| 39 |
with pytest.raises(RuntimeError): |
| 40 |
for ( |
| 41 |
tar, |
| 42 |
_, |
| 43 |
) in conda_package_streaming.package_streaming.stream_conda_component( |
| 44 |
testconda |
| 45 |
): |
| 46 |
pass # pragma: no cover |
| 47 |
|
| 48 |
with pytest.raises(RuntimeError): |
| 49 |
conda_package_streaming.extract.extract(testconda, tmpdir) |
| 50 |
|
| 51 |
finally: |
| 52 |
sys.modules.pop("compression.zstd", None) |
| 53 |
sys.modules.pop("backports.zstd", None) |
| 54 |
|
| 55 |
import conda_package_streaming.package_streaming |
| 56 |
|
| 57 |
importlib.reload(conda_package_streaming.package_streaming) |
| 58 |
assert conda_package_streaming.package_streaming.zstd |