def test_finds_all_projects(self):
        p1 = create_project("p1", base_path=self.temp_dir)
        create_file(p1._project_file)
        p2 = create_project("p2", base_path=self.temp_dir)
        create_file(p2._project_file)

        self.uut.run()

        assert_equals([call(p1), call(p2)],
                      self.test_task.process_project.call_args_list)
    def test_runs_only_whitelisted_project(self):
        p2 = create_project("p2")
        self.uut._get_projects = MagicMock(
            return_value=[create_project("p1"), p2])
        self.uut.white_list.append("p2")

        self.uut.run()

        assert_equals([call(p2)],
                      self.test_task.process_project.call_args_list)
示例#3
0
    def test_finds_all_projects(self):
        p1 = create_project("p1", base_path=self.temp_dir)
        create_file(p1._project_file)
        p2 = create_project("p2", base_path=self.temp_dir)
        create_file(p2._project_file)
        uut = CollectProjectsTask(self.temp_dir)

        actual = uut.run(DataEntityLists([], []))

        assert_equals([p1, p2], actual)
示例#4
0
    def setup(self):
        self.temp_dir = mkdtemp(prefix="mubench-compile-test_")
        self.project_path = join(self.temp_dir, "project")
        self.version_path = join(self.project_path, "versions", "v0")
        self.checkout_base_path = join(self.temp_dir, "checkouts")
        self.compile_base_path = self.checkout_base_path

        self.source_dir = "src"
        self.project = create_project(self.project_path, meta={"repository": {"type": "git", "url": "-url-"}})
        self.version = create_version(self.version_path, project=self.project,
                                      meta={"build": {"src": self.source_dir,
                                                      "commands": ["mkdir classes"],
                                                      "classes": "classes"},
                                            "revision": "0"},
                                      misuses=[])

        checkout = self.version.get_checkout(self.checkout_base_path)

        self.checkout_path = checkout.checkout_dir
        self.source_path = join(self.checkout_path, self.source_dir)
        makedirs(self.source_path)

        self.base_path = dirname(self.checkout_path)
        self.build_path = join(self.base_path, "build")
        self.original_sources_path = join(self.base_path, "original-src")
        self.original_classes_path = join(self.base_path, "original-classes")
        self.misuse_source_path = join(self.base_path, "misuse-src")
        self.misuse_classes_path = join(self.base_path, "misuse-classes")
        self.pattern_sources_path = join(self.base_path, "patterns-src")
        self.pattern_classes_path = join(self.base_path, "patterns-classes")
        self.dep_path = join(self.base_path, "dependencies")

        self.uut = Compile(self.checkout_base_path, self.compile_base_path, False, False)
示例#5
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
示例#6
0
    def test_misuses_none(self, _):
        project = create_project("-project-", meta={})
        version = create_version("-id-", meta={"misuses": None}, project=project)

        self.uut.run(project, version)

        self.uut._report_missing_key.assert_any_call("misuses", "-project-/versions/-id-/version.yml")
    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 test_processes_project(self):
        project = create_project("p1")
        self.uut._get_projects = MagicMock(return_value=[project])

        self.uut.run()

        self.test_task.process_project.assert_called_with(project)
    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-")
示例#10
0
    def test_synthetic_no_url(self):
        meta = {"name": "-project-name-", "repository": {"type": "synthetic"}}
        project = create_project("-id-", meta=meta)

        self.uut.run(project)

        self.uut._report_missing_key.assert_not_called()
    def test_skips_blacklisted_project(self):
        self.uut._get_projects = MagicMock(return_value=[create_project("p1")])
        self.uut.black_list.append("p1")

        self.uut.run()

        self.test_task.process_project.assert_not_called()
 def test_unknown_type(self):
     version = create_version("-v-",
                              project=create_project(
                                  "-p-",
                                  meta={"repository": {
                                      "type": "unknown"
                                  }}))
     assert_raises(ValueError, version.get_checkout, "-base_path-")
示例#13
0
    def test_missing_repository_url(self):
        meta = {"name": "-project-name-", "repository": {"type": "git"}}
        project = create_project("-id-", meta=meta)

        self.uut.run(project)

        self.uut._report_missing_key.assert_any_call("repository.url",
                                                     "-id-/project.yml")
示例#14
0
    def test_filters_blacklisted(self):
        project = create_project("-id-", base_path=self.temp_dir)
        create_file(project._project_file)
        uut = CollectProjectsTask(self.temp_dir)

        actual = uut.run(DataEntityLists([], ["-id-"]))

        assert_equals([], actual)
示例#15
0
    def test_missing_misuses(self, _):
        meta = {"revision": "1"}
        project = create_project("-project-", meta={})
        version = create_version("-id-", meta=meta, project=project)

        self.uut.run(project, version)

        self.uut._report_missing_key.assert_any_call("misuses", "-project-/versions/-id-/version.yml")
