-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitChain.py
More file actions
51 lines (37 loc) · 1.37 KB
/
initChain.py
File metadata and controls
51 lines (37 loc) · 1.37 KB
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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib
import unittest
import os
class impl:
def initChain(self):
if os.path.exists('./textfile'):
if os.path.getsize('./textfile'):
print("\n Non-empty file!\n")
return 1
else:
entry = {'date':'1/1/2020','partID':'12938329','tested':'fail'}
finprint_input = entry['date']+entry['partID']+entry['tested']
fingerprint = hashlib.md5(finprint_input.encode())
entry.update({'fingerprint':fingerprint.hexdigest()})
txt = open('./textfile','a')
txt.write(str(entry)+'\n')
txt.close()
return entry
if __name__ == '__main__':
x = impl()
x.initChain()
print("?????????")
class Test(unittest.TestCase):
default_value = "{'date': '1/1/200', 'partID': '12938329', 'tested': 'fail', 'fingerprint': 'f957352772e787a9b15a262247d6c641'}\n"
def test_cmp_defaultValue_with_file(self):
if os.path.exists('./textfile'):
with open('./textfile') as f:
first_line = f.readline()
self.assertEqual(first_line, self.default_value)
def test_initChain_return_code(self):
y = impl()
x = y.initChain()
self.assertEqual(x, self.default_value)
# if __name__ == '__main__':
# unittest.main()