##// END OF EJS Templates
add save widget to text editor
add save widget to text editor

File last commit:

r15307:df95e3b4
r19316:faa203b6
Show More
__init__.py
145 lines | 4.8 KiB | text/x-python | PythonLexer
MinRK
some initial tests for newparallel
r3637 """toplevel setup/teardown for parallel tests."""
Thomas Kluyver
Convert print statements to print function calls...
r13348 from __future__ import print_function
MinRK
some initial tests for newparallel
r3637
MinRK
update API after sagedays29...
r3664 #-------------------------------------------------------------------------------
# Copyright (C) 2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
MinRK
better, more forceful wait for controller to start
r3678 import os
MinRK
add message tracking to client, add/improve tests
r3654 import tempfile
MinRK
added preliminary tests for zmq.parallel
r3595 import time
Thomas Kluyver
Capture output from subprocs during test, and display on failure...
r12973 from subprocess import Popen, PIPE, STDOUT
import nose
MinRK
added preliminary tests for zmq.parallel
r3595
MinRK
better, more forceful wait for controller to start
r3678 from IPython.utils.path import get_ipython_dir
MinRK
monkeypatch RemoteError to include tracebacks during tests
r15307 from IPython.parallel import Client, error
MinRK
improve process cleanup on Windows...
r3778 from IPython.parallel.apps.launcher import (LocalProcessLauncher,
ipengine_cmd_argv,
ipcontroller_cmd_argv,
MinRK
small changes in response to pyflakes pass...
r6270 SIGKILL,
ProcessStateError,
)
MinRK
added preliminary tests for zmq.parallel
r3595
MinRK
improve process cleanup on Windows...
r3778 # globals
launchers = []
blackhole = open(os.devnull, 'w')
# Launcher class
class TestProcessLauncher(LocalProcessLauncher):
"""subclass LocalProcessLauncher, to prevent extra sockets and threads being created on Windows"""
def start(self):
if self.state == 'before':
Thomas Kluyver
Option to spew subprocess streams during tests...
r13824 # Store stdout & stderr to show with failing tests.
# This is defined in IPython.testing.iptest
MinRK
improve process cleanup on Windows...
r3778 self.process = Popen(self.args,
Thomas Kluyver
Option to spew subprocess streams during tests...
r13824 stdout=nose.iptest_stdstreams_fileno(), stderr=STDOUT,
MinRK
improve process cleanup on Windows...
r3778 env=os.environ,
cwd=self.work_dir
)
self.notify_start(self.process.pid)
self.poll = self.process.poll
else:
s = 'The process was already started and has state: %r' % self.state
raise ProcessStateError(s)
MinRK
some initial tests for newparallel
r3637
# nose setup/teardown
MinRK
added preliminary tests for zmq.parallel
r3595
def setup():
MinRK
monkeypatch RemoteError to include tracebacks during tests
r15307
# show tracebacks for RemoteErrors
class RemoteErrorWithTB(error.RemoteError):
def __str__(self):
s = super(RemoteErrorWithTB, self).__str__()
return '\n'.join([s, self.traceback or ''])
error.RemoteError = RemoteErrorWithTB
MinRK
don't reuse connection files in parallel tests
r4116 cluster_dir = os.path.join(get_ipython_dir(), 'profile_iptest')
engine_json = os.path.join(cluster_dir, 'security', 'ipcontroller-engine.json')
client_json = os.path.join(cluster_dir, 'security', 'ipcontroller-client.json')
for json in (engine_json, client_json):
if os.path.exists(json):
os.remove(json)
MinRK
improve process cleanup on Windows...
r3778 cp = TestProcessLauncher()
cp.cmd_and_args = ipcontroller_cmd_argv + \
Thomas Kluyver
Capture output from subprocs during test, and display on failure...
r12973 ['--profile=iptest', '--log-level=20', '--ping=250', '--dictdb']
MinRK
improve process cleanup on Windows...
r3778 cp.start()
launchers.append(cp)
MinRK
better handle controller/engines never starting in tests
r3680 tic = time.time()
while not os.path.exists(engine_json) or not os.path.exists(client_json):
if cp.poll() is not None:
MinRK
remove some extraneous print statements from IPython.parallel...
r12522 raise RuntimeError("The test controller exited with status %s" % cp.poll())
MinRK
relax some timing constraints in parallel tests
r6890 elif time.time()-tic > 15:
MinRK
better handle controller/engines never starting in tests
r3680 raise RuntimeError("Timeout waiting for the test controller to start.")
MinRK
better, more forceful wait for controller to start
r3678 time.sleep(0.1)
MinRK
update API after sagedays29...
r3664 add_engines(1)
MinRK
added preliminary tests for zmq.parallel
r3595
MinRK
expedite IPython.parallel tests...
r6162 def add_engines(n=1, profile='iptest', total=False):
"""add a number of engines to a given profile.
If total is True, then already running engines are counted, and only
the additional engines necessary (if any) are started.
"""
MinRK
organize IPython.parallel into subpackages
r3673 rc = Client(profile=profile)
MinRK
update API after sagedays29...
r3664 base = len(rc)
MinRK
expedite IPython.parallel tests...
r6162
if total:
n = max(n - base, 0)
MinRK
update API after sagedays29...
r3664 eps = []
for i in range(n):
MinRK
improve process cleanup on Windows...
r3778 ep = TestProcessLauncher()
MinRK
don't color engine tracebacks in tests
r9731 ep.cmd_and_args = ipengine_cmd_argv + [
'--profile=%s' % profile,
'--log-level=50',
'--InteractiveShell.colors=nocolor'
]
MinRK
improve process cleanup on Windows...
r3778 ep.start()
launchers.append(ep)
MinRK
update API after sagedays29...
r3664 eps.append(ep)
MinRK
better handle controller/engines never starting in tests
r3680 tic = time.time()
MinRK
update API after sagedays29...
r3664 while len(rc) < base+n:
MinRK
better handle controller/engines never starting in tests
r3680 if any([ ep.poll() is not None for ep in eps ]):
raise RuntimeError("A test engine failed to start.")
MinRK
relax some timing constraints in parallel tests
r6890 elif time.time()-tic > 15:
MinRK
better handle controller/engines never starting in tests
r3680 raise RuntimeError("Timeout waiting for engines to connect.")
MinRK
update API after sagedays29...
r3664 time.sleep(.1)
rc.spin()
rc.close()
return eps
MinRK
added preliminary tests for zmq.parallel
r3595
def teardown():
MinRK
catch KeyboardInterrupt in parallel tests teardown...
r15305 try:
time.sleep(1)
except KeyboardInterrupt:
return
MinRK
improve process cleanup on Windows...
r3778 while launchers:
p = launchers.pop()
MinRK
added preliminary tests for zmq.parallel
r3595 if p.poll() is None:
try:
MinRK
improve process cleanup on Windows...
r3778 p.stop()
Matthias BUSSONNIER
conform to pep 3110...
r7787 except Exception as e:
Thomas Kluyver
Convert print statements to print function calls...
r13348 print(e)
MinRK
added preliminary tests for zmq.parallel
r3595 pass
if p.poll() is None:
MinRK
catch KeyboardInterrupt in parallel tests teardown...
r15305 try:
time.sleep(.25)
except KeyboardInterrupt:
return
MinRK
added preliminary tests for zmq.parallel
r3595 if p.poll() is None:
try:
Thomas Kluyver
Convert print statements to print function calls...
r13348 print('cleaning up test process...')
MinRK
improve process cleanup on Windows...
r3778 p.signal(SIGKILL)
MinRK
added preliminary tests for zmq.parallel
r3595 except:
Thomas Kluyver
Convert print statements to print function calls...
r13348 print("couldn't shutdown process: ", p)
MinRK
improve process cleanup on Windows...
r3778 blackhole.close()
MinRK
added preliminary tests for zmq.parallel
r3595