def test_passes_artifacts_dir(self): cmdline = "echo %TAURUS_ARTIFACTS_DIR%" if is_windows() else "echo $TAURUS_ARTIFACTS_DIR" self.engine.eval_env() self.engine.prepare() process = self.obj._execute(cmdline, shell=True) stdout, _ = communicate(process) self.assertEquals(self.engine.artifacts_dir, stdout.strip())
def check_if_installed(self): self.log.debug('Checking LocustIO: %s' % self.tool_path) try: stdout, stderr = communicate(shell_exec([self.tool_path, '--version'])) self.log.debug("Locustio check stdout/stderr: %s, %s", stdout, stderr) except (CalledProcessError, OSError, AttributeError): return False return True
def check_if_installed(self): self.log.debug('Checking Molotov: %s' % self.tool_path) try: stdout, stderr = communicate(shell_exec([self.tool_path, '--version'])) self.log.debug("Molotov stdout/stderr: %s, %s", stdout, stderr) version_s = stdout.strip() version = LooseVersion(version_s) if version < LooseVersion("1.4"): raise ToolError("You must install molotov>=1.4 to use this executor (version %s detected)" % version) except (CalledProcessError, OSError, AttributeError): return False return True
def test_communicate(self): self.sniff_log() out = b'\xf1\xe5\xedoutput' # on py2 bytes is just str synonym err = b'\xf1\xe5\xederror' obj = MockPopen(out, err) output = communicate(obj) if PY2: output = output[0].decode(), output[1].decode() # logging to file converts them to unicode self.assertEqual(output, ("output", "error"))
def tool_is_started(self): adb_path = os.path.join(get_full_path(self.tool_path, step_up=2), 'platform-tools', 'adb') if not os.path.isfile(adb_path): self.log.debug('adb is not found in sdk, trying to use an external one..') adb_path = 'adb' cmd = [adb_path, "shell", "getprop", "sys.boot_completed"] self.log.debug("Trying: %s", cmd) try: proc = shell_exec(cmd) out, _ = communicate(proc) return out.strip() == '1' except BaseException as exc: raise ToolError('Checking if android emulator starts is impossible: %s', exc)
def test_case_of_variables(self): env = {'aaa': 333, 'AAA': 666} line_tpl = "echo %%%s%%" if is_windows() else "echo $%s" cmdlines = [line_tpl % "aaa", line_tpl % "AAA"] results = set() for cmdline in cmdlines: process = self.executor.execute(cmdline, shell=True, env=env) stdout, _ = communicate(process) results.add(stdout.strip()) if is_windows(): self.assertEqual(1, len(results)) else: self.assertEqual(2, len(results))
def _get_results(self): stdout, stderr = communicate(self.process) # todo: show temp files from startup if stdout and (self.out == PIPE): self.log.debug("Output for %s:\n%s", self, stdout) if stderr and (self.err == PIPE): self.log.warning("Errors for %s:\n%s", self, stderr) self.log.debug("Task was finished with exit code %s: %s", self.process.returncode, self) if not self.ignore_failure and self.process.returncode != 0: if self.out != PIPE: self.log.warning("Output for %s:\n%s", self, stdout) raise CalledProcessError(self.process.returncode, self)
def test_case_of_variables(self): env = {'aaa': 333, 'AAA': 666} line_tpl = "echo %%%s%%" if is_windows() else "echo $%s" cmdlines = [line_tpl % "aaa", line_tpl % "AAA"] results = set() for cmdline in cmdlines: self.executor.env.set(env) process = self.executor.execute(cmdline, shell=True) stdout, _ = communicate(process) results.add(stdout.strip()) if is_windows(): self.assertEqual(1, len(results)) else: self.assertEqual(2, len(results))