From 4ba38b0d27122a09fb566a6be2e39e25154636a6 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Thu, 7 Mar 2024 13:11:39 +0000 Subject: [PATCH] :white_check_mark: Add initial tests for shui.functions.extract_tarball --- tests/commands/test_all.py | 6 +++-- tests/fixtures/example.tgz.sha512 | 1 + tests/functions/test_install.py | 38 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/example.tgz.sha512 create mode 100644 tests/functions/test_install.py diff --git a/tests/commands/test_all.py b/tests/commands/test_all.py index 7949335..686204c 100644 --- a/tests/commands/test_all.py +++ b/tests/commands/test_all.py @@ -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( diff --git a/tests/fixtures/example.tgz.sha512 b/tests/fixtures/example.tgz.sha512 new file mode 100644 index 0000000..36f08ca --- /dev/null +++ b/tests/fixtures/example.tgz.sha512 @@ -0,0 +1 @@ +4c63792055a083e8c770370f22240853dc64da96e3200c7aa2710607b841bb0972c29eece43b068dd11c4f77719427b6c48df27e6e389efd664fb3e9b9743f9f diff --git a/tests/functions/test_install.py b/tests/functions/test_install.py new file mode 100644 index 0000000..70be9d7 --- /dev/null +++ b/tests/functions/test_install.py @@ -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"