예제 #1
0
파일: test.py 프로젝트: rotba/patcher
 def test_patch_tescases_not_compiling_testcases(self):
     git_url = 'https://github.com/rotba/MavenProj'
     commit_h = 'a71cdc161b0d87e7ee808f5078ed5fefab758773'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == commit_h
     ][0]
     parent = commit.parents[0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_1')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_not_compiling_testcase = [
         t for t in commit_testcases if 'MainTest#gooTest' in t.mvn_name
     ][0]
     commit_new_testcases = get_delta_testcases(commit_testcases)
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None)
     patcher.patch()
     not_compiling_testcases = patcher.get_all_unpatched()
     self.assertTrue(
         expected_not_compiling_testcase in not_compiling_testcases,
         "'MainTest#gooTest should have been picked as for compilation error"
     )
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     parent_tests = mvn_repo.get_tests(module_path)
     parent_testcases = mvn.get_testcases(parent_tests)
     self.assertTrue(len(parent_testcases) > 0, 'Build probably failed')
     self.assertTrue(
         not expected_not_compiling_testcase in parent_testcases,
         expected_not_compiling_testcase.mvn_name +
         ' should have been unpatched')
예제 #2
0
 def get_relevant_tests(self, repo):
     test_files = map(
         lambda x:
         (os.path.normpath(os.path.join(repo.working_dir, x)), ".".join([
             "org"
         ] + os.path.normpath(x.lower()).replace(".java", "").replace(
             os.path.sep, ".").lower().split('org.')[1].split('.')[:-1])),
         filter(lambda x: "test" in x and x.endswith("java"),
                repo.git.ls_files().split()))
     relevant_tests_packages = set(list(zip(*test_files))[1]).intersection(
         self.get_diffed_packages())
     self.tests.extend(
         list(
             map(
                 lambda x: x[0],
                 filter(lambda x: x[1] in relevant_tests_packages,
                        test_files))))
     commit_tests_object = list(
         map(
             lambda t_path: TestObjects.TestClass(
                 t_path, self.fix_commit.repo.working_dir),
             filter(lambda t: os.path.exists(os.path.realpath(t)),
                    self.tests)))
     commit_testcases = mvn.get_testcases(commit_tests_object)
     return commit_testcases
예제 #3
0
파일: test.py 프로젝트: rotba/patcher
 def test_patch_tescases(self):
     git_url = 'https://github.com/rotba/MavenProj'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == 'e00037324027af30134ee1554b93f5969f8f100e'
     ][0]
     parent = commit.parents[0]
     module_path = os.getcwd() + r'\tested_project\MavenProj\sub_mod_1'
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_1')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_delta_testcase = [
         t for t in commit_testcases if 'p_1.AmitTest#hoo' in t.mvn_name
     ][0]
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None)
     patcher.patch()
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     parent_tests = mvn_repo.get_tests(module_path)
     parent_testcases = mvn.get_testcases(parent_tests)
     self.assertTrue(
         expected_delta_testcase in parent_testcases,
         "'p_1.AmitTest should have been patchd on the parent commit and exist"
     )
