Debian Codegraph @

tests/test_streaming.py

raw ◀ ▶
1 Debian patch touch this file
1 import io
2 import json
3 import tarfile
4
5 import pytest
6
7 from conda_package_streaming import package_streaming
8
•9 @pytest.mark.skip(reason="Conda is not yet available for Debian")
10 def test_package_streaming(conda_paths):
11 for path in conda_paths:
12 if str(path).endswith(".conda"):
13 with pytest.raises(LookupError):
14 package_streaming.stream_conda_component(path, component="notfound")
15
16 with pytest.raises(ValueError):
17 package_streaming.stream_conda_component("notapackage.rar")
18
•19 @pytest.mark.skip(reason="Conda is not yet available for Debian")
20 def test_early_exit(conda_paths):
21 for package in conda_paths:
22 print(package)
23 stream = iter(package_streaming.stream_conda_info(package))
24 found = False
25 for tar, member in stream:
26 assert not found, "early exit did not work"
27 if member.name == "info/index.json":
28 reader = tar.extractfile(member)
29 if reader:
30 json.load(reader)
31 found = True
32 stream.close() # PEP 342 close()
33 # stream_conda_info doesn't close a passed-in fileobj, but a
34 # filename should be closed.
35 assert found, f"index.json not found in {package}"
36
37
38 def test_chmod_error(tmp_path, monkeypatch):
39 """
40 Coverage for os.chmod() error handling.
41 """
42 with package_streaming.TarfileNoSameOwner(tmp_path / "test.tar", mode="w") as tar:
43 member = tarfile.TarInfo(name="file")
44 tar.addfile(member, io.BytesIO())
45
46 def not_chmod(*args):
47 raise OSError()
48
49 monkeypatch.setattr("os.chmod", not_chmod)
50 with pytest.raises(tarfile.ExtractError):
51 # only logs a debug message if errorlevel<=1
52 with package_streaming.TarfileNoSameOwner(
53 tmp_path / "test.tar", errorlevel=2
54 ) as tar:
55 tar.extractall(tmp_path)