Skip to content

Commit 26a029c

Browse files
committed
simplify test
1 parent f631476 commit 26a029c

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

Lib/test/test_hashlib.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -216,24 +216,6 @@ def shake_constructors(self):
216216
def is_fips_mode(self):
217217
return get_fips_mode()
218218

219-
def match_digest(self, h1, h2, *, shake_size=16):
220-
self.assertIs(type(h1), type(h2))
221-
self.assertEqual(h1.name, h2.name)
222-
223-
if h1.name in self.shakes:
224-
d1, h1 = h1.digest(shake_size), h1.hexdigest(shake_size)
225-
d2, h2 = h2.digest(shake_size), h2.hexdigest(shake_size)
226-
else:
227-
d1, h1 = h1.digest(), h1.hexdigest()
228-
d2, h2 = h2.digest(), h2.hexdigest()
229-
230-
self.assertIsInstance(d1, bytes)
231-
self.assertIsInstance(h1, str)
232-
self.assertEqual(d1.hex(), h1)
233-
234-
self.assertEqual(d1, d2)
235-
self.assertEqual(h1, h2)
236-
237219
def test_hash_array(self):
238220
a = array.array("b", range(10))
239221
for cons in self.hash_constructors:
@@ -391,11 +373,13 @@ def test_get_builtin_constructor(self):
391373

392374
def test_copy(self):
393375
for cons in self.hash_constructors:
394-
h1 = cons(usedforsecurity=False)
395-
h1.update(os.urandom(16))
376+
h1 = cons(os.urandom(16), usedforsecurity=False)
396377
h2 = h1.copy()
397378
self.assertIs(type(h1), type(h2))
398-
self.match_digest(h1, h2)
379+
self.assertEqual(h1.name, h2.name)
380+
size = (16,) if h1.name in self.shakes else ()
381+
self.assertEqual(h1.digest(*size), h2.digest(*size))
382+
self.assertEqual(h1.hexdigest(*size), h2.hexdigest(*size))
399383

400384
def test_hexdigest(self):
401385
for cons in self.hash_constructors:

0 commit comments

Comments
 (0)