##// END OF EJS Templates
Set up shell command-line tab-completion for ipython...
Set up shell command-line tab-completion for ipython Set up shell command-line tab-completion using argcomplete and ipython/traitlets#811 argcomplete supports following setuptools console_scripts to the corresponding package's __main__.py to look for a PYTHON_ARGCOMPLETE_OK marker.

File last commit:

r26723:f03bb325
r27960:3455b573
Show More
test_backgroundjobs.py
85 lines | 2.6 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
#-----------------------------------------------------------------------------
# Stdlib imports
import time
# Our own imports
from IPython.lib import backgroundjobs as bg
#-----------------------------------------------------------------------------
# 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()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert 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()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert len(jobs.completed) == 1
assert len(jobs.dead) == 0
Fernando Perez
Add basic test suite to background jobs library.
r4941 jobs.flush()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert 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()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert len(jobs.completed) == 0
assert len(jobs.dead) == 1
Fernando Perez
Add basic test suite to background jobs library.
r4941 jobs.flush()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert 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)
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert len(jobs.running) == 1
assert len(jobs.completed) == 0
Fernando Perez
Add basic test suite to background jobs library.
r4941 j.join()
Matthias Bussonnier
remove nose from test_background_jobs
r26723 assert len(jobs.running) == 0
assert len(jobs.completed) == 1