def test_functional(self): """ It works """ root = FilePath(self.mktemp()) root.makedirs() foo = root.child('foo') foo.setContent('#!%s\n' 'import sys, os\n' 'print sys.argv[1]\n' 'print sys.stdin.read()\n' % (sys.executable,)) foo.chmod(0777) history = [] runner = ScriptRunner(root.path, history.append) r = runner.run('foo', ['something'], 'guts') def check(proto): self.assertEqual(proto.stdout, 'something\nguts\n') self.assertEqual(proto.stderr, '') self.assertTrue(len(history) > 0) def eb(res): print res print '' for i in history: if i.key in [1,2,3]: print i.data['line'] return res return r.done.addCallback(check).addErrback(eb)
def test_run(self): """ You can run scripts in a directory """ runner = ScriptRunner('something', 'ch3_logger') runner.find = create_autospec(runner.find, return_value=FilePath('the script')) runner.spawn = create_autospec(runner.spawn, return_value='spawn ret') r = runner.run('joe', ['a', 'b'], 'stdin stuff') runner.find.assert_called_with('joe') runner.spawn.assert_called_with('joe', FilePath('the script').path, ['a', 'b'], 'stdin stuff') self.assertEqual(r, 'spawn ret')