class TestMineAndDetectExecution:
    # noinspection PyAttributeOutsideInit
    def setup(self):
        self.version = create_version("-version-", project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_base_path = "-findings-"

        self.logger = logging.getLogger("test")

        self.uut = MineAndDetectExecution(self.detector, self.version, self.findings_base_path,
                                          AllFindings(self.detector))
        self.uut.save = MagicMock

    def test_execute(self, get_dependencies_classpath_mock, shell_mock):
        jar = self.detector.jar_path
        findings_path = join("-findings-", "mine_and_detect", "StubDetector", "-project-", "-version-")
        target = join(findings_path, "findings.yml")
        run_info = join(findings_path, "run.yml")
        compiles_path = join("-compiles-", "-project-", "-version-")
        target_src_path = join(compiles_path, "original-src")
        target_classpath = join(compiles_path, "original-classes")
        dependencies_classpath = "-dependencies-classpath-"
        get_dependencies_classpath_mock.return_value = dependencies_classpath

        self.uut.execute("-compiles-", 42, self.logger)

        shell_mock.exec.assert_called_with('java -jar "{}" '.format(jar) +
                                           'target "{}" '.format(target) +
                                           'run_info "{}" '.format(run_info) +
                                           'detector_mode "0" ' +
                                           'target_src_path "{}" '.format(target_src_path) +
                                           'target_classpath "{}" '.format(target_classpath) +
                                           'dep_classpath "{}"'.format(dependencies_classpath),
                                           logger=self.logger,
                                           timeout=42)
Beispiel #2
0
    def test_not_run(self):
        execution = MineAndDetectExecution(self.detector, self.version, self.findings_path, AllFindings(self.detector))
        run = Run([execution])
        execution.result = None

        assert not run.is_success()
        assert not run.is_failure()
    def test_load(self, read_run_info):
        read_run_info.return_value = {"result": "success", "runtime": "23.42", "message": "-arbitrary text-"}

        execution = MineAndDetectExecution(self.detector, self.version, self.findings_path, AllFindings())

        assert execution.is_success()
        assert_equals(execution.runtime, "23.42")
        assert_equals(execution.message, "-arbitrary text-")
    def test_load(self):
        self.write_run_file({"result": "success", "runtime": "23.42", "message": "-arbitrary text-"})

        execution = MineAndDetectExecution(self.detector, self.version, self.findings_path, AllFindings(self.detector))

        assert execution.is_success()
        assert_equals(execution.runtime, "23.42")
        assert_equals(execution.message, "-arbitrary text-")
    def test_success(self):
        execution = MineAndDetectExecution(self.detector, self.version,
                                           self.findings_path,
                                           AllFindings(self.detector))
        run = Run([execution])
        execution.result = Result.success

        assert run.is_success()
    def setup(self):
        self.version = create_version("-version-", project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_base_path = "-findings-"

        self.logger = logging.getLogger("test")

        self.uut = MineAndDetectExecution(self.detector, self.version, self.findings_base_path,
                                          AllFindings())
Beispiel #7
0
    def setup(self):
        self.version = create_version("-version-",
                                      project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_base_path = "-findings-"

        self.logger = logging.getLogger("test")

        self.__orig_shell_exec = Shell.exec
        Shell.exec = MagicMock()

        self.uut = MineAndDetectExecution(self.detector, self.version,
                                          self.findings_base_path,
                                          AllFindings(self.detector))
        self.uut.save = MagicMock
Beispiel #8
0
    def setup(self):
        self.temp_dir = mkdtemp(prefix='mubench-detect-test_')
        self.compiles_path = join(self.temp_dir, "checkout")
        self.findings_path = join(self.temp_dir, "findings")

        os.chdir(self.temp_dir)

        self.project = create_project("-project-")
        self.version = create_version("-version-", project=self.project)
        self.detector = StubDetector()
        self.test_run_execution = MineAndDetectExecution(
            self.detector, self.version, self.findings_path,
            AllFindings(self.detector))
        self.test_run = Run([self.test_run_execution])
        self.test_run.execute = MagicMock(
            return_value="test execution successful")
        self.experiment = Experiment(Experiment.TOP_FINDINGS, self.detector,
                                     self.findings_path)
        self.experiment.get_run = lambda v: self.test_run
        self.uut = Detect(self.compiles_path, self.experiment, None, False)

        self.last_invoke = None

        # mock command-line invocation
        def mock_invoke_detector(detect, absolute_misuse_detector_path: str,
                                 detector_args: str):
            self.last_invoke = absolute_misuse_detector_path, detector_args
Beispiel #9
0
    def test_not_run(self, result_mock):
        execution = MineAndDetectExecution(self.detector, self.version, self.findings_path, FindingsFilter())
        result_mock.return_value = None
        run = Run([execution])

        assert not run.is_success()
        assert not run.is_failure()
    def get_run(self, version: ProjectVersion) -> Run:
        if self.id == Experiment.PROVIDED_PATTERNS:
            executions = [
                DetectOnlyExecution(self.detector, version, misuse, self.findings_base_path,
                                    PotentialHits(self.detector, [misuse])) for
                misuse in version.misuses if misuse.patterns]
        elif self.id == Experiment.TOP_FINDINGS:
            executions = [
                MineAndDetectExecution(self.detector, version, self.findings_base_path,
                                       AllFindings(self.detector, self.limit))]
        elif self.id == Experiment.BENCHMARK:
            executions = [MineAndDetectExecution(self.detector, version, self.findings_base_path,
                                                 PotentialHits(self.detector, version.misuses))]
        else:
            executions = []

        return Run(executions)
class TestMineAndDetectExecution:
    # noinspection PyAttributeOutsideInit
    def setup(self):
        self.version = create_version("-version-", project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_base_path = "-findings-"

        self.logger = logging.getLogger("test")

        self.uut = MineAndDetectExecution(self.detector, self.version, self.findings_base_path,
                                          AllFindings())

    # noinspection PyUnusedLocal
    # patch prevents write to filesystem
    def test_execute(self, get_dependencies_classpath_mock, write_yaml_mock):
        findings_path = join("-findings-", "mine_and_detect", "StubDetector", "-project-", "-version-")
        target = join(findings_path, "findings.yml")
        run_info = join(findings_path, "run.yml")
        compiles_path = join("-compiles-", "-project-", "-version-")
        target_src_path = join(compiles_path, "original-src")
        target_classpath = join(compiles_path, "original-classes")
        original_classpath = join(compiles_path, "original-classes.jar")
        dependencies_classpath = "-dependencies-classpath-"
        get_dependencies_classpath_mock.return_value = dependencies_classpath

        self.uut.execute("-compiles-", 42, self.logger)

        self.detector.runner_interface.execute.assert_called_with(
            self.version,
            {
                'target': target,
                'run_info': run_info,
                'detector_mode': "0",
                'target_src_path': target_src_path,
                'target_classpath': target_classpath,
                'dep_classpath': '{}:{}'.format(dependencies_classpath, original_classpath)
            },
            42, self.logger)
Beispiel #12
0
 def get_run(self, version: ProjectVersion):
     findings_filter = PotentialHits(version.misuses)
     return Run([
         MineAndDetectExecution(self.detector, version,
                                self.findings_base_path, findings_filter)
     ])
Beispiel #13
0
 def get_run(self, version: ProjectVersion):
     findings_filter = AllFindings(self.limit)
     return Run([
         MineAndDetectExecution(self.detector, version,
                                self.findings_base_path, findings_filter)
     ])
Beispiel #14
0
    def test_success(self, result_mock):
        execution = MineAndDetectExecution(self.detector, self.version, self.findings_path, FindingsFilter())
        result_mock.return_value = Result.success
        run = Run([execution])

        assert run.is_success()