def test_capture_timeout(self): ## make sure that capture doesn't return instantly cmd = Cmd("/bin/sh -c 'sleep 1 && echo foo'") self.assertSh( cmd.capture(1).stdout.read(), 'foo') ## make sure that timeout is honored, this process should take ## too long and be terminated cmd = Cmd("/bin/sh -c 'sleep 5 && echo foo'") self.assertSh( cmd.capture(1, timeout=1).stdout.read(), '')
def test_capture(self): self.assertSh( Cmd("/bin/sh -c 'echo foo'").capture(1).stdout.read(), 'foo') self.assertSh( Cmd("/bin/sh -c 'echo bar >&2'").capture(2).stderr.read(), 'bar') c_obj = Cmd("/bin/sh -c 'echo foo; echo bar >&2'") cout, cerr, status = c_obj.capture(1, 2) self.assertSh(cout.read(), 'foo') self.assertSh(cerr.read(), 'bar')