示例#1
0
    def test_grab_stderr(self, tmpdir):
        tmp = tmpdir.join("test.out")
        spawn = Spawn(stderr=tmp.open('w'), stdout=None)
        spawn.run('perl -e "print STDERR 123456"', shell=True)

        assert tmp.read() == '123456'
        assert spawn.exitstatus == 0
示例#2
0
    def test_grab_stderr(self, tmpdir):
        tmp = tmpdir.join("test.out")
        spawn = Spawn(stderr=tmp.open('w'), stdout=None)
        spawn.run('perl -e "print STDERR 123456"', shell=True)

        assert tmp.read() == '123456'
        assert spawn.exitstatus == 0
示例#3
0
 def test_grab_stderr(self):
     f = open(outfile, 'w')
     spawn = Spawn(stderr=f, stdout=None)
     spawn.run('perl -e "print STDERR 123456"', shell=True)
     f.close()
     f = open(outfile)
     self.assertEqual(f.read(), '123456')
     self.assertEqual(spawn.exitstatus, 0)
     os.unlink(outfile)
示例#4
0
 def test_shell_error(self):
     # With shell=True you don't get an OSError
     spawn = Spawn(shell=True, stdout=None)
     spawn.run('sadfasdfasdf')
     assert spawn.exitstatus != 0
     assert spawn.exitstatus is not None
示例#5
0
 def test_multi_stdout(self):
     spawn = Spawn(stdout=[self.f, self.g])
     spawn.run('perl -e "print 123456"', shell=True)
     assert self.f.getvalue() == '123456'
     assert self.g.getvalue() == '123456'
     assert spawn.exitstatus == 0
示例#6
0
 def test_timeout_error(self):
     spawn = Spawn(shell=True, timeout=1, stdout=None)
     with pytest.raises(RunTimeoutError):
         spawn.run('sleep 5')
     assert spawn.exitstatus == None
示例#7
0
 def test_os_error(self):
     spawn = Spawn(stdout=None)
     with pytest.raises(OSError):
         spawn.run('bad command')
     assert spawn.exitstatus == None
示例#8
0
 def test_ok(self):
     spawn = Spawn(stdout=self.f)
     spawn.run(['echo', 'hello world'])
     assert spawn.exitstatus == 0
     assert spawn.outlines == ['hello world\n']
     assert self.f.getvalue() == 'hello world\n'
示例#9
0
 def test_shell_error(self):
     # With shell=True you don't get an OSError
     spawn = Spawn(shell=True, stdout=None)
     spawn.run('sadfasdfasdf')
     self.assertNotEqual(spawn.exitstatus, 0)
     self.assertNotEqual(spawn.exitstatus, None)
示例#10
0
 def test_multi_stdout(self):
     spawn = Spawn(stdout=[self.f, self.g])
     spawn.run('perl -e "print 123456"', shell=True)
     self.assertEqual(self.f.getvalue(), '123456')
     self.assertEqual(self.g.getvalue(), '123456')
     self.assertEqual(spawn.exitstatus, 0)
示例#11
0
 def test_ok(self):
     spawn = Spawn(stdout=self.f)
     spawn.run(['echo', 'hello world'])
     self.assertEqual(spawn.exitstatus, 0)
     self.assertEqual(spawn.outlines, ['hello world\n'])
     self.assertEqual(self.f.getvalue(), 'hello world\n')
示例#12
0
 def test_shell_error(self):
     # With shell=True you don't get an OSError
     spawn = Spawn(shell=True, stdout=None)
     spawn.run('sadfasdfasdf')
     assert spawn.exitstatus != 0
     assert spawn.exitstatus is not None
示例#13
0
 def test_multi_stdout(self):
     spawn = Spawn(stdout=[self.f, self.g])
     spawn.run('perl -e "print 123456"', shell=True)
     assert self.f.getvalue() == '123456'
     assert self.g.getvalue() == '123456'
     assert spawn.exitstatus == 0
示例#14
0
 def test_timeout_error(self):
     spawn = Spawn(shell=True, timeout=1, stdout=None)
     with pytest.raises(RunTimeoutError):
         spawn.run('sleep 5')
     assert spawn.exitstatus is None
示例#15
0
 def test_os_error(self):
     spawn = Spawn(stdout=None)
     with pytest.raises(OSError):
         spawn.run('bad command')
     assert spawn.exitstatus is None
示例#16
0
 def test_ok(self):
     spawn = Spawn(stdout=self.f)
     spawn.run(['echo', 'hello world'])
     assert spawn.exitstatus == 0
     assert spawn.outlines == ['hello world\n']
     assert self.f.getvalue() == 'hello world\n'