Skip to content

Commit 9bae921

Browse files
committed
Remove test fixture and inline the gzip open in the test itself.
1 parent fabf210 commit 9bae921

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

tests/conftest.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import gzip
43
import importlib.util
54
import pathlib
65
import tempfile
@@ -627,31 +626,3 @@ def guarded_keychain() -> Iterator[None]:
627626
keychain.KEYCHAIN.clear()
628627
yield
629628
keychain.KEYCHAIN.clear()
630-
631-
632-
@pytest.fixture(scope="session")
633-
def path_debian_ext4_raw(tmp_path_factory: pytest.TempPathFactory) -> Iterator[pathlib.Path]:
634-
"""Fixture that provides a path to a Debian Trixie ext4 raw image.
635-
636-
The image only contains a /bin directory with ~1000 files and an /etc directory with some configuration files.
637-
The rest of the filesystem is not included.
638-
639-
The /bin files are all sparse (filled with zeros).
640-
The files in /etc do contain data.
641-
642-
The source image is stored compressed in the test data directory to save space.
643-
Compressed size is 100kb and decompresses to 5mb.
644-
"""
645-
tmp_path = tmp_path_factory.mktemp("data")
646-
647-
raw_path = tmp_path / "debian-trixie-bin-ext4.raw"
648-
with gzip.open(absolute_path("_data/filesystems/ext4/debian-trixie-bin-ext4.raw.gz"), "rb") as fh:
649-
raw_path.write_bytes(fh.read())
650-
651-
return raw_path
652-
653-
654-
@pytest.fixture
655-
def target_debian_ext4_raw(path_debian_ext4_raw: pathlib.Path) -> Target:
656-
"""Fixture that provides a Target for a Debian Trixie ext4 raw image."""
657-
return Target.open(path_debian_ext4_raw)

tests/tools/test_shell.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import argparse
4+
import gzip
45
import os
56
import pathlib
67
import platform
@@ -13,7 +14,9 @@
1314

1415
import pytest
1516

17+
from dissect.target.containers.raw import RawContainer
1618
from dissect.target.helpers.fsutil import TargetPath, normalize
19+
from dissect.target.target import Target
1720
from dissect.target.tools.shell import (
1821
DebugMode,
1922
ExtendedCmd,
@@ -33,8 +36,6 @@
3336

3437
from pytest_benchmark.fixture import BenchmarkFixture
3538

36-
from dissect.target.target import Target
37-
3839

3940
try:
4041
import pexpect
@@ -617,16 +618,25 @@ def ansi_new_data(cls: pexpect.expect.Expecter, data: bytes) -> int | None:
617618
],
618619
)
619620
def test_benchmark_ls_bin(
620-
target_debian_ext4_raw: Target,
621621
benchmark: BenchmarkFixture,
622622
args: str,
623623
capsys: pytest.CaptureFixture,
624624
) -> None:
625625
"""Benchmark ls command with different parameters with a /bin directory containing ~1000 files."""
626+
with gzip.open(absolute_path("_data/filesystems/ext4/debian-trixie-bin-ext4.raw.gz"), "rb") as fh:
627+
container = RawContainer(fh)
628+
629+
t = Target()
630+
t.disks.add(container)
631+
t.apply()
632+
633+
def run_ls() -> None:
634+
target_cli = TargetCli(t)
635+
target_cli.onecmd(f"ls {args} /bin")
626636

627-
def run_ls() -> None:
628-
target_cli = TargetCli(target_debian_ext4_raw)
629-
target_cli.onecmd(f"ls {args} /bin")
637+
benchmark(run_ls)
630638

631-
benchmark(run_ls)
632-
capsys.readouterr()
639+
out, err = capsys.readouterr()
640+
assert not err
641+
assert "bash" in out
642+
assert "zgrep" in out

0 commit comments

Comments
 (0)