예제 #4
0
파일: test.py 프로젝트: rotba/patcher
 def test_patch_tescases_not_compiling_testcases_exclusive_patching(self):
     git_url = 'https://github.com/rotba/MavenProj'
     commit_h = 'e4d2bb8efdfa576632b99d0e91b35cf0262e70be'
     git_dir = self.setUpProj(git_url=git_url)
     git_repo = git.Repo(git_dir)
     mvn_repo = MVN_Repo(git_dir)
     branch_inspected = 'origin/master'
     hey = list(git_repo.iter_commits(branch_inspected))
     commit = [
         c for c in list(git_repo.iter_commits(branch_inspected))
         if c.hexsha == commit_h
     ][0]
     parent = commit.parents[0]
     module_path = os.path.join(mvn_repo.repo_dir, 'sub_mod_2')
     prepare_project_repo_for_testing(commit, module_path, git_repo)
     os.system(
         'mvn clean test surefire:test -DfailIfNoTests=false -Dmaven.test.failure.ignore=true -f '
         + module_path)
     commit_tests = mvn_repo.get_tests(module_path)
     commit_testcases = mvn.get_testcases(commit_tests)
     expected_not_compiling_delta_testcase = \
      [t for t in commit_testcases if 'p_1.AssafTest#notCompTest' in t.mvn_name][0]
     expected_compiling_delta_testcase = [
         t for t in commit_testcases
         if 'p_1.AssafTest#compTest' in t.mvn_name
     ][0]
     prepare_project_repo_for_testing(parent, module_path, git_repo)
     delta_testcases = get_delta_testcases(commit_testcases)
     patcher = TestcasePatcher(testcases=commit_testcases,
                               proj_dir=git_dir,
                               commit_fix=commit,
                               commit_bug=parent,
                               module_path=module_path,
                               generated_tests_diff=[],
                               gen_commit=None).patch()
     unpatched = patcher.get_all_unpatched()
     patched = patcher.get_patched()
     self.assertTrue(
         expected_not_compiling_delta_testcase in unpatched,
         "'p_1.AssafTest#notCompTest' should have been picked for compilation error"
     )
     self.assertTrue(
         not expected_not_compiling_delta_testcase in patched,
         "'p_1.AssafTest#notCompTest' should have not benn patched")
     self.assertTrue(expected_compiling_delta_testcase in patched,
                     "'p_1.AssafTest#compTest' should have been patched")
     self.assertTrue(not expected_compiling_delta_testcase in unpatched,
                     "'p_1.AssafTest#compTest' should have been patched")
예제 #5
0
 def test_apply_tika_56(self):
     testcase_dir = os.path.join(test_dir, 'test_apply_tika_56')
     if not os.path.isdir(os.path.join(test_dir, 'test_apply_tika_56')):
         os.mkdir(testcase_dir)
     shutil.copytree(TIKA_56_DATA_DIR, TIKA_DB_DIR)
     applier = Applier.Applier('https://github.com/apache/tika', testcase_dir)
     mvn_repo = MavenRepo.Repo(applier.proj_dir)
     testcase_id_suffix = 'tika\\src\\test\\java\\org\\apache\\tika\\mime\\TestMimeTypes.java#TestMimeTypes#None_testCaseSensitivity()'
     bugs = applier.get_bugs('TIKA-56', 'b12c01d9b56053554cec501aab0530f7f4352daf')
     bug = [b for b in bugs if b.bugged_testcase.id.endswith(testcase_id_suffix)][0]
     applier.apply(bug)
     os.system('mvn test -f '+applier.proj_dir+' -fn')
     testclasses = mvn_repo.get_tests(applier.proj_dir)
     testcases = mvn.get_testcases(testclasses)
     testcase = [t for t in testcases if t.id.endswith('TestMimeTypes#None_testCaseSensitivity()')][0]
     testcase.parent.look_for_report()
     self.assertTrue(testcase.failed)
예제 #6
0
 def test_apply_generated_test_tika_56(self):
     testcase_dir = os.path.join(test_dir, 'test_apply_generated_test_tika_56')
     if not os.path.isdir(os.path.join(test_dir, 'test_apply_generated_test_tika_56')):
         os.mkdir(testcase_dir)
     shutil.copytree(TIKA_56_GEN_DATA_DIR, TIKA_DB_DIR)
     applier = Applier.Applier('https://github.com/apache/tika', testcase_dir)
     mvn_repo = MavenRepo.Repo(applier.proj_dir)
     testcase_id_infix = 'tika\\src\\test\\java\\org\\apache\\tika\\mime\\MimeTypes_ESTest.java'
     bugs = applier.get_bugs('TIKA-56', 'b12c01d9b56053554cec501aab0530f7f4352daf')
     valid_bugs = filter(lambda b: b.valid,bugs)
     bug = valid_bugs[0]
     applier.apply(bug)
     os.system('mvn test -f '+applier.proj_dir+' -fn')
     testclasses = mvn_repo.get_tests(applier.proj_dir)
     testcases = mvn.get_testcases(testclasses)
     testcases = [t for t in testcases if t in map(lambda x: x.bugged_testcase, valid_bugs)]
     for testcase in testcases:
         testcase.parent.look_for_report()
         self.assertTrue(testcase.failed)