class TestMineAndDetectExecution: # noinspection PyAttributeOutsideInit 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 def test_execute(self, get_dependencies_classpath_mock, shell_mock): jar = self.detector.jar_path findings_path = join("-findings-", "mine_and_detect", "StubDetector", "-project-", "-version-") target = join(findings_path, "findings.yml") run_info = join(findings_path, "run.yml") compiles_path = join("-compiles-", "-project-", "-version-") target_src_path = join(compiles_path, "original-src") target_classpath = join(compiles_path, "original-classes") dependencies_classpath = "-dependencies-classpath-" get_dependencies_classpath_mock.return_value = dependencies_classpath self.uut.execute("-compiles-", 42, self.logger) shell_mock.exec.assert_called_with('java -jar "{}" '.format(jar) + 'target "{}" '.format(target) + 'run_info "{}" '.format(run_info) + 'detector_mode "0" ' + 'target_src_path "{}" '.format(target_src_path) + 'target_classpath "{}" '.format(target_classpath) + 'dep_classpath "{}"'.format(dependencies_classpath), logger=self.logger, timeout=42)
class TestMineAndDetectExecution: # noinspection PyAttributeOutsideInit 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()) # noinspection PyUnusedLocal # patch prevents write to filesystem def test_execute(self, get_dependencies_classpath_mock, write_yaml_mock): findings_path = join("-findings-", "mine_and_detect", "StubDetector", "-project-", "-version-") target = join(findings_path, "findings.yml") run_info = join(findings_path, "run.yml") compiles_path = join("-compiles-", "-project-", "-version-") target_src_path = join(compiles_path, "original-src") target_classpath = join(compiles_path, "original-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': "0", 'target_src_path': target_src_path, 'target_classpath': target_classpath, 'dep_classpath': '{}:{}'.format(dependencies_classpath, original_classpath) }, 42, self.logger)