-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_1.py
More file actions
77 lines (60 loc) · 2.33 KB
/
module_1.py
File metadata and controls
77 lines (60 loc) · 2.33 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
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
#!/bin/python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This file looks for the every test pattern and following
# function signature.
# @Author Owen McCormack
# @Date 10/8/16 12:13AM
import sys
import re
import copy
# Nothing
# ->
# (list of tuples of function a signature string mapped to a list of function
# test strings)
#
# Reads code file name from first cli argument
def parse_code():
# Check for only one input file
if((len(sys.argv) < 2) or (len(sys.argv) > 2)):
print("Incorrect number of arguments, the correct format is python3" +
"sit.py then your cpp/cc file.")
# Create tuple for pair list
pair_list = [];
# string to hold function signature
funct_sign = ""
# list for each test string
funct_tests = []
# Save filename for a later import
filename = sys.argv[1]
# Open file from command line for reading to parse
with open(filename,"r") as p_file:
lines = p_file.readlines()
# variable notifies if a test was found
found_test = 0
# iterate over each line for regex
for line in lines:
# Regex to grab each test
test_grab = re.search('>>> test(-[^: ]*)?: [\-\w\. ]* @ .*',line)
inter_grab = re.search('>>> test-interactive',line)
# check regex for a function signature, if none keep moving down
if found_test is 1:
func_grab = re.search("(([a-zA-Z_]*)? *[a-zA-Z0-9_]+" +
" +[a-zA-Z0-9_]+\(.*\))", line)
# if a function signature is found append to pair list and reset
if func_grab is not None:
funct_sign = func_grab.group(1)
found_test = 0
pair = (funct_sign, copy.deepcopy(funct_tests))
pair_list.append(pair)
funct_tests[:] = []
# when a test is found start looking for function signature
if test_grab is not None:
funct_tests.append(test_grab.group(0))
found_test = 1
# grab interactive test seperately
if inter_grab is not None:
funct_tests.append(inter_grab.group(0))
found_test = 1
return (filename, pair_list)