Example #1
0
    def test_capture_timeout(self):
        ## make sure that capture doesn't return instantly
        cmd = Pipe(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 = Pipe(Cmd("/bin/sh -c 'sleep 5 && echo foo'"))
        self.assertSh(
            cmd.capture(1, timeout=1).stdout.read(), '')
Example #2
0
    def test_capture_timeout2(self):
        """ make sure that a timeout that is longer than a pipeline
        should take to execute doesn't alter the results of that
        pipeline
        """
        p = Pipe(Cmd('yes'), Cmd('head -n 10'))
        self.assertSh(
            p.capture(1).stdout.read(),
            'y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n')

        p = Pipe(Cmd('yes'), Cmd('head -n 10'))
        self.assertSh(
            p.capture(1, timeout=1).stdout.read(),
            'y\ny\ny\ny\ny\ny\ny\ny\ny\ny\n')
Example #3
0
    def test_pipe_proc_decorator(self):
        @fork_dec
        def echoer(stdin_f, stdout_f, stderr_f):
            for line in stdin_f:
                stdout_f.write(line + "\n")
        pipe_obj = Pipe(Cmd("echo foo"),
                        echoer)
        self.assertSh(pipe_obj.capture(1).stdout.read(), 'foo')

        @fork_dec
        def doubler(stdin_f, stdout_f, stderr_f):
            for line in stdin_f:
                stdout_f.write(line+line + "\n")

        pipe_obj = Pipe(Cmd("echo foo"), doubler)
        self.assertSh(pipe_obj.capture(1).stdout.read(), 'foofoo')
Example #4
0
    def test_capture(self):
        self.assertSh(
            Pipe(Sh('echo foo; echo bar >&2', {2: os.devnull}),
                 Cmd('cat')).capture(1).stdout.read(),
            'foo')

        self.assertSh(
            Pipe(Sh('echo foo; echo bar >&2'),
                 Cmd('cat', {1: os.devnull})).capture(2).stderr.read(),
            'bar')

        sh_call = Pipe(Sh('echo bar >&2; echo foo; exit 1'))
        out, err, status = sh_call.capture(1, 2)
        self.assertEquals(status, 1)
        # these tests pass on OS X, not sure how they will run on
        # linux
        self.assertSh(out.read(), 'foo')
        self.assertSh(err.read(), 'bar')
Example #5
0
    def test_capture(self):
        sh_call = Sh('echo bar >&2; echo foo; exit 1')
        out, err, status = sh_call.capture(1, 2)
        self.assertEquals(status, 1)
        # these tests pass on OS X, not sure how they will run on
        # linux
        self.assertSh(out.read(), 'foo')
        self.assertSh(err.read(), 'bar')

        ### test Pipe impossible capture
        self.assertRaises(
            ValueError,
            lambda:pipe(Sh("echo bogus"), Cmd("cat", {1: os.devnull})))

        ### test Cmd impossible capture
        self.assertRaises(
            ValueError,
            lambda: sh("echo bogus stuff", {1: os.devnull}))

        ### test Pipe stderr capture
        pipe_ = Pipe(Sh('echo foo; sleep 0.01; echo  bar >&2'), Sh('cat >&2'))
        self.assertSh(pipe_.capture(2).stderr.read(), 'foobar')
Example #6
0
    def _asfd(self):
        pipe_a=Pipe(Cmd('ls /usr/local/Cellar'))

        pipe_b=Pipe(Cmd('wc -l'))
        outer_pipe = Pipe(pipe_a, pipe_b)
        self.assertSh(outer_pipe.capture(1).stdout.read(), '10')
Example #7
0
    def test_pipe_proc_interface(self):
        ### test Pipe ENV
        pipe_obj = Pipe(Pipe(Cmd("/bin/sh -c 'echo foo'")))

        self.assertSh(pipe_obj.capture(1).stdout.read(), 'foo')