Пример #1
0
    def test_spawn_basic(self):
        # User does not exist
        self.assertRaises(ValueError,
                          sp.spawn,
                          '/bin/sleep', ['/bin/sleep', '1000'],
                          user=self.nouser)
        self.assertRaises(ValueError,
                          sp.spawn,
                          '/bin/sleep', ['/bin/sleep', '1000'],
                          user=self.nouid)
        # Invalid CWD: it is a file
        self.assertRaises(OSError, sp.spawn, '/bin/sleep', cwd='/bin/sleep')
        # Invalid CWD: does not exist
        self.assertRaises(OSError, sp.spawn, '/bin/sleep', cwd=self.nofile)
        # Exec failure
        self.assertRaises(OSError, sp.spawn, self.nofile)

        # Test that the environment is cleared: sleep should not be found
        # XXX: This should be a python bug: if I don't set PATH explicitly, it
        # uses a default search path
        self.assertRaises(OSError, sp.spawn, 'sleep', env={'PATH': ''})

        r, w = os.pipe()
        p = sp.spawn('/bin/echo', ['echo', 'hello world'], stdout=w)
        os.close(w)
        self.assertEquals(_readall(r), "hello world\n")
        os.close(r)

        # Check poll.
        while True:
            ret = sp.poll(p)
            if ret is not None:
                self.assertEquals(ret, 0)
                break
            time.sleep(0.2)  # Wait a little bit.
        # It cannot be wait()ed again.
        self.assertRaises(OSError, sp.wait, p)

        r0, w0 = os.pipe()
        r1, w1 = os.pipe()
        p = sp.spawn('/bin/cat', stdout=w0, stdin=r1, close_fds=[r0, w1])
        os.close(w0)
        os.close(r1)
        self.assertEquals(sp.poll(p), None)
        os.write(w1, "hello world\n")
        os.close(w1)
        self.assertEquals(_readall(r0), "hello world\n")
        os.close(r0)
        self.assertEquals(sp.wait(p), 0)
Пример #2
0
    def test_spawn_basic(self):
        # User does not exist
        self.assertRaises(ValueError, sp.spawn,
                '/bin/sleep', ['/bin/sleep', '1000'], user = self.nouser)
        self.assertRaises(ValueError, sp.spawn,
                '/bin/sleep', ['/bin/sleep', '1000'], user = self.nouid)
        # Invalid CWD: it is a file
        self.assertRaises(OSError, sp.spawn, '/bin/sleep', cwd = '/bin/sleep')
        # Invalid CWD: does not exist
        self.assertRaises(OSError, sp.spawn, '/bin/sleep', cwd = self.nofile)
        # Exec failure
        self.assertRaises(OSError, sp.spawn, self.nofile)

        # Test that the environment is cleared: sleep should not be found
        # XXX: This should be a python bug: if I don't set PATH explicitly, it
        # uses a default search path
        self.assertRaises(OSError, sp.spawn, 'sleep', env = {'PATH': ''})

        r, w = os.pipe()
        p = sp.spawn('/bin/echo', ['echo', 'hello world'], stdout = w)
        os.close(w)
        self.assertEquals(_readall(r), "hello world\n")
        os.close(r)

        # Check poll.
        while True:
            ret = sp.poll(p)
            if ret is not None:
                self.assertEquals(ret, 0)
                break
            time.sleep(0.2)  # Wait a little bit.
        # It cannot be wait()ed again.
        self.assertRaises(OSError, sp.wait, p)

        r0, w0 = os.pipe()
        r1, w1 = os.pipe()
        p = sp.spawn('/bin/cat', stdout = w0, stdin = r1, close_fds = [r0, w1])
        os.close(w0)
        os.close(r1)
        self.assertEquals(sp.poll(p), None)
        os.write(w1, "hello world\n")
        os.close(w1)
        self.assertEquals(_readall(r0), "hello world\n")
        os.close(r0)
        self.assertEquals(sp.wait(p), 0)
Пример #3
0
 def test_spawn_chuser(self):
     user = '******'
     pid = sp.spawn('/bin/sleep', ['/bin/sleep', '100'], user=user)
     self._check_ownership(user, pid)
     os.kill(pid, signal.SIGTERM)
     self.assertEquals(sp.wait(pid), signal.SIGTERM)
Пример #4
0
 def test_spawn_chuser(self):
     user = '******'
     pid = sp.spawn('/bin/sleep', ['/bin/sleep', '100'], user = user)
     self._check_ownership(user, pid)
     os.kill(pid, signal.SIGTERM)
     self.assertEquals(sp.wait(pid), signal.SIGTERM)