-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit_tests.py
103 lines (91 loc) · 2.84 KB
/
unit_tests.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
@app.route('/test/unit/render_msg')
def test_render_msg():
msg = {'msg': 'AWAKEN a bit ago, RECAP PLAY GAME vampire survivors',
'Date': 'Tue Feb 14 11:13:50 PST 2023'}
for i in range(1000):
DISCUSSION_RENDER.msg(msg)
return 'DONE'
@app.route('/test/unit/date_cmd')
def test_date_cmd():
for i in range(10000):
DATE.cmd("-d", 'Tue Feb 14 11:13:50 PST 2023', "+%T")
return 'DONE'
@app.route('/test/unit/render_every_note')
def test_render_every_note():
for note in FLAT.list():
DISCUSSION_RENDER.MAIN(note)
return 'DONE'
@app.route('/test/unit/pagesize_every_note')
def test_pagesize_every_note():
size = 0
for note in FLAT.list():
size += len(DISCUSSION_RENDER.MAIN(note))
return 'rendered size: ' + str(size)
def eqch(*P):
g = [] # pass
b = [] # failed
for i, p in enumerate(P):
assert len(p) in {2, 3}, f"{p}, {len(p)}"
if len(p) == 2:
A, B = p
v = f"#{i}: '{repr(A)}' == '{repr(B)}'"
elif len(p) == 3:
A, B, msg = p
v = f"#{i}: '{repr(A)}' == '{repr(B)}', {msg}"
try:
if A == B:
g.append(v)
else:
b.append(v)
except Exception as e:
raise Exception(v) from e
return \
"<p>FAIL</p>" + "<pre>" + "<br>".join(b) + "</pre>" + \
"<p>PASS</p>" + "<pre>" + "<br>".join(g) + "</pre>"
@app.route('/test/unit/tag_parse')
def test_tag_parse():
return eqch(
[TAG.parse('HELLO WORLD'),
[{'tag': 'HELLO'}, ' ', {'tag': 'WORLD'}]],
[TAG.parse('INPUT generators vs stackless coroutines: QUOTE testing I am testing 1 2 3'),
[{"tag": "INPUT"},
" generators vs stackless coroutines: ",
{"tag": "QUOTE"},
" testing I am testing 1 2 3"],
"capital 'I' should not disrupt parsing non-tags"]
)
def total_size(o):
# from: https://code.activestate.com/recipes/577504/
from itertools import chain
dict_handler = lambda d: chain.from_iterable(d.items())
handlers = {dict: dict_handler, tuple: iter, list: iter, set: iter, frozenset: iter}
seen = set() # track which object id's have already been seen
def sizeof(o):
if id(o) in seen: # do not double count the same object
return 0
seen.add(id(o))
s = sys.getsizeof(o)
if type(o) in handlers:
try:
s += sum(map(sizeof, handlers[type(o)](o))) # get size of the objects it refers to as well
except:
import pdb
pdb.set_trace()
return s
return sizeof(o)
@app.route('/test/unit/parse_all_memory')
def test_parse_all_memory():
acc = dict()
for note in FLAT.list():
acc[note] = REWRITE.note(note)
return str(total_size(acc))
@app.route('/test/unit/rewrite_all')
def test_rewrite_all():
for note in FLAT.list():
REWRITE.note(note)
return 'Done'
@app.route('/test/unit/parse_all')
def test_parse_all():
for note in FLAT.list():
PARSER.parse_file(FLAT.to_path(note))
return 'Done'