def test_white_list_misuse(self): uut = ProjectMisuseTask() uut.process_project_misuse = MagicMock() project = create_project("-p-") misuse1 = create_misuse("-m1-", project=project) misuse2 = create_misuse("-m2-", project=project) create_version("-v-", misuses=[misuse1, misuse2], project=project) uut.white_list = [misuse1.id] uut.process_project(project) assert_equals([call(project, misuse1)], uut.process_project_misuse.call_args_list)
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)
def test_finds_versions(self): version = create_version("v1", project=self.uut) create_file(version._version_file) versions = self.uut.versions assert_equals([version], versions)
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)
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)
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)
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)
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)
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)
def setup(self): self.temp_dir = mkdtemp(prefix="mubench-run-test_") self.findings_path = join(self.temp_dir, "-findings-") self.detector = Dummy("-detectors-") 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(self.detector) )
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)
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
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 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)
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-")
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
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-")
def setup(self): self.detector = Dummy("-detectors-") self.project = create_project("-project-") self.version = create_version("-version-", project=self.project)