##// END OF EJS Templates
Merge pull request #2868 from takluyver/import-performance...
Merge pull request #2868 from takluyver/import-performance Import performance Defer various imports for a small reduction in startup time. IPython.lib.__init__ previously loaded IPython.lib.inputhook to export some of its functions. This meant that importing anything from IPython.lib also loaded inputhook. For now, I've just removed that import, but that is an API change, because the functions are no longer accessible as e.g. IPython.lib.enable_qt4 Added a note about the API change. Timing command, borrowed from Openoffice to simulate cold start: $ sync ; echo 3 | sudo tee /proc/sys/vm/drop_caches; time ipython3 -c pass Results with this branch: 7.68, 7.64, 7.35, 7.38 s 'real' Results with master: 8.17, 8.04, 7.81, 7.77

File last commit:

r7875:2549896b
r9459:ff3032f2 merge
Show More
test_backgroundjobs.py
91 lines | 2.9 KiB | text/x-python | PythonLexer
/ IPython / lib / tests / test_backgroundjobs.py
Fernando Perez
Add basic test suite to background jobs library.
r4941 """Tests for pylab tools module.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2011, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
# Stdlib imports
import sys
import time
# Third-party imports
import nose.tools as nt
# Our own imports
from IPython.lib import backgroundjobs as bg
from IPython.testing import decorators as dec
#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
t_short = 0.0001 # very short interval to wait on jobs
#-----------------------------------------------------------------------------
# Local utilities
#-----------------------------------------------------------------------------
def sleeper(interval=t_short, *a, **kw):
args = dict(interval=interval,
other_args=a,
kw_args=kw)
time.sleep(interval)
return args
def crasher(interval=t_short, *a, **kw):
time.sleep(interval)
raise Exception("Dead job with interval %s" % interval)
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
def test_result():
"""Test job submission and result retrieval"""
jobs = bg.BackgroundJobManager()
j = jobs.new(sleeper)
j.join()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(j.result['interval'], t_short)
Fernando Perez
Add basic test suite to background jobs library.
r4941
def test_flush():
"""Test job control"""
jobs = bg.BackgroundJobManager()
j = jobs.new(sleeper)
j.join()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.completed), 1)
nt.assert_equal(len(jobs.dead), 0)
Fernando Perez
Add basic test suite to background jobs library.
r4941 jobs.flush()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.completed), 0)
Fernando Perez
Add basic test suite to background jobs library.
r4941
def test_dead():
"""Test control of dead jobs"""
jobs = bg.BackgroundJobManager()
j = jobs.new(crasher)
j.join()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.completed), 0)
nt.assert_equal(len(jobs.dead), 1)
Fernando Perez
Add basic test suite to background jobs library.
r4941 jobs.flush()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.dead), 0)
Fernando Perez
Add basic test suite to background jobs library.
r4941
def test_longer():
"""Test control of longer-running jobs"""
jobs = bg.BackgroundJobManager()
# Sleep for long enough for the following two checks to still report the
# job as running, but not so long that it makes the test suite noticeably
# slower.
j = jobs.new(sleeper, 0.1)
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.running), 1)
nt.assert_equal(len(jobs.completed), 0)
Fernando Perez
Add basic test suite to background jobs library.
r4941 j.join()
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(len(jobs.running), 0)
nt.assert_equal(len(jobs.completed), 1)