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 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_get_potential_hits(self): execution1 = MagicMock() execution1.potential_hits = [{ "rank": 0, "name": "finding1" }, { "rank": 1, "name": "finding2" }] execution2 = MagicMock() execution2.potential_hits = [{"rank": 0, "name": "finding3"}] run = Run([execution1, execution2]) potential_hits = run.get_potential_hits() assert_equals(potential_hits, [{ "rank": 0, "name": "finding1" }, { "rank": 1, "name": "finding2" }, { "rank": 2, "name": "finding3" }])
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 test_get_runtime(self): execution1 = MagicMock() execution1.runtime = 10 execution2 = MagicMock() execution2.runtime = 5 run = Run([execution1, execution2]) runtime = run.get_runtime() assert_equals(runtime, 7.5)
def test_get_findings(self): execution1 = MagicMock() execution1.findings = ["finding1", "finding2"] execution2 = MagicMock() execution2.findings = ["finding3"] run = Run([execution1, execution2]) potential_hits = run.get_findings() assert_equals(potential_hits, ["finding1", "finding2", "finding3"])
def test_get_number_of_findings(self): execution1 = MagicMock() execution1.number_of_findings = 5 execution2 = MagicMock() execution2.number_of_findings = 42 run = Run([execution1, execution2]) number_of_findings = run.get_number_of_findings() assert_equals(number_of_findings, 5 + 42)
def test_get_potential_hits_preserves_rank(self): execution = MagicMock() execution.potential_hits = [{"rank": 42, "name": "f1"}, {"rank": 1337, "name": "f2"}] run = Run([execution]) potential_hits = run.get_potential_hits() assert_equals(potential_hits, [ {"rank": 42, "name": "f1"}, {"rank": 1337, "name": "f2"} ])
def setup(self): self.dataset = "-d-" self.project = create_project("-p-") self.misuse = create_misuse("-m-", project=self.project) self.version = create_version("-v-", project=self.project, misuses=[self.misuse]) self.test_run = Run([MagicMock()]) self.test_run.is_success = lambda: False self.test_run.is_error = lambda: False self.test_run.is_timeout = lambda: False self.test_run.get_runtime = lambda: 0 self.test_run.get_number_of_findings = lambda: 0 self.detector = StubDetector() # type: Detector self.detector.id = "test_detector" self.experiment = MagicMock() # type: Experiment self.experiment.id = "test_experiment" self.experiment.get_run = lambda v: self.test_run self.experiment.detector = self.detector self.uut = PublishFindingsTask(self.experiment, self.dataset, "/sources", "http://dummy.url", "-username-")
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 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 get_run(self, version: ProjectVersion): findings_filter = PotentialHits(version.misuses) return Run([ MineAndDetectExecution(self.detector, version, self.findings_base_path, findings_filter) ])
def get_run(self, version: ProjectVersion): findings_filter = AllFindings(self.limit) return Run([ MineAndDetectExecution(self.detector, version, self.findings_base_path, findings_filter) ])
def get_run(self, version: ProjectVersion): return Run([ self.__create_execution(version, misuse) for misuse in version.misuses if misuse.patterns ])
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()