-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_smell_rule_runners.py
78 lines (52 loc) · 2.77 KB
/
test_smell_rule_runners.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
import test_smells.test_method_smells as test_method_smells
import test_smells.test_case_smells as test_case_smells
import test_smells.project_smells as project_smells
def project_rule_runner(python_files):
"""Run rules that need the entire python project to detect a smell"""
project_smell_list = list()
project_smell_list.append(project_smells.LazyTest())
project_smell_list.append(project_smells.EagerTest())
output = list()
for smell in project_smell_list:
result = smell.test_for_smell(python_files)
if result is not None:
output = output + result
return output
def test_case_rule_runner(test_case_ast_pair):
"""Run rules that only need a test case to detect a smell
Accepts a pair with a test case AST and their file of origin, and runs each
of the defined test case rules on the AST."""
test_case_smell_list = list()
test_case_smell_list.append(test_case_smells.GeneralFixture())
test_case_smell_list.append(test_case_smells.ConstructorInitialization())
test_case_smell_list.append(test_case_smells.DefaultTest())
output = list()
for smell in test_case_smell_list:
result = smell.test_for_smell(test_case_ast_pair[0])
if result is not None:
output.append((result,test_case_ast_pair[1]))
return output
def test_method_rule_runner(test_method_ast_pair):
"""Run rules that need the entire test method to detect a smell"""
#all of the smells run in the test_method_rule_runner get added to the
#method_smell_list
method_smell_list = list()
method_smell_list.append(test_method_smells.MagicNumberTest())
method_smell_list.append(test_method_smells.SensitiveEquality())
method_smell_list.append(test_method_smells.ConditionalTestLogic())
method_smell_list.append(test_method_smells.DuplicateAssertTest())
method_smell_list.append(test_method_smells.EmptyTest())
method_smell_list.append(test_method_smells.ExceptionCatchingAndThrowing())
method_smell_list.append(test_method_smells.SkippedTest())
method_smell_list.append(test_method_smells.RedundantPrint())
method_smell_list.append(test_method_smells.RedundantAssert())
method_smell_list.append(test_method_smells.SleepyTest())
method_smell_list.append(test_method_smells.MysteryGuest())
method_smell_list.append(test_method_smells.UnknownTest())
output = list()
for smell in method_smell_list:
result = smell.test_for_smell(test_method_ast_pair[0])
if result is not None:
result_pair = (result, test_method_ast_pair[0].name, test_method_ast_pair[1])
output.append(result_pair)
return output