示例#1
0
    def setup(self):
        self.detector = StubDetector()

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

        self.uut = AllFindings()
示例#2
0
    def setup(self):
        self.temp_dir = mkdtemp(prefix='mubench-detect-test_')
        self.findings_path = join(self.temp_dir, "findings")

        self.detector = StubDetector()

        self.uut = LoadDetectorTask("", "", "", [])
示例#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 setup(self):
        self.project = create_project("-p-")
        self.misuse = create_misuse("-m-", project=self.project)
        self.version = create_version("-v-", project=self.project, misuses=[self.misuse],
                                      meta={"build": {"src": "", "classes": ""}})
        self.version_compile = self.version.get_compile("/sources")

        self.test_detector_execution = MagicMock()  # type: DetectorRun
        self.test_detector_execution.is_success = lambda: False
        self.test_detector_execution.is_error = lambda: False
        self.test_detector_execution.is_timeout = lambda: False
        self.test_detector_execution.runtime = 0
        self.test_detector_execution.number_of_findings = 0
        self.test_run_timestamp = 1337
        self.test_detector_execution.get_run_info = lambda: {
            'number_of_findings': self.test_detector_execution.number_of_findings,
            'runtime': self.test_detector_execution.runtime,
            'timestamp': self.test_run_timestamp
        }
        self.test_detector_execution.findings_path = "-findings-"

        self.created_files_per_finding = dict()

        self.detector = StubDetector()  # type: Detector
        self.detector.id = "test_detector"

        self.experiment_id = "ex1"

        self.test_potential_hits = PotentialHits([])

        self.uut = PublishFindingsTask(self.experiment_id, "/sources", "http://dummy.url", "-username-", "-password-")
    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-")
示例#6
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")

        self.detector = StubDetector()
        experiment = Experiment("mock experiment", self.detector, self.findings_path)
        self.uut = Detect(self.compiles_path, experiment, None, False)
    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())
示例#8
0
    def test_creates_empty_execution_if_no_patterns(self):
        detector = StubDetector()
        project = create_project("-project-")
        version = create_version("-version-", project=project)

        experiment = ProvidedPatternsExperiment(detector, "-base-path-")
        run = experiment.get_run(version)

        assert not run.executions
    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()
示例#10
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")

        detector = StubDetector()
        experiment = Experiment(Experiment.PROVIDED_PATTERNS, detector,
                                self.findings_path)
        self.uut = Detect(self.compiles_path, experiment, None, False)
        self.uut._download = MagicMock(return_value=True)
    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.misuse = create_misuse('-misuse-', meta={"location": {"file": "a", "method": "m()"}})
        self.version = create_version("-version-", misuses=[self.misuse], project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_base_path = "-findings-"

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

        self.uut = DetectOnlyExecution(self.detector, self.version, self.misuse, self.findings_base_path,
                                       PotentialHits(self.misuse))
    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
示例#14
0
    def setup(self):
        self.misuse = create_misuse('-misuse-', meta={"location": {"file": "a", "method": "m()"}})
        self.version = create_version("-version-", misuses=[self.misuse], project=create_project("-project-"))
        self.detector = StubDetector()

        self.temp_dir = mkdtemp(prefix='mubench-run-test_')
        self.findings_path = join(self.temp_dir, "-findings-")

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

        self.__orig_shell_exec = Shell.exec
        Shell.exec = MagicMock()
    def test_adds_rank(self, read_yamls_mock):
        read_yamls_mock.return_value.__enter__.return_value = [{"name": "f1"}, {"name": "f2"}]
        execution = DetectorExecution(DetectorMode.mine_and_detect, StubDetector(), create_version("-v-"),
                                      "-findings-base-path-", FindingsFilter())
        execution._get_findings_path = lambda: ""

        findings = execution._load_findings()

        assert_equals(findings, [
            Finding({"name": "f1", "rank": 0}),
            Finding({"name": "f2", "rank": 1})
        ])
示例#16
0
    def setup(self):
        self.version = create_version("-version-",
                                      project=create_project("-project-"))
        self.detector = StubDetector()
        self.findings_path = "-findings-"
        self.findings_file_path = join(self.findings_path, "FINDINGS_FILE")
        self.run_file_path = join(self.findings_path, "run.yml")

        self.detector_args = {}

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

        self.uut = DetectorRun(self.detector, self.version, self.findings_path)
    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()
示例#18
0
    def test_adds_rank(self, read_yamls_mock, _):
        read_yamls_mock.return_value.__enter__.return_value = [{
            "name": "f1"
        }, {
            "name": "f2"
        }]
        execution = DetectorRun(StubDetector(), create_version("-v-"),
                                "-findings-path-")

        findings = execution._load_findings()

        assert_equals(findings, [
            Finding({
                "name": "f1",
                "rank": 0
            }),
            Finding({
                "name": "f2",
                "rank": 1
            })
        ])
示例#19
0
 def setup(self):
     self.detector = StubDetector()
     self.misuses = []
     self.uut = PotentialHits(self.misuses)
 def setup(self):
     self.detector = StubDetector()
     self.project = create_project("-project-")
     self.version = create_version("-version-", project=self.project)