Example #1
0
    def test_redirect_binary(self):
        with sh.pipes(sh.cat(__file__)) as cmd:
            cmd > 'tmp'
        ls = str(sh.ls('-l tmp'))

        with sh.pipes(sh.cat(__file__)) as cmd:
            cmd >> 'tmp'
        self.assertFalse(ls == str(sh.ls('-l tmp')))
        sh.rm('tmp')
Example #2
0
    def test_redirect_python(self):

        @sh.wraps
        def grep(stdin):
            for line in stdin:
                if b'__' in line:
                    yield line

        pipe = sh.cat(__file__) | grep
        with sh.pipes(pipe) as cmd:
            cmd > 'tmp'
        ls = str(sh.ls('-l tmp'))
        with sh.pipes(pipe) as cmd:
            cmd >> 'tmp'
        self.assertFalse(ls == str(sh.ls('-l tmp')), ls)
Example #3
0
 def test_redirect_to_std(self):
     ls = sh.ls()
     with open('/tmp/stdout', 'wb+') as fd:
         ls._sys_stdout = fd
         ls._sys_stderr = fd
         ls._write(1, 'x')
         ls._write(2, 'x')
         ls.args = ['/none']
         sh.log.handlers = []
         self.assertRaises(OSError, ls._write, 1, 'x')
Example #4
0
 def test_call_opts(self):
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.', shell=True)))
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.')(shell=True)))
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.', stderr=1)))
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.')(stderr=1)))
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.', combine_stderr=True)))
     self.assertEqual(str(sh.ls('.')), str(sh.ls('.')(combine_stderr=True)))