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))
class TestDetectOnlyExecution: # noinspection PyAttributeOutsideInit 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.__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 teardown(self): Shell.exec = self.__orig_shell_exec def test_execute_per_misuse(self): jar = self.detector.jar_path target = join("-findings-", "detect_only", "StubDetector", "-project-", "-version-", "-misuse-", "findings.yml") run_info = join("-findings-", "detect_only", "StubDetector", "-project-", "-version-", "-misuse-", "run.yml") training_src_path = join("-compiles-", "-project-", "-version-", "patterns-src", "-misuse-") training_classpath = join("-compiles-", "-project-", "-version-", "patterns-classes", "-misuse-") target_src_path = join("-compiles-", "-project-", "-version-", "misuse-src") target_classpath = join("-compiles-", "-project-", "-version-", "misuse-classes") self.uut.execute("-compiles-", 42, self.logger) Shell.exec.assert_called_with( 'java -jar "{}" '.format(jar) + 'target "{}" '.format(target) + 'run_info "{}" '.format(run_info) + 'detector_mode "1" ' + 'training_src_path "{}" '.format(training_src_path) + 'training_classpath "{}" '.format(training_classpath) + 'target_src_path "{}" '.format(target_src_path) + 'target_classpath "{}"'.format(target_classpath), logger=self.logger, timeout=42)
class TestDetectOnlyExecution: # noinspection PyAttributeOutsideInit 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)) # noinspection PyUnusedLocal # patch prevents write to filesystem def test_execute_per_misuse(self, get_dependencies_classpath_mock, write_yaml_mock): findings_path = join("-findings-", "detect_only", "StubDetector", "-project-", "-version-", "-misuse-") target = join(findings_path, "findings.yml") run_info = join(findings_path, "run.yml") compiles_path = join("-compiles-", "-project-", "-version-") training_src_path = join(compiles_path, "patterns-src", "-misuse-") training_classpath = join(compiles_path, "patterns-classes", "-misuse-") target_src_path = join(compiles_path, "misuse-src") target_classpath = join(compiles_path, "misuse-classes") original_classpath = join(compiles_path, "original-classes.jar") dependencies_classpath = "-dependencies-classpath-" get_dependencies_classpath_mock.return_value = dependencies_classpath self.uut.execute("-compiles-", 42, self.logger) self.detector.runner_interface.execute.assert_called_with( self.version, { 'target': target, 'run_info': run_info, 'detector_mode': "1", 'training_src_path': training_src_path, 'training_classpath': training_classpath, 'target_src_path': target_src_path, 'target_classpath': target_classpath, 'dep_classpath': dependencies_classpath + ":" + original_classpath }, 42, self.logger)
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 __create_execution(self, version, misuse): findings_filter = PotentialHits([misuse]) return DetectOnlyExecution(self.detector, version, misuse, self.findings_base_path, findings_filter)