-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tahiat/dev
Build specimin command and execution.
- Loading branch information
Showing
9 changed files
with
425 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Python Test | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
python-script-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout project sources | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
- name: Run tests | ||
run: python TestMain.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,9 @@ | |
ISSUES | ||
|
||
# macOS specific file | ||
.DS_Store | ||
.DS_Store | ||
|
||
__pycache__/ | ||
|
||
#Ignore compiled class file | ||
*.class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from enum import Enum | ||
|
||
class JsonKeys(Enum): | ||
ISSUE_ID = 'issue_id' | ||
URL = 'url' | ||
BRANCH = 'branch' | ||
COMMIT_HASH = 'commit_hash' | ||
PROJECT_NAME = 'project_name' | ||
BUILD_COMMAND = 'build_command' | ||
ROOT_DIR = 'root_dir' | ||
PACKAGE = 'package' | ||
TARGETS = 'targets' | ||
METHOD_NAME = 'method' | ||
FILE_NAME = 'file' | ||
CF_Version = 'cf_version' | ||
JAVA_VERSION = 'java_version' | ||
NOTE = 'note' | ||
SKIP = 'skip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import unittest | ||
import main | ||
import shutil | ||
import os | ||
from Keyvalue import JsonKeys | ||
|
||
class TestMain(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
# cloning the specimin | ||
main.clone_repository('https://github.com/kelloggm/specimin.git', 'resources') | ||
cls.json_data = main.read_json_from_file('resources/test_data.json')[0] | ||
cls.specimin_dir = "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 = '[email protected]:codespecs/daikon.git' | ||
self.assertEqual(main.get_repository_name(url), 'daikon') | ||
|
||
url = '[email protected]:kelloggm/specimin.git' | ||
self.assertEqual(main.get_repository_name(url), 'specimin') | ||
|
||
url = '[email protected]:typetools/checker-framework.git' | ||
self.assertEqual(main.get_repository_name(url), 'checker-framework') | ||
|
||
url = '[email protected]: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 = '[email protected]: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' | ||
package = 'org.apache.cassandra.index.sasi.conf' | ||
targets = [{ | ||
"method": "getMode(ColumnMetadata, Map<String, String>)", | ||
"file": "IndexMode.java" | ||
}] | ||
specimin_dir = 'user/specimin' | ||
target_dir = 'user/ISSUES/cf-6077' | ||
command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, 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/' | ||
package = 'com.fillmore_labs.kafka.sensors.serde.confluent.interop' | ||
targets = [{ | ||
"method": "transform(String, byte[])", | ||
"file": "Avro2Confluent.java" | ||
}] | ||
specimin_dir = 'user/specimin' | ||
target_dir = 'user/ISSUES/cf-6019' | ||
command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, 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('resources/cf-1291/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}")) | ||
|
||
command = main.build_specimin_command(project_name, f"resources/{issue_name}", self.specimin_dir, self.json_data[JsonKeys.ROOT_DIR.value], self.json_data[JsonKeys.PACKAGE.value], self.json_data[JsonKeys.TARGETS.value]) | ||
print(command) | ||
result = main.run_specimin(command, self.specimin_dir) | ||
self.assertTrue(result) | ||
|
||
def test_run_specimin(self): | ||
proj_name = 'test_proj' | ||
root = '' | ||
package = 'com.example' | ||
targets = [{ | ||
"method": "bar()", | ||
"file": "Simple.java" | ||
}] | ||
specimin_dir = 'resources/specimin' | ||
target_dir = 'resources/onefilesimple' | ||
|
||
command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, targets) | ||
result = main.run_specimin(command, 'resources/specimin') | ||
self.assertTrue(result) | ||
|
||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.