Skip to content

Commit

Permalink
refactor in test
Browse files Browse the repository at this point in the history
  • Loading branch information
tarilabs committed Dec 8, 2024
1 parent fcc0a3a commit c30acad
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions tests/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def test_single_file_tar(tmp_path):
with tarfile.open(fileobj=writer, mode="w") as tar:
tar.add(hello_path, arcname=hello_path.name)

checksum_from_disk = get_file_hash(temp_tar_filename)
print(f"to double-check, here is the checksum of .tar re-reading it: {checksum_from_disk}")

checksum = writer.hash_func.hexdigest()
print(f"digest of the tar file: {checksum}")
assert checksum == "08e87bd00a65bebed3cabc34b4cf9a005b3bf31c25078ebd44a30fa1ad0778e3"

checksum2 = get_file_hash(temp_tar_filename)
print(f"to double-check, here is the checksum of .tar.gz re-reading it: {checksum2}")
assert checksum == checksum_from_disk

final_tar_filename = f"{checksum}.tar"
os.rename(temp_tar_filename, sha256_path / final_tar_filename)
Expand All @@ -46,15 +46,21 @@ def test_single_file_gz(tmp_path):
with tarfile.open(fileobj=inner_writer, mode="w") as tar:
tar.add(hello_path, arcname=hello_path.name)

checksum_from_disk = get_file_hash(temp_tar_filename)
print(f"to double-check, here is the checksum of .tar.gz re-reading it: {checksum_from_disk}")

throwaway_tar = tmp_path / "throwaway.tar"
with tarfile.open(throwaway_tar, mode="w") as tar:
tar.add(hello_path, arcname=hello_path.name)
throwaway_checksum_from_disk = get_file_hash(throwaway_tar)
print(f"to double-check, here is the checksum of throwaway_tar .tar re-reading it: {throwaway_checksum_from_disk}")

tar_checksum = inner_writer.hash_func.hexdigest()
print(f"digest of the tar file: {tar_checksum}")
assert tar_checksum == "08e87bd00a65bebed3cabc34b4cf9a005b3bf31c25078ebd44a30fa1ad0778e3"
assert tar_checksum == throwaway_checksum_from_disk
checksum = writer.hash_func.hexdigest()
print(f"digest of the tar.gz file: {checksum}")
assert checksum == "42ebad9bfd3ace9ea36c96957b41a0ab3d8f7b0528700a1a154887c459b33587"

checksum2 = get_file_hash(temp_tar_filename)
print(f"to double-check, here is the checksum of .tar.gz re-reading it: {checksum2}")
assert checksum == checksum_from_disk

final_tar_filename = f"{checksum}.tar.gz"
os.rename(temp_tar_filename, sha256_path / final_tar_filename)
Expand Down

0 comments on commit c30acad

Please sign in to comment.