Skip to content

Commit

Permalink
✅ Add initial tests for shui.functions.extract_tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Mar 7, 2024
1 parent 613a7f9 commit 4ba38b0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/commands/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def spark_example_tgz(fixtures_directory: Path) -> bytes:


@pytest.fixture
def spark_example_tgz_hash() -> str:
return "4c63792055a083e8c770370f22240853dc64da96e3200c7aa2710607b841bb0972c29eece43b068dd11c4f77719427b6c48df27e6e389efd664fb3e9b9743f9f\n"
def spark_example_tgz_hash(fixtures_directory: Path) -> str:
with open(fixtures_directory / "example.tgz.sha512", "r") as f_in:
content = f_in.readlines()
return "\n".join(content)


def test_install_fail(
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/example.tgz.sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4c63792055a083e8c770370f22240853dc64da96e3200c7aa2710607b841bb0972c29eece43b068dd11c4f77719427b6c48df27e6e389efd664fb3e9b9743f9f
38 changes: 38 additions & 0 deletions tests/functions/test_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from pathlib3x import Path

from shui.classes import FileInfo, FileWithHash
from shui.functions import extract_tarball


@pytest.fixture
def fixtures_directory() -> Path:
return Path(__file__).parent.parent.resolve() / "fixtures"


@pytest.fixture
def filewithhash(testfile: FileInfo, testhashfile: FileInfo) -> FileWithHash:
return FileWithHash(testfile, testhashfile)


@pytest.fixture
def spark_example_tgz(fixtures_directory: Path) -> bytes:
return FileInfo(
"https://example.com/example.tgz", fixtures_directory / "example.tgz"
)


@pytest.fixture
def spark_example_tgz_hash(fixtures_directory: Path) -> FileInfo:
return FileInfo(
"https://example.com/example.tgz.sha512",
fixtures_directory / "example.tgz.sha512",
)


def test_extract_tarball(
spark_example_tgz: FileInfo, spark_example_tgz_hash: FileInfo, tmp_path: Path
) -> None:
file_with_hash = FileWithHash(spark_example_tgz, spark_example_tgz_hash)
install_dir = Path(tmp_path) / "install"
assert extract_tarball(file_with_hash.file, install_dir) == install_dir / "spark"

0 comments on commit 4ba38b0

Please sign in to comment.