forked from tzikis/ArduinoMD5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_md5.py
40 lines (29 loc) · 936 Bytes
/
test_md5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import hashlib
import subprocess
import unittest
def md5emb(data):
p = subprocess.run(["Debug/md5emb.exe"], input=data, capture_output=True, text=False)
return p.stdout.strip().decode('ascii')
class Test(unittest.TestCase):
def test_empty(self):
data = b''
h = hashlib.md5()
h.update(data)
self.assertEqual(h.hexdigest(), md5emb(data))
def test_0123456789(self):
data = b'0123456789'
h = hashlib.md5()
h.update(data)
self.assertEqual(h.hexdigest(), md5emb(data))
def test_long_data(self):
data = bytes(range(255)) * 1000
h = hashlib.md5()
h.update(data)
self.assertEqual(h.hexdigest(), md5emb(data))
def test_0_255(self):
data = bytes(range(256))
h = hashlib.md5()
h.update(data)
self.assertEqual(h.hexdigest(), md5emb(data))
if __name__ == '__main__':
unittest.main()