def test_stdin(self): """ Making sure getPassword accepts a password from standard input by running a child process which uses getPassword to read in a string which it then writes it out again. Write a string to the child process and then read one and make sure it is the right string. """ p = PasswordTestingProcessProtocol() p.finished = Deferred() reactor.spawnProcess( p, sys.executable, [ sys.executable, '-c', ('import sys\n' 'from reqs.twisted.python.util import getPassword\n' 'sys.stdout.write(getPassword())\n' 'sys.stdout.flush()\n') ], env={'PYTHONPATH': os.pathsep.join(sys.path)}) def processFinished((reason, output)): reason.trap(ProcessDone) self.assertIn((1, 'secret'), output) return p.finished.addCallback(processFinished)
def test_stdin(self): """ Making sure getPassword accepts a password from standard input by running a child process which uses getPassword to read in a string which it then writes it out again. Write a string to the child process and then read one and make sure it is the right string. """ p = PasswordTestingProcessProtocol() p.finished = Deferred() reactor.spawnProcess( p, sys.executable, [sys.executable, '-c', ('import sys\n' 'from reqs.twisted.python.util import getPassword\n' 'sys.stdout.write(getPassword())\n' 'sys.stdout.flush()\n')], env={'PYTHONPATH': os.pathsep.join(sys.path)}) def processFinished((reason, output)): reason.trap(ProcessDone) self.assertIn((1, 'secret'), output) return p.finished.addCallback(processFinished)
def _callProtocolWithDeferred(protocol, executable, args, env, path, reactor=None): if reactor is None: from reqs.twisted.internet import reactor d = defer.Deferred() p = protocol(d) reactor.spawnProcess(p, executable, (executable,)+tuple(args), env, path) return d
def _callProtocolWithDeferred(protocol, executable, args, env, path, reactor=None): if reactor is None: from reqs.twisted.internet import reactor d = defer.Deferred() p = protocol(d) reactor.spawnProcess(p, executable, (executable, ) + tuple(args), env, path) return d