Пример #1
0
 def test_iter_stdin(self):
     self.assertTrue(isinstance(sh.stdin(b'blah').iter_stdout, int))
     self.assertTrue(isinstance(sh.stdin('blah').iter_stdout, int))
     self.assertTrue(isinstance(sh.stdin(StringIO('')).iter_stdout,
                     StringIO))
     with open(__file__, 'rb') as fd:
         self.assertEqual(sh.stdin(fd).iter_stdout, fd)
Пример #2
0
 def test_stdin(self):
     content = open(__file__).read().strip()
     if not isinstance(content, six.binary_type):
         bcontent = content.encode('utf-8')
     else:
         bcontent = content
     self.assertEqual(content,
                      str(sh.stdin(bcontent) | sh.cat('-')))
     self.assertEqual(content,
                      str(sh.stdin(open(__file__, 'rb')) | sh.cat('-')))
Пример #3
0
    def test_sudo(self):
        sh.aliases['sudo'] = sh.path.join(sh.pwd(), 'sudo')
        old_path = sh.env.path
        sh.env.path = []
        self.assertRaises(OSError, sh.check_sudo)
        sh.env.path = old_path

        sh.stdin(six.b('#!/bin/bash\necho root')) > 'sudo'
        self.assertEqual(sh.chmod('+x sudo').succeeded, True)
        self.assertEqual(sh.check_sudo(), None)
Пример #4
0
    def test_repr(self):
        self.assertEqual(repr(sh.stdin(six.b('')) | sh.cat('-')),
                         repr(str('stdin | cat -')))

        @sh.wraps
        def w():
            pass

        self.assertEqual(repr(sh.cat('-') | w),
                         repr(str('cat - | w()')))

        self.assertEqual(str('<sh>'), repr(sh.sh))
Пример #5
0
 def test_stdin2(self):
     head = str(
         sh.stdin(open(self.__file__, 'rb')
                  ) | sh.cat('-') | sh.head('-n1'))
     self.assertTrue(len(head) > 1, head)
     self.assertTrue(len(head) > 2, head)
Пример #6
0
    def test_redirect_stdin(self):
        sh.stdin(b'blah') > 'tmp'
        self.assertEqual(str(sh.cat('tmp')), 'blah')

        sh.stdin(b'blah') >> 'tmp'
        self.assertEqual(str(sh.cat('tmp')), 'blahblah')
Пример #7
0
 def test_stdin_to_std(self):
     with open(__file__, 'rb') as stdin:
         sh.stdin(stdin) > '/tmp/stdout'