Skip to content

Commit 6d4e380

Browse files
committed
add unit tests for get_check_sum
1 parent 0affc9c commit 6d4e380

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pyntegrity/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,5 @@ def validate_file_integrity(self):
108108
def get_file_checksum(self):
109109
with self.file.open() as file_to_validate:
110110
file_content = file_to_validate.read()
111-
self.hashlib_obj.update(file_content)
111+
self.hashlib_obj.update(file_content.encode())
112112
return self.hashlib_obj.hexdigest()

tests/test_core.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from unittest import TestCase
33

44
from pyntegrity.core import detect_hash_algo
5-
from pyntegrity.core import get_file_path_from_str
5+
from pyntegrity.core import IntegrityValidator
66
from pyntegrity.core import validate_checksum_str
7+
from pyntegrity.core import get_file_path_from_str
78

89
from pyntegrity.exceptions import FileNotFoundException
910
from pyntegrity.exceptions import ObjectNotAFileException
@@ -62,3 +63,19 @@ def test_get_file_path_from_str_nok_is_not_file(self):
6263
def test_get_file_path_from_str_nok_not_found(self):
6364
with self.assertRaises(FileNotFoundException):
6465
get_file_path_from_str("tests/data/doesnt_exists.csv")
66+
67+
68+
class TestGetFileChecksum(TestCase):
69+
def test_get_file_checksum_text(self):
70+
obj = IntegrityValidator(
71+
str_path="tests/data/test_file.txt",
72+
checksum_str="bbe4f28b27120e0a9611d90d242bc656",
73+
)
74+
self.assertEqual(obj.get_file_checksum(), "bbe4f28b27120e0a9611d90d242bc656")
75+
76+
def test_get_file_checksum_bin(self):
77+
obj = IntegrityValidator(
78+
str_path="tests/data/test_file.dat",
79+
checksum_str="0cb988d042a7f28dd5fe2b55b3f5ac7a",
80+
)
81+
self.assertEqual(obj.get_file_checksum(), "0cb988d042a7f28dd5fe2b55b3f5ac7a")

0 commit comments

Comments
 (0)