forked from divyagiridhar/SE-HW-Trial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.py
68 lines (57 loc) · 1.65 KB
/
Utils.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
import math
import re
import sys
import random
from code import Num
help = " \n\
CSV : summarized csv file \n\
(c) 2022 Tim Menzies <[email protected]> BSD-2 license\n\
USAGE: lua seen.lua [OPTIONS]\n\
OPTIONS:\n\
-e --eg start-up example = nothing\n\
-d --dump on test failure, exit with stack dump = false\n\
-f --file file with csv data = ../data/auto93.csv\n\
-h --help show help = false\n\
-n --nums number of nums to keep = 512\n\
-s --seed random number seed = 10019\n\
-S --seperator feild seperator = , "
def message(status):
if status:
return "PASS"
else:
return "FAIL"
def coerce(s):
s = s.strip()
if s.isnumeric():
return int(s)
else:
try:
return float(s)
except ValueError:
if s in ['true', 'TRUE', 'True']:
return True
elif s in ['false', 'FALSE', 'False']:
return False
return re.match("\s*(.*)\s*", s).string
def parse_csv(src, separator):
lines = src.split('\n')
for line in lines:
line_split = line.split(separator)
ans = []
for val in line_split:
val = coerce(val)
ans.append(val)
def copy(t):
if type(t) is not dict:
return t
u = {}
for k, v in t.items():
u[k] = copy(v)
return u
def create_the():
the = {}
tup_list = re.findall(r'[-][\S]+[\s]+[-][-]([\S]+)[^\n]+= ([\S]+)', help)
for k,x in tup_list:
the[k] = coerce(x)
return the
the = create_the()