示例#1
0
 def isnt_cpu_heavy(self):
     "stdin mirroring isn't CPU-heavy"
     # CPU measurement under PyPy is...rather different. NBD.
     if PYPY:
         skip()
     # Python 3.5 has been seen using up to ~6.0s CPU time under Travis
     with assert_cpu_usage(lt=7.0):
         run("python -u busywork.py 10", pty=True, hide=True)
示例#2
0
 def nonprinting_bytes_pty(self):
     if WINDOWS:
         return
     # PTY use adds another utf-8 decode spot which can also fail.
     run(
         "echo '\xff'",
         pty=True,
         hide="stderr",
         out_stream=self.bad_stdout,
     )
示例#3
0
 def both_streams(self):
     watchers = [
         Responder("standard out", "with it\n"),
         Responder("standard error", "between chair and keyboard\n"),
     ]
     run(
         "python -u respond_both.py",
         watchers=watchers,
         hide=True,
         timeout=5,
     )
示例#4
0
 def triggers_exception_when_command_slow(self):
     before = time.time()
     with raises(CommandTimedOut) as info:
         run("sleep 5", timeout=0.5)
     after = time.time()
     # Fudge real time check a bit, <=0.5 typically fails due to
     # overhead etc. May need raising further to avoid races? Meh.
     assert (after - before) <= 0.75
     # Sanity checks of the exception obj
     assert info.value.timeout == 0.5
     assert info.value.result.command == "sleep 5"
示例#5
0
 def base_case(self):
     # Basic "doesn't explode" test: respond.py will exit nonzero unless
     # this works, causing a Failure.
     watcher = Responder(r"What's the password\?", "Rosebud\n")
     # Gotta give -u or Python will line-buffer its stdout, so we'll
     # never actually see the prompt.
     run(
         "python -u respond_base.py",
         watchers=[watcher],
         hide=True,
         timeout=5,
     )
示例#6
0
 def complex_nesting_under_ptys_doesnt_break(self):
     if WINDOWS:  # Not sure how to make this work on Windows
         return
     # GH issue 191
     substr = "      hello\t\t\nworld with spaces"
     cmd = """ eval 'echo "{}" ' """.format(substr)
     expected = "      hello\t\t\r\nworld with spaces\r\n"
     assert run(cmd, pty=True, hide="both").stdout == expected
示例#7
0
 def pty_puts_both_streams_in_stdout(self):
     if WINDOWS:
         return
     os.chdir("_support")
     err_echo = "{} err.py".format(sys.executable)
     command = "echo foo && {} bar".format(err_echo)
     r = run(command, hide="both", pty=True)
     assert r.stdout == "foo\r\nbar\r\n"
     assert r.stderr == ""
示例#8
0
 def watcher_errors_become_Failures(self):
     watcher = FailingResponder(
         pattern=r"What's the password\?",
         response="Rosebud\n",
         sentinel="You're not Citizen Kane!",
     )
     try:
         run(
             "python -u respond_fail.py",
             watchers=[watcher],
             hide=True,
             timeout=5,
         )
     except Failure as e:
         assert isinstance(e.reason, WatcherError)
         assert e.result.exited is None
     else:
         assert False, "Did not raise Failure!"
示例#9
0
 def pty_size_is_realistic(self):
     # When we don't explicitly set pty size, 'stty size' sees it as
     # 0x0.
     # When we do set it, it should be some non 0x0, non 80x24 (the
     # default) value. (yes, this means it fails if you really do have
     # an 80x24 terminal. but who does that?)
     size = run("stty size", hide=True, pty=True).stdout.strip()
     assert size != ""
     assert size != "0 0"
     assert size != "24 80"
示例#10
0
 def simple_command_with_pty(self):
     """
     Run command under PTY
     """
     # Most Unix systems should have stty, which asplodes when not run
     # under a pty, and prints useful info otherwise
     result = run("stty -a", hide=True, pty=True)
     # PTYs use \r\n, not \n, line separation
     assert "\r\n" in result.stdout
     assert result.pty is True
示例#11
0
 def doesnt_break_when_stdin_exists_but_null(self):
     # Re: #425 - IOError occurs when bug present
     run("inv -c nested_or_piped foo < /dev/null", hide=True)
示例#12
0
 def piped_stdin_is_not_conflated_with_mocked_stdin(self):
     # Re: GH issue #308
     # Will die on broken-pipe OSError if bug is present.
     run("echo 'lollerskates' | inv -c nested_or_piped foo", hide=True)
示例#13
0
 def nested_invoke_sessions_not_conflated_with_mocked_stdin(self):
     # Also re: GH issue #308. This one will just hang forever. Woo!
     run("inv -c nested_or_piped calls-foo", hide=True)
示例#14
0
def _output_eq(cmd, expected):
    assert run(cmd, hide=True).stdout == expected
示例#15
0
 def nonprinting_bytes(self):
     # Seriously non-printing characters (i.e. non UTF8) also don't
     # asplode (they would print as escapes normally, but still)
     run("echo '\xff'", hide="stderr", out_stream=self.bad_stdout)
示例#16
0
 def does_not_fire_when_command_quick(self):
     assert run("sleep 1", timeout=5)
示例#17
0
 def per_task_help(self):
     assert "Frobazz" in run("raft -c _explicit foo --help").stdout
示例#18
0
 def help_output(self):
     assert "Usage: inv[oke] " in run("raft --help").stdout
示例#19
0
 def basic_nonstandard_characters(self):
     os.chdir("_support")
     # Crummy "doesn't explode with decode errors" test
     cmd = ("type" if WINDOWS else "cat") + " tree.out"
     run(cmd, hide="stderr", out_stream=self.bad_stdout)
示例#20
0
 def bad_collection_exits_nonzero(self):
     result = run("inv -c nope -l", warn=True)
     assert result.exited == 1
     assert not result.stdout
     assert result.stderr
示例#21
0
 def run(self, Context):
     result = raft.run("foo", bar="biz")
     ctx = Context.return_value
     ctx.run.assert_called_once_with("foo", bar="biz")
     assert result is ctx.run.return_value