def test_writes_stderr_from_cache(self, flags): """Write subprocess stderr on cached run of jobstamp.""" with open(self._executable_file, "w") as executable_file: executable_file.write(_PYTHON_SHEBANG + "import sys\n" "sys.stderr.write(\"stderr\\n\")\n") with capture(): run_executable(*flags) with capture() as captured: run_executable(*flags) self.assertEqual(captured.stderr.replace("\r\n", "\n"), "stderr\n")
def test_returncode(self, flags): """Return actual return code of subprocess.""" with open(self._executable_file, "w") as executable_file: executable_file.write(_PYTHON_SHEBANG + "import sys\n" "sys.exit(2)\n") with capture(): self.assertEqual(run_executable(*flags), 2)
def _get_command_output(self, set_options_func=lambda d: None): """Get output of running lint command with command line arguments.""" with capture() as captured: cmd = PolysquareLintCommand(self._distribution) set_options_func(cmd) cmd.ensure_finalized() cmd.run() return captured.stdout
def test_addComment(self): with iocapture.capture() as captured: retval = self.contract.addComment(self.params["market"], self.params["ipfsHash"]) output = json.loads(captured.stdout.replace("'", '"') .replace("L", "") .replace('u"', '"')) assert(retval == 1) assert(set(output.keys()) == self.event_fields) for k in self.params: assert(self.params[k] == output[k] % 2**256)
def when_i_launch_command_line(step): world.command_line = ['hello'] if world.parameters: world.command_line += world.parameters.split(' ') world.stdout = None import iocapture with iocapture.capture() as captured: alice.cli.ARGV = world.command_line alice.cli.main() world.stdout = captured.stdout
def test_prog(): "Program name propagates from sys.argv[0]" def cmd(foo=1): return foo p = DebugArghParser() p.add_commands([cmd]) usage = get_usage_string() with iocapture.capture() as captured: assert run(p, '-h', exit=True) == None assert captured.stdout.startswith(usage)
def when_i_launch_command_line_with_json_command(step): responses.add(responses.GET, 'http://echo.jsontest.com/key/value/one/two', json='{"one": "two","key": "value"}', status=200, content_type='application/json') world.command_line = ['json'] world.stdout = None import iocapture with iocapture.capture() as captured: alice.cli.ARGV = world.command_line alice.cli.main() world.stdout = captured.stdout
def test_show_checks(self, check): """Check that --checks shows a specified check.""" if check != list(linter.LINTER_FUNCTIONS.keys())[-1]: final_ellipsis = " ..." else: final_ellipsis = "" doctest_contents = ("... * {0}{1}").format(check, final_ellipsis) with capture() as captured: self.patch(sys, "exit", lambda _: None) linter.main(["--checks"]) self.assertThat(captured.stdout, # suppress(PYC70) DocTestMatches(doctest_contents, doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE | doctest.REPORT_NDIFF))
def test_require_double_dash(self): """Exit with error when -- is not present in command line.""" with capture(): self.assertEqual(jobstamp_cmd_main.main(["cmd"]), 1)
def test_with_statement(): with iocapture.capture() as captured: sys.stdout.write(string("hello world")) assert captured.stdout.strip() == string("hello world")