Exemplo n.º 1
0
    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)
Exemplo n.º 2
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)

        self.uut.run()

        assert_equals([call(p1), call(p2)], self.test_task.process_project.call_args_list)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def test_finds_misuses(self):
        misuse = create_misuse("1", project=create_project(self.project_id, base_path=self.temp_dir))
        create_file(misuse.misuse_file)
        self.uut._YAML = {"misuses": ["1"]}

        actual_misuses = self.uut.misuses

        assert_equals([misuse], actual_misuses)
Exemplo n.º 7
0
    def test_synthetic_project(self):
        version = create_version("-version-", project=create_project("-project-", meta={"repository": {"type": "synthetic"}}))

        checkout = version.get_checkout("-base_path-")

        assert isinstance(checkout, SyntheticProjectCheckout)
        assert_equals("-project-", checkout.name)
        assert_equals("-version-", checkout.version)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
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)
Exemplo n.º 11
0
    def test_svn_project(self):
        project = create_project("-project-", meta={"repository": {"type": "svn", "url": "http://url/svn"}})
        version = create_version("-version-", meta={"revision": "667"}, project=project)

        checkout = version.get_checkout("-base_path-")

        assert isinstance(checkout, SVNProjectCheckout)
        assert_equals("http://url/svn", checkout.url)
        assert_equals("-project-", checkout.name)
        assert_equals("-version-", checkout.version)
        assert_equals("667", checkout.revision)
Exemplo n.º 12
0
    def test_zip_project(self):
        project = create_project("-project-", meta={"repository": {"type": "zip"}})
        version = create_version("-version-", meta={"revision": "http://to.zip", "md5": "-checksum-"}, project=project)

        checkout = version.get_checkout("-base_path-")

        assert isinstance(checkout, ZipProjectCheckout)
        assert_equals("http://to.zip", checkout.url)
        assert_equals("-project-", checkout.name)
        assert_equals("-version-", checkout.version)
        assert_equals("-checksum-", checkout.md5_checksum)
Exemplo n.º 13
0
    def test_git_project(self):
        project = create_project("-project-", meta={"repository": {"type": "git", "url": "ssh://foobar.git"}})
        version = create_version("-version-", meta={"revision": "-revision-"}, project=project)

        checkout = version.get_checkout( "-base_path-")

        assert isinstance(checkout, GitProjectCheckout)
        assert_equals("ssh://foobar.git", checkout.url)
        assert_equals("-project-", checkout.name)
        assert_equals("-version-", checkout.version)
        assert_equals("-revision-", checkout.revision)
Exemplo n.º 14
0
    def test_finds_only_own_misuses(self):
        project = create_project(self.project_id, base_path=self.temp_dir)
        misuse1 = create_misuse("1", project=project)
        create_file(misuse1.misuse_file)
        misuse2 = create_misuse("2", project=project)
        create_file(misuse2.misuse_file)
        self.uut._YAML = {"misuses": ["2"]}

        misuses = self.uut.misuses

        assert_equals([misuse2], misuses)
    def test_white_list_project(self):
        uut = ProjectVersionMisuseTask()
        uut.process_project_version_misuse = MagicMock()

        project = create_project("-p-")
        misuse1 = create_misuse("-m1-", project=project)
        version = create_version("-v-", misuses=[misuse1], project=project)

        uut.white_list = [misuse1.project_id]

        uut.process_project_version(project, version)

        assert_equals([call(project, version, misuse1)], uut.process_project_version_misuse.call_args_list)
Exemplo n.º 16
0
    def setup(self):
        self.version = create_version("-version-", project=create_project("-project-"))
        self.detector = Dummy("-detectors-")
        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
Exemplo n.º 17
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 = Dummy("-detectors-")
        self.findings_base_path = "-findings-"

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

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

        self.uut = DetectOnlyExecution(
            self.detector, self.version, self.misuse, self.findings_base_path, PotentialHits(self.detector, self.misuse)
        )
        self.uut.save = MagicMock()
    def test_process_misuse(self):
        uut = ProjectVersionMisuseTask()
        uut.process_project_version_misuse = MagicMock()

        project = create_project("p1")
        m1 = create_misuse("m1")
        m2 = create_misuse("m2")
        m3 = create_misuse("m3")
        v1 = create_version("v1", misuses=[m1, m2], project=project)
        v2 = create_version("v2", misuses=[m3], project=project)

        uut.process_project(project)

        assert_equals([call(project, v1, m1), call(project, v1, m2), call(project, v2, m3)],
                      uut.process_project_version_misuse.call_args_list)
Exemplo n.º 19
0
    def test_process_misuse(self):
        uut = ProjectMisuseTask()
        uut.process_project_misuse = MagicMock()

        project = create_project("p1")
        m1 = create_misuse("m1")
        m2 = create_misuse("m2")
        m3 = create_misuse("m3")
        create_version("v1", misuses=[m1, m2], project=project)
        create_version("v2", misuses=[m3], project=project)

        uut.process_project(project)

        actual_call = uut.process_project_misuse.call_args_list
        assert_equals(3, len(actual_call))
        assert_in(call(project, m1), actual_call)
        assert_in(call(project, m2), actual_call)
        assert_in(call(project, m3), actual_call)
Exemplo n.º 20
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.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")

        def mock_compile(commands: List[str], cwd: str):
            source_path = join(cwd, self.source_dir)
            class_path = join(cwd, "classes")
            makedirs(class_path, exist_ok=True)
            for root, dirs, files in os.walk(source_path):
                package = relpath(root, source_path)
                for file in files:
                    file = file.replace(".java", ".class")
                    create_file(join(class_path, package, file))
                    print("fake compile: {}".format(join(class_path, package, file)))

        self.uut = Compile(self.checkout_base_path, self.checkout_base_path, False)
        self.uut._compile = MagicMock(side_effect=mock_compile)
Exemplo n.º 21
0
    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.detector = MagicMock()  # 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, "http://dummy.url", "-username-")
Exemplo n.º 22
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 = Dummy("path")
        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
Exemplo n.º 23
0
 def setup(self):
     self.project = create_project("-p-")
Exemplo n.º 24
0
 def setup(self):
     self.detector = Dummy("-detectors-")
     self.project = create_project("-project-")
     self.version = create_version("-version-", project=self.project)
Exemplo n.º 25
0
 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-")