-
Notifications
You must be signed in to change notification settings - Fork 6
/
TestMain.py
124 lines (102 loc) · 5.31 KB
/
TestMain.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import unittest
import main
import shutil
import os
from Keyvalue import JsonKeys
class TestMain(unittest.TestCase):
@classmethod
def setUpClass(cls):
#TODO: previously used cf-1291 (index 0) fails when absolute path of the target is used. Will investigate it later.
#Currently using cf-6060
cls.json_data = main.read_json_from_file('resources/test_data.json')[3]
sp_env_var = main.get_specimin_env_var()
if sp_env_var is not None and os.path.exists(sp_env_var) and os.path.isdir(sp_env_var):
print("Local Specimin copy is being used")
cls.specimin_dir = sp_env_var
else:
print("Local Specimin not found. Cloning a Specimin copy")
main.clone_repository('https://github.com/kelloggm/specimin.git', 'resources')
cls.specimin_dir = os.path.abspath("resources/specimin")
@classmethod
def tearDownClass(cls):
# deleting specimin from resources
try:
shutil.rmtree('resources/specimin')
except Exception as e:
print(f"Error occurred {e}")
# removing any issue project cloned in resources
for root, dirs, files in os.walk('resources', topdown=False):
for dir_name in dirs:
if 'cf-' in dir_name:
dir_path = os.path.join(root, dir_name)
shutil.rmtree(dir_path)
print(f"Removed directory: {dir_path}")
def test_get_repository_name(self):
url = 'git@github.com:codespecs/daikon.git'
self.assertEqual(main.get_repository_name(url), 'daikon')
url = 'git@github.com:kelloggm/specimin.git'
self.assertEqual(main.get_repository_name(url), 'specimin')
url = 'git@github.com:typetools/checker-framework.git'
self.assertEqual(main.get_repository_name(url), 'checker-framework')
url = 'git@github.com:awslabs/aws-kms-compliance-checker.git'
self.assertEqual(main.get_repository_name(url), 'aws-kms-compliance-checker')
url = 'https://github.com/kelloggm/specimin.git'
self.assertEqual(main.get_repository_name(url), 'specimin')
url = 'git@github.com:awslabs/aws-kms-compliance-checker.git'
self.assertNotEqual(main.get_repository_name(url), 'aws-km-compliance-checker')
def test_build_specimin_command(self):
proj_name = 'cassandra'
root = 'src/java'
targets = [{
"method": "getMode(ColumnMetadata, Map<String, String>)",
"file": "IndexMode.java",
"package": 'org.apache.cassandra.index.sasi.conf'
}]
target_dir = '/user/ISSUES/cf-6077'
command = main.build_specimin_command(proj_name, target_dir, root, targets)
target_command = ''
with open('resources/specimin_command_cf-6077.txt','r') as file:
target_command = file.read()
self.assertEqual(command, target_command)
# not executing since this crashes specimin
proj_name = 'kafka-sensors'
root = 'src/main/java/'
targets = [{
"method": "transform(String, byte[])",
"file": "Avro2Confluent.java",
"package": 'com.fillmore_labs.kafka.sensors.serde.confluent.interop'
}]
target_dir = '/user/ISSUES/cf-6019'
command = main.build_specimin_command(proj_name, target_dir, root, targets)
with open('resources/specimin_command_cf-6019.txt','r') as file:
target_command = file.read()
self.assertEqual(command, target_command)
#not executing since it crashes specimin.
# make
issue_name = self.json_data[JsonKeys.ISSUE_ID.value]
main.create_issue_directory('resources', issue_name)
self.assertTrue(os.path.exists(f'resources/{issue_name}/input'))
main.clone_repository(self.json_data[JsonKeys.URL.value], f"resources/{issue_name}/input")
project_name = main.get_repository_name(self.json_data[JsonKeys.URL.value])
self.assertTrue(main.checkout_commit(self.json_data[JsonKeys.COMMIT_HASH.value],f"resources/{issue_name}/input/{project_name}"))
self.assertTrue(main.is_git_directory(f"resources/{issue_name}/input/{project_name}"))
main.change_branch(self.json_data[JsonKeys.BRANCH.value], f"resources/{issue_name}/input/{project_name}")
#build_specimin_command accept absolute path of the root directory.
command = main.build_specimin_command(project_name, os.path.abspath(f"resources/{issue_name}"), self.json_data[JsonKeys.ROOT_DIR.value], self.json_data[JsonKeys.TARGETS.value])
print(command)
result = main.run_specimin(issue_name, command, self.specimin_dir)
self.assertEqual(result.status, "PASS")
def test_run_specimin(self):
proj_name = 'test_proj'
root = ''
targets = [{
"method": "bar()",
"file": "Simple.java",
"package": "com.example"
}]
target_dir = 'resources/onefilesimple'
command = main.build_specimin_command(proj_name, os.path.abspath(target_dir), root, targets)
result = main.run_specimin(proj_name, command, self.specimin_dir)
self.assertEqual(result.status, "PASS")
if __name__ == '__main__':
unittest.main()