Skip to content

Commit

Permalink
tests: skip extensions cli test shouldn't call process file either
Browse files Browse the repository at this point in the history
all other tests in this file assert on `process_file` being called
with correct arguments. We need specific tests which test that the
configuration is interpreted correctly
  • Loading branch information
vlaci committed Dec 4, 2024
1 parent 495e351 commit f5b2974
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Iterable, List, Optional, Type
from typing import Iterable, List, Optional, Tuple, Type
from unittest import mock

import pytest
Expand All @@ -13,6 +13,7 @@
from unblob.processing import (
DEFAULT_DEPTH,
DEFAULT_PROCESS_NUM,
DEFAULT_SKIP_EXTENSION,
DEFAULT_SKIP_MAGIC,
ExtractionConfig,
)
Expand Down Expand Up @@ -310,16 +311,16 @@ def test_keep_extracted_chunks(


@pytest.mark.parametrize(
"skip_extension, extracted_files_count",
"skip_extension, expected_skip_extensions",
[
pytest.param([], 5, id="skip-extension-empty"),
pytest.param([""], 5, id="skip-zip-extension-empty-suffix"),
pytest.param([".zip"], 0, id="skip-extension-zip"),
pytest.param([".rlib"], 5, id="skip-extension-rlib"),
pytest.param((), DEFAULT_SKIP_EXTENSION, id="skip-extension-empty"),
pytest.param(("",), ("",), id="skip-zip-extension-empty-suffix"),
pytest.param((".zip",), (".zip",), id="skip-extension-zip"),
pytest.param((".rlib",), (".rlib",), id="skip-extension-rlib"),
],
)
def test_skip_extension(
skip_extension: List[str], extracted_files_count: int, tmp_path: Path
skip_extension: List[str], expected_skip_extensions: Tuple[str, ...], tmp_path: Path
):
runner = CliRunner()
in_path = (
Expand All @@ -335,8 +336,12 @@ def test_skip_extension(
for suffix in skip_extension:
args += ["--skip-extension", suffix]
params = [*args, "--extract-dir", str(tmp_path), str(in_path)]
result = runner.invoke(unblob.cli.cli, params)
assert extracted_files_count == len(list(tmp_path.rglob("*")))
process_file_mock = mock.MagicMock()
with mock.patch.object(unblob.cli, "process_file", process_file_mock):
result = runner.invoke(unblob.cli.cli, params)
assert (
process_file_mock.call_args.args[0].skip_extension == expected_skip_extensions
)
assert result.exit_code == 0


Expand Down

0 comments on commit f5b2974

Please sign in to comment.