| 1 |
""" |
| 2 |
Test streaming module. |
| 3 |
""" |
| 4 |
|
| 5 |
from pathlib import Path |
| 6 |
|
| 7 |
import pytest |
| 8 |
from conda_package_streaming.exceptions import ( |
| 9 |
CaseInsensitiveFileSystemError as CPSCaseInsensitiveFileSystemError, |
| 10 |
) |
| 11 |
from pytest_mock import MockerFixture |
| 12 |
|
| 13 |
from conda_package_handling.exceptions import CaseInsensitiveFileSystemError, InvalidArchiveError |
| 14 |
from conda_package_handling.streaming import _extract, _stream_components |
| 15 |
|
| 16 |
from .test_interface import TEST_CONDA |
| 17 |
|
| 18 |
|
| 19 |
def test__stream_components(tmp_path: Path, mocker: MockerFixture): |
| 20 |
""" |
| 21 |
Execute two error handling paths in _stream_components |
| 22 |
""" |
| 23 |
test_file = tmp_path / "hello.conda" |
| 24 |
test_file.write_text("hello") |
| 25 |
with pytest.raises(InvalidArchiveError): |
| 26 |
list(_stream_components(test_file, ["pkg"])) |
| 27 |
|
| 28 |
# translates their exception to our exception of the same name |
| 29 |
mocker.patch( |
| 30 |
"conda_package_streaming.package_streaming.stream_conda_component", |
| 31 |
side_effect=CPSCaseInsensitiveFileSystemError(), |
| 32 |
) |
| 33 |
|
| 34 |
with pytest.raises(CaseInsensitiveFileSystemError): |
| 35 |
list(_stream_components(TEST_CONDA, ["pkg"])) |
| 36 |
|
| 37 |
|
| 38 |
def test__extract(tmp_path: Path, mocker: MockerFixture): |
| 39 |
# translates their exception to our exception of the same name |
| 40 |
mocker.patch( |
| 41 |
"conda_package_handling.streaming.extract_stream", |
| 42 |
side_effect=CPSCaseInsensitiveFileSystemError(), |
| 43 |
) |
| 44 |
|
| 45 |
with pytest.raises(CaseInsensitiveFileSystemError): |
| 46 |
_extract(str(TEST_CONDA), str(tmp_path), ["pkg", "info"]) |