Skip to content

Commit 58f9f25

Browse files
committed
tests(processing,cli): introduce tests for skip-extraction option.
1 parent d680083 commit 58f9f25

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

tests/test_cli.py

+34
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,37 @@ def test_skip_extension(
333333
result = runner.invoke(unblob.cli.cli, params)
334334
assert extracted_files_count == len(list(tmp_path.rglob("*")))
335335
assert result.exit_code == 0
336+
337+
338+
@pytest.mark.parametrize(
339+
"args, skip_extraction, fail_message",
340+
[
341+
([], False, "Should *NOT* have skipped extraction"),
342+
(["-s"], True, "Should have skipped extraction"),
343+
(["--skip-extraction"], True, "Should have skipped extraction"),
344+
],
345+
)
346+
def test_skip_extraction(
347+
args: List[str], skip_extraction: bool, fail_message: str, tmp_path: Path
348+
):
349+
runner = CliRunner()
350+
in_path = (
351+
Path(__file__).parent
352+
/ "integration"
353+
/ "archive"
354+
/ "zip"
355+
/ "regular"
356+
/ "__input__"
357+
/ "apple.zip"
358+
)
359+
params = [*args, "--extract-dir", str(tmp_path), str(in_path)]
360+
361+
process_file_mock = mock.MagicMock()
362+
with mock.patch.object(unblob.cli, "process_file", process_file_mock):
363+
result = runner.invoke(unblob.cli.cli, params)
364+
365+
assert result.exit_code == 0
366+
process_file_mock.assert_called_once()
367+
assert (
368+
process_file_mock.call_args.args[0].skip_extraction == skip_extraction
369+
), fail_message

tests/test_processing.py

+31
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,37 @@ def get_all(file_name, report_type: Type[ReportType]) -> List[ReportType]:
447447
)
448448

449449

450+
@pytest.mark.parametrize(
451+
"skip_extraction, file_count, extracted_file_count",
452+
[
453+
(True, 5, 0),
454+
(False, 5, 6),
455+
],
456+
)
457+
def test_skip_extraction(
458+
skip_extraction: bool,
459+
file_count: int,
460+
extracted_file_count: int,
461+
tmp_path: Path,
462+
extraction_config: ExtractionConfig,
463+
):
464+
input_file = tmp_path / "input"
465+
with zipfile.ZipFile(input_file, "w") as zf:
466+
for i in range(file_count):
467+
zf.writestr(f"file{i}", data=b"This is a test file.")
468+
469+
extraction_config.extract_root = tmp_path / "output"
470+
extraction_config.skip_extraction = skip_extraction
471+
472+
process_result = process_file(extraction_config, input_file)
473+
task_result_by_path = {r.task.path: r for r in process_result.results}
474+
475+
assert len(task_result_by_path) == extracted_file_count + 1
476+
assert (
477+
len(list(extraction_config.extract_root.rglob("**/*"))) == extracted_file_count
478+
)
479+
480+
450481
class ConcatenateExtractor(DirectoryExtractor):
451482
def extract(self, paths: List[Path], outdir: Path):
452483
outfile = outdir / "data"

0 commit comments

Comments
 (0)