Esempio n. 1
0
class TestAllFindings:
    # noinspection PyAttributeOutsideInit
    def setup(self):
        self.detector = StubDetector()

        self.misuse = create_misuse("-m1-")
        self.misuses = [self.misuse, create_misuse("-m2-")]

        self.uut = AllFindings()

    def test_returns_all_findings(self):
        expected = [
            Finding({
                "rank": "1",
                "file": ""
            }),
            Finding({
                "rank": "2",
                "file": ""
            })
        ]

        actual = self.uut.get_potential_hits(expected)

        assert_equals(expected, actual)

    def test_limits_number_of_findings(self):
        all = [Finding({"rank": "1"}), Finding({"rank": "2"})]
        self.uut.limit = 1

        actual = self.uut.get_potential_hits(all)

        assert_equals(1, len(actual))
Esempio n. 2
0
    def setup(self):
        self.detector = StubDetector()

        self.misuse = create_misuse("-m1-")
        self.misuses = [self.misuse, create_misuse("-m2-")]

        self.uut = AllFindings()
Esempio n. 3
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
    def test_run_outdated(self, read_run_info):
        self.detector.md5 = "-md5-"
        read_run_info.return_value = {"md5": "-old-md5-"}

        uut = DetectorExecutionTestImpl(DetectorMode.detect_only, self.detector, self.version, self.findings_base_path,
                                        AllFindings())

        assert uut.is_outdated()
Esempio n. 5
0
    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 = DetectorExecutionTestImpl(DetectorMode.detect_only, self.detector, self.version,
                                             self.findings_base_path, AllFindings())
    def test_run_outdated(self):
        with mock.patch('tests.data.stub_detector.StubDetector.md5', new_callable=PropertyMock) as mock_md5:
            mock_md5.return_value = "-md5-"
            detector = StubDetector()

            uut = DetectorExecutionTestImpl(DetectorMode.detect_only, detector, self.version, self.findings_base_path,
                                            AllFindings(detector))

            assert uut.is_outdated()
Esempio n. 8
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 setup(self):
        self.temp_dir = mkdtemp(prefix='mubench-run-test_')
        self.findings_path = join(self.temp_dir, "-findings-")

        self.detector = StubDetector()
        self.version = create_version("-v-")
        self.findings_base_path = "-findings-"

        self.uut = DetectorExecutionTestImpl(DetectorMode.detect_only, self.detector, self.version,
                                             self.findings_base_path, AllFindings())
    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 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 = DetectorExecutionTestImpl(DetectorMode.detect_only, self.detector, self.version,
                                             self.findings_base_path, AllFindings(self.detector))
        self.uut.save = MagicMock()
Esempio n. 12
0
    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-")
Esempio n. 13
0
    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)
    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-")
Esempio n. 15
0
 def get_run(self, version: ProjectVersion):
     findings_filter = AllFindings(self.limit)
     return Run([
         MineAndDetectExecution(self.detector, version,
                                self.findings_base_path, findings_filter)
     ])