示例#16
0
    def test_missing_repository(self):
        meta = {"name": "-project-name-"}
        project = create_project("-id-", meta=meta)

        self.uut.process_project(project)

        self.uut._report_missing_key.assert_any_call("repository",
                                                     "-id-/project.yml")
    def test_adds_project_to_backlist_when_task_answers_skip(self):
        self.uut._get_projects = MagicMock(
            return_value=[(create_project("p1"))])
        self.test_task.process_project = MagicMock(return_value=["p1"])

        self.uut.run()

        assert_equals(["p1"], self.uut.black_list)
    def test_runs_whitelisted_project_if_version_only_whitelist(self):
        project = create_project("p")
        self.uut._get_projects = MagicMock(return_value=[project])
        self.uut.white_list.append("p.42")

        self.uut.run()

        self.test_task.process_project.assert_called_with(project)
示例#19
0
    def test_missing_build_src(self, _):
        meta = {"build": {}}
        project = create_project("-project-", meta={})
        version = create_version("-id-", meta=meta, project=project)

        self.uut.run(project, version)

        self.uut._report_missing_key.assert_any_call("build.src", "-project-/versions/-id-/version.yml")
示例#20
0
    def test_empty_build_commands(self, _):
        meta = {"build": {"commands": []}}
        project = create_project("-project-", meta={})
        version = create_version("-id-", meta=meta, project=project)

        self.uut.run(project, version)

        self.uut._report_missing_key.assert_any_call("build.commands", "-project-/versions/-id-/version.yml")
示例#21
0
    def test_no_warning_on_known_project(self):
        project = create_project("-project-", meta=EMPTY_META)
        self.uut.datasets = {"-dataset-": [project.id]}

        self.uut.process_project(project)
        self.uut.end()

        self.uut._report_unknown_dataset_entry.assert_not_called()
示例#22
0
    def test_empty_misuses(self):
        meta = {"misuses": []}
        project = create_project("-project-", meta=EMPTY_META)
        version = create_version("-id-", meta=meta, project=project)

        self.uut.process_project_version(project, version)

        self.uut._report_missing_key.assert_any_call(
            "misuses", "-project-/versions/-id-/version.yml")
示例#23
0
    def test_no_warning_on_known_version(self):
        project = create_project("-project-", meta=EMPTY_META)
        version = create_version("-version-", project=project, meta=EMPTY_META)
        self.uut.datasets = {"-dataset-": [version.id]}

        self.uut.process_project_version(project, version)
        self.uut.end()

        self.uut._report_unknown_dataset_entry.assert_not_called()
示例#24
0
    def test_missing_build_commands(self):
        meta = {"build": {}}
        project = create_project("-project-", meta=EMPTY_META)
        version = create_version("-id-", meta=meta, project=project)

        self.uut.process_project_version(project, version)

        self.uut._report_missing_key.assert_any_call(
            "build.commands", "-project-/versions/-id-/version.yml")
示例#25
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 setup(self):
        self.project = create_project("p1")
        self.version1 = create_version("v1", project=self.project)
        self.version2 = create_version("v2", project=self.project)

        self.uut = ProjectVersionTask()
        self.uut.black_list = []
        self.uut.white_list = []
        self.uut.process_project_version = 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.uut = DetectorExecutionTestImpl(DetectorMode.detect_only, self.detector, self.version,
                                             self.findings_base_path, AllFindings())
    def test_white_list_project(self):
        uut = ProjectMisuseTask()
        uut.process_project_misuse = MagicMock()

        project1 = create_project("-p1-")
        project2 = create_project("-p2-")
        misuse1 = create_misuse("-m1-", project=project1)
        misuse2 = create_misuse("-m2-", project=project2)
        create_version("-v1-", misuses=[misuse1], project=project1)
        create_version("-v2-", misuses=[misuse2], project=project2)

        uut.white_list = [project1.id]

        uut.process_project(project1)
        uut.process_project(project2)

        assert_equals([call(project1, misuse1)],
                      uut.process_project_misuse.call_args_list)
示例#29
0
    def test_non_existent_misuse(self, _):
        self.uut._report_unknown_misuse = MagicMock()
        project = create_project("-project-", meta={})
        version = create_version("-id-", meta={"misuses": ["-misuse-"]}, project=project)
        version._MISUSES = []

        self.uut.run(project, version)

        self.uut._report_unknown_misuse.assert_any_call(version.id, "-misuse-")
示例#30
0
    def setUp(self):
        self.checkout = ProjectCheckout("-url-", "-base_path-", "-name-")
        self.checkout.create = MagicMock()
        self.checkout.delete = MagicMock()

        self.project = create_project("-project-")
        self.version = create_version("-version-", project=self.project)
        self.version.get_checkout = MagicMock(return_value=self.checkout)

        self.uut = Checkout("-checkouts-", force_checkout=False, use_temp_dir=False)