From 7a3b83705d3dae5572146e08b50cd6bf83557166 Mon Sep 17 00:00:00 2001
From: Carlos Valiente <carlos.valiente@ecmwf.int>
Date: Mon, 5 Jul 2010 09:21:09 +0100
Subject: [PATCH] Test PTYProcess
Previoues versions of the test were not passing the ``usePTY=True``
argument to ``reactor.spawnProcess``.
---
twisted/internet/test/test_process.py | 31 ++++++++++++++++++-------------
1 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/twisted/internet/test/test_process.py b/twisted/internet/test/test_process.py
index 6eaf537..b356359 100644
a
|
b
|
class ProcessTestsBuilderBase(ReactorBuilder): |
238 | 238 | "sys.stdout.write(str(process._listOpenFDs()))", |
239 | 239 | "sys.stdout.flush()") |
240 | 240 | |
| 241 | def checkOutput(output): |
| 242 | self.assertEquals('[0, 1, 2, 3]', output) |
| 243 | |
241 | 244 | reactor = self.buildReactor() |
242 | 245 | |
243 | | def processFinished(output): |
244 | | self.assertEquals('[0, 1, 2, 3]', output) |
| 246 | class Protocol(ProcessProtocol): |
245 | 247 | |
246 | | def shutdown(result): |
247 | | reactor.stop() |
248 | | return result |
| 248 | def __init__(self): |
| 249 | self.output = [] |
249 | 250 | |
250 | | def spawnChild(): |
251 | | msg("Spawning child with Twisted at %r" % (top.path,)) |
252 | | d = succeed(None) |
253 | | d.addCallback(lambda dummy: utils.getProcessOutput( |
254 | | sys.executable, ["-c", "\n".join(source)], reactor=reactor)) |
255 | | d.addCallback(processFinished) |
256 | | d.addBoth(shutdown) |
| 251 | def outReceived(self, data): |
| 252 | self.output.append(data) |
257 | 253 | |
258 | | reactor.callWhenRunning(spawnChild) |
| 254 | def processEnded(self, reason): |
| 255 | try: |
| 256 | checkOutput("".join(self.output)) |
| 257 | finally: |
| 258 | reactor.stop() |
| 259 | |
| 260 | proto = Protocol() |
| 261 | reactor.callWhenRunning( |
| 262 | reactor.spawnProcess, proto, sys.executable, |
| 263 | [sys.executable, "-c", "\n".join(source)], usePTY=self.usePTY) |
259 | 264 | self.runReactor(reactor) |
260 | 265 | |
261 | 266 | |