Skip to content

Commit d5d1417

Browse files
Fix tests and get_hash usefulib from #1
1 parent 449b497 commit d5d1417

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

usefulib/_usefulibs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,13 @@ def external_verbose_output(data, path="data.log"):
135135
with open(path, "w") as f:
136136
f.write("# Logged by usefulibs.external_verbose_output()\n\n")
137137
f.write(data)
138+
138139
def get_hash(string):
139140
"""
140-
@MKM12345 - This function takes a string as input, hashes it using the SHA-256 algorithm, and returns the hexadecimal representation of the hash value. Useful for developers that one to store strings without actually having to store them.
141+
@MKM12345 + @hamdivazim - This function takes a string as input, hashes it using the SHA-256 algorithm, and returns the hexadecimal representation of the hash value. Useful for developers that one to store strings without actually having to store them.
141142
"""
143+
144+
if not isinstance(string, str):
145+
raise TypeError("get_hash() cannot get the hash of a non-string.")
146+
142147
return hashlib.sha256(string.encode('utf-8')).hexdigest()

usefulib/tests.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010

1111
import unittest
12-
import _usefulibs
1312
from _usefulibs import *
1413

1514
class TestUsefulibs(unittest.TestCase):
@@ -74,16 +73,11 @@ def test_external_verbose_output(self):
7473

7574
with open(R"usefulib\temp_data\ext_verbose_test.log", "r") as f:
7675
self.assertEqual(f.read(), "# Logged by usefulibs.external_verbose_output()\n\nTest Data\n1 2 3\na b c")
77-
def test_get_hash(self):
78-
""" @MKM12345 """
79-
password = "myPassword123"
80-
password_hash = get_hash(password)
81-
user_input = input("Please enter your password: ")
82-
if get_hash(user_input) == password_hash:
83-
print("Welcome!")
84-
else:
85-
print("Incorrect password")
8676

77+
def test_get_hash(self):
78+
""" @MKM12345 + @hamdivazim """
79+
self.assertEqual(get_hash("abc123"), get_hash("abc123"))
80+
self.assertRaises(TypeError, get_hash, 1)
8781

8882
if __name__ == "__main__":
8983
unittest.main()

0 commit comments

Comments
 (0)