-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_diff_parser.py
More file actions
executable file
·61 lines (57 loc) · 1.97 KB
/
Copy pathgit_diff_parser.py
File metadata and controls
executable file
·61 lines (57 loc) · 1.97 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
#! /usr/bin/python
import sys
import re
def main(argv):
# Take the first input
diff = argv[0]
# Split it into lines
diff_list = diff.splitlines()
files_and_functions = {}
file_name = ""
for line in diff_list:
# Check for any renames
line_rename_from = ""
rename_from = "rename from (.*)\.py"
rename_to = "rename to (.*)\.py"
file_regexp = "--- a/(.*)\.py"
function_regexp = "@@.*@@ def ([\\w|\\d|_]*)"
new_function = "\\+\\s+def\\s+(.*):"
# Check line if it is an addition to the file take note of the file name
match = re.search(rename_from, line)
if match is not None:
line_rename_from = match.group(1)
match = re.search(rename_to, line)
if match is not None:
if not files_and_functions.has_key(line_rename_from):
files_and_fuctions[line_rename_from] = {}
files_and_functions[line_rename_from]["rename"] = match.group(1)
match = re.search(file_regexp, line)
if match is not None:
file_name = match.group(1)
if not files_and_functions.has_key(file_name):
files_and_functions[file_name] = {}
match = re.search(function_regexp, line)
if match is not None:
if not files_and_functions.has_key(file_name):
files_and_functions[file_name] = {}
files_and_functions[file_name][match.group(1)] = ""
match = re.search(new_function, line)
if match is not None:
if not files_and_functions.has_key(file_name):
files_and_functions[file_name] = {}
files_and_functions[file_name][match.group(1)] = ""
# Check line if it is an addition to a function add the function name to a dictionary {"filename" : {"function_name" : "" }}
# Collate functions and filename togeather
collated = collate(files_and_functions)
# Print/return list of tests to run
print collated
def collate(dictionary):
keys = dictionary.keys()
collated = []
for key in keys:
functions = dictionary[key].keys()
for function in functions:
collated.append(key+"Tests.test_"+function)
return collated
if __name__ == "__main__":
main(sys.argv[1:])