def test__twistdBin(self): """ Should know what twistd to use. """ runner = Runner() path = commands.getoutput('which twistd') self.assertEqual(runner._twistdBin(), path)
def test_twistd(self): """ Should run twistd with the given arguments """ runner = Runner() fake_twistd = FilePath(self.mktemp()) fake_twistd.setContent('#!%s\n' 'import sys, os\n' 'print " ".join(sys.argv[1:])\n' 'print os.environ["FOO"]\n' 'print os.path.abspath(os.curdir)\n' 'sys.stdout.flush()\n' 'sys.stderr.write("error\\n")\n' 'print "stdout"\n' 'sys.exit(4)\n' % sys.executable) fake_twistd.chmod(0777) runner._twistdBin = lambda: fake_twistd.path path = FilePath(self.mktemp()) path.makedirs() d = runner.twistd(['foo', 'bar', 'baz'], env={'FOO': 'foo value'}, path=path.path) def check(result): out, err, code = result self.assertEqual(code, 4) self.assertEqual(out, 'foo bar baz\n' 'foo value\n' '%s\n' 'stdout\n' % path.path) self.assertEqual(err, 'error\n') return d.addCallback(check)