Show More
@@ -0,0 +1,201 b'' | |||
|
1 | # encoding: utf-8 | |
|
2 | ||
|
3 | __docformat__ = "restructuredtext en" | |
|
4 | ||
|
5 | #------------------------------------------------------------------------------- | |
|
6 | # Copyright (C) 2008 The IPython Development Team | |
|
7 | # | |
|
8 | # Distributed under the terms of the BSD License. The full license is in | |
|
9 | # the file COPYING, distributed as part of this software. | |
|
10 | #------------------------------------------------------------------------------- | |
|
11 | ||
|
12 | #------------------------------------------------------------------------------- | |
|
13 | # Imports | |
|
14 | #------------------------------------------------------------------------------- | |
|
15 | ||
|
16 | import os, sys | |
|
17 | ||
|
18 | from glob import glob | |
|
19 | ||
|
20 | from setupext import install_data_ext | |
|
21 | ||
|
22 | #------------------------------------------------------------------------------- | |
|
23 | # Useful globals and utility functions | |
|
24 | #------------------------------------------------------------------------------- | |
|
25 | ||
|
26 | # A few handy globals | |
|
27 | isfile = os.path.isfile | |
|
28 | pjoin = os.path.join | |
|
29 | ||
|
30 | def oscmd(s): | |
|
31 | print ">", s | |
|
32 | os.system(s) | |
|
33 | ||
|
34 | # A little utility we'll need below, since glob() does NOT allow you to do | |
|
35 | # exclusion on multiple endings! | |
|
36 | def file_doesnt_endwith(test,endings): | |
|
37 | """Return true if test is a file and its name does NOT end with any | |
|
38 | of the strings listed in endings.""" | |
|
39 | if not isfile(test): | |
|
40 | return False | |
|
41 | for e in endings: | |
|
42 | if test.endswith(e): | |
|
43 | return False | |
|
44 | return True | |
|
45 | ||
|
46 | #--------------------------------------------------------------------------- | |
|
47 | # Basic project information | |
|
48 | #--------------------------------------------------------------------------- | |
|
49 | ||
|
50 | # Release.py contains version, authors, license, url, keywords, etc. | |
|
51 | execfile(pjoin('IPython','Release.py')) | |
|
52 | ||
|
53 | # Create a dict with the basic information | |
|
54 | # This dict is eventually passed to setup after additional keys are added. | |
|
55 | setup_args = dict( | |
|
56 | name = name, | |
|
57 | version = version, | |
|
58 | description = description, | |
|
59 | long_description = long_description, | |
|
60 | author = author, | |
|
61 | author_email = author_email, | |
|
62 | url = url, | |
|
63 | download_url = download_url, | |
|
64 | license = license, | |
|
65 | platforms = platforms, | |
|
66 | keywords = keywords, | |
|
67 | cmdclass = {'install_data': install_data_ext}, | |
|
68 | ) | |
|
69 | ||
|
70 | ||
|
71 | #--------------------------------------------------------------------------- | |
|
72 | # Find packages | |
|
73 | #--------------------------------------------------------------------------- | |
|
74 | ||
|
75 | def add_package(packages, pname, config=False, tests=False, scripts=False, others=None): | |
|
76 | packages.append('.'.join(['ipython1',pname])) | |
|
77 | if config: | |
|
78 | packages.append('.'.join(['ipython1',pname,'config'])) | |
|
79 | if tests: | |
|
80 | packages.append('.'.join(['ipython1',pname,'tests'])) | |
|
81 | if scripts: | |
|
82 | packages.append('.'.join(['ipython1',pname,'scripts'])) | |
|
83 | if others is not None: | |
|
84 | for o in others: | |
|
85 | packages.append('.'.join(['ipython1',pname,o])) | |
|
86 | ||
|
87 | def find_packages(): | |
|
88 | packages = ['ipython'] | |
|
89 | add_package(packages, 'config', tests=True) | |
|
90 | add_package(packages , 'Extensions') | |
|
91 | add_package(packages, 'external') | |
|
92 | add_package(packages, 'gui') | |
|
93 | add_package(packages, 'gui.wx') | |
|
94 | add_package(packages, 'kernel', config=True, tests=True, scripts=True) | |
|
95 | add_package(packages, 'kernel.core', config=True, tests=True) | |
|
96 | add_package(packages, 'testing', tests=True) | |
|
97 | add_package(packages, 'tools', tests=True) | |
|
98 | add_package(packages, 'UserConfig') | |
|
99 | return packages | |
|
100 | ||
|
101 | #--------------------------------------------------------------------------- | |
|
102 | # Find package data | |
|
103 | #--------------------------------------------------------------------------- | |
|
104 | ||
|
105 | def find_package_data(): | |
|
106 | # This is not enough for these things to appear in an sdist. | |
|
107 | # We need to muck with the MANIFEST to get this to work | |
|
108 | package_data = {'IPython.UserConfig' : ['*'] } | |
|
109 | return package_data | |
|
110 | ||
|
111 | ||
|
112 | #--------------------------------------------------------------------------- | |
|
113 | # Find data files | |
|
114 | #--------------------------------------------------------------------------- | |
|
115 | ||
|
116 | def find_data_files(): | |
|
117 | ||
|
118 | # I can't find how to make distutils create a nested dir. structure, so | |
|
119 | # in the meantime do it manually. Butt ugly. | |
|
120 | # Note that http://www.redbrick.dcu.ie/~noel/distutils.html, ex. 2/3, contain | |
|
121 | # information on how to do this more cleanly once python 2.4 can be assumed. | |
|
122 | # Thanks to Noel for the tip. | |
|
123 | docdirbase = 'share/doc/ipython' | |
|
124 | manpagebase = 'share/man/man1' | |
|
125 | ||
|
126 | # We only need to exclude from this things NOT already excluded in the | |
|
127 | # MANIFEST.in file. | |
|
128 | exclude = ('.sh','.1.gz') | |
|
129 | docfiles = filter(lambda f:file_doesnt_endwith(f,exclude),glob('doc/*')) | |
|
130 | examfiles = filter(isfile, glob('doc/examples/*.py')) | |
|
131 | manfiles = filter(isfile, glob('doc/manual/*')) | |
|
132 | manstatic = filter(isfile, glob('doc/manual/_static/*')) | |
|
133 | manpages = filter(isfile, glob('doc/*.1.gz')) | |
|
134 | scriptfiles = filter(isfile, ['scripts/ipython','scripts/pycolor', | |
|
135 | 'scripts/irunner']) | |
|
136 | igridhelpfiles = filter(isfile, glob('IPython/Extensions/igrid_help.*')) | |
|
137 | ||
|
138 | data_files = [('data', docdirbase, docfiles), | |
|
139 | ('data', pjoin(docdirbase, 'examples'),examfiles), | |
|
140 | ('data', pjoin(docdirbase, 'manual'),manfiles), | |
|
141 | ('data', pjoin(docdirbase, 'manual/_static'),manstatic), | |
|
142 | ('data', manpagebase, manpages), | |
|
143 | ('data',pjoin(docdirbase, 'extensions'),igridhelpfiles), | |
|
144 | ] | |
|
145 | return data_files | |
|
146 | ||
|
147 | #--------------------------------------------------------------------------- | |
|
148 | # Find scripts | |
|
149 | #--------------------------------------------------------------------------- | |
|
150 | ||
|
151 | def find_scripts(): | |
|
152 | scripts = [] | |
|
153 | scripts.append('ipython1/kernel/scripts/ipengine') | |
|
154 | scripts.append('ipython1/kernel/scripts/ipcontroller') | |
|
155 | scripts.append('ipython1/kernel/scripts/ipcluster') | |
|
156 | scripts.append('scripts/ipython') | |
|
157 | scripts.append('scripts/pycolor') | |
|
158 | scripts.append('scripts/irunner') | |
|
159 | ||
|
160 | # Script to be run by the windows binary installer after the default setup | |
|
161 | # routine, to add shortcuts and similar windows-only things. Windows | |
|
162 | # post-install scripts MUST reside in the scripts/ dir, otherwise distutils | |
|
163 | # doesn't find them. | |
|
164 | if 'bdist_wininst' in sys.argv: | |
|
165 | if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): | |
|
166 | print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." | |
|
167 | sys.exit(1) | |
|
168 | scripts.append('scripts/ipython_win_post_install.py') | |
|
169 | ||
|
170 | return scripts | |
|
171 | ||
|
172 | #--------------------------------------------------------------------------- | |
|
173 | # Find scripts | |
|
174 | #--------------------------------------------------------------------------- | |
|
175 | ||
|
176 | def check_for_dependencies(): | |
|
177 | from setupext.setupext import ( | |
|
178 | print_line, print_raw, print_status, print_message, | |
|
179 | check_for_zopeinterface, check_for_twisted, | |
|
180 | check_for_foolscap, check_for_pyopenssl, | |
|
181 | check_for_sphinx, check_for_pygments, | |
|
182 | check_for_nose, check_for_pexpect | |
|
183 | ) | |
|
184 | print_line() | |
|
185 | print_raw("BUILDING IPYTHON") | |
|
186 | print_status('python', sys.version) | |
|
187 | print_status('platform', sys.platform) | |
|
188 | if sys.platform == 'win32': | |
|
189 | print_status('Windows version', sys.getwindowsversion()) | |
|
190 | ||
|
191 | print_raw("") | |
|
192 | print_raw("OPTIONAL DEPENDENCIES") | |
|
193 | ||
|
194 | check_for_zopeinterface() | |
|
195 | check_for_twisted() | |
|
196 | check_for_foolscap() | |
|
197 | check_for_pyopenssl() | |
|
198 | check_for_sphinx() | |
|
199 | check_for_pygments() | |
|
200 | check_for_nose() | |
|
201 | check_for_pexpect() No newline at end of file |
@@ -0,0 +1,177 b'' | |||
|
1 | # encoding: utf-8 | |
|
2 | ||
|
3 | __docformat__ = "restructuredtext en" | |
|
4 | ||
|
5 | #------------------------------------------------------------------------------- | |
|
6 | # Copyright (C) 2008 The IPython Development Team | |
|
7 | # | |
|
8 | # Distributed under the terms of the BSD License. The full license is in | |
|
9 | # the file COPYING, distributed as part of this software. | |
|
10 | #------------------------------------------------------------------------------- | |
|
11 | ||
|
12 | #------------------------------------------------------------------------------- | |
|
13 | # Imports | |
|
14 | #------------------------------------------------------------------------------- | |
|
15 | ||
|
16 | import sys, os | |
|
17 | from textwrap import fill | |
|
18 | ||
|
19 | display_status=True | |
|
20 | ||
|
21 | if display_status: | |
|
22 | def print_line(char='='): | |
|
23 | print char * 76 | |
|
24 | ||
|
25 | def print_status(package, status): | |
|
26 | initial_indent = "%22s: " % package | |
|
27 | indent = ' ' * 24 | |
|
28 | print fill(str(status), width=76, | |
|
29 | initial_indent=initial_indent, | |
|
30 | subsequent_indent=indent) | |
|
31 | ||
|
32 | def print_message(message): | |
|
33 | indent = ' ' * 24 + "* " | |
|
34 | print fill(str(message), width=76, | |
|
35 | initial_indent=indent, | |
|
36 | subsequent_indent=indent) | |
|
37 | ||
|
38 | def print_raw(section): | |
|
39 | print section | |
|
40 | else: | |
|
41 | def print_line(*args, **kwargs): | |
|
42 | pass | |
|
43 | print_status = print_message = print_raw = print_line | |
|
44 | ||
|
45 | #------------------------------------------------------------------------------- | |
|
46 | # Tests for specific packages | |
|
47 | #------------------------------------------------------------------------------- | |
|
48 | ||
|
49 | def check_for_ipython(): | |
|
50 | try: | |
|
51 | import IPython | |
|
52 | except ImportError: | |
|
53 | print_status("IPython", "Not found") | |
|
54 | return False | |
|
55 | else: | |
|
56 | print_status("IPython", IPython.__version__) | |
|
57 | return True | |
|
58 | ||
|
59 | def check_for_zopeinterface(): | |
|
60 | try: | |
|
61 | import zope.interface | |
|
62 | except ImportError: | |
|
63 | print_status("zope.Interface", "Not found (required for parallel computing capabilities)") | |
|
64 | return False | |
|
65 | else: | |
|
66 | print_status("Zope.Interface","yes") | |
|
67 | return True | |
|
68 | ||
|
69 | def check_for_twisted(): | |
|
70 | try: | |
|
71 | import twisted | |
|
72 | except ImportError: | |
|
73 | print_status("Twisted", "Not found (required for parallel computing capabilities)") | |
|
74 | return False | |
|
75 | else: | |
|
76 | major = twisted.version.major | |
|
77 | minor = twisted.version.minor | |
|
78 | micro = twisted.version.micro | |
|
79 | if not ((major==2 and minor>=5 and micro>=0) or \ | |
|
80 | major>=8): | |
|
81 | print_message("WARNING: IPython requires Twisted 2.5.0 or greater, you have version %s"%twisted.version.short()) | |
|
82 | return False | |
|
83 | else: | |
|
84 | print_status("Twisted", twisted.version.short()) | |
|
85 | return True | |
|
86 | ||
|
87 | def check_for_foolscap(): | |
|
88 | try: | |
|
89 | import foolscap | |
|
90 | except ImportError: | |
|
91 | print_status('Foolscap', "Not found (required for parallel computing capabilities)") | |
|
92 | return False | |
|
93 | else: | |
|
94 | print_status('Foolscap', foolscap.__version__) | |
|
95 | return True | |
|
96 | ||
|
97 | def check_for_pyopenssl(): | |
|
98 | try: | |
|
99 | import OpenSSL | |
|
100 | except ImportError: | |
|
101 | print_status('OpenSSL', "Not found (required if you want security in the parallel computing capabilities)") | |
|
102 | return False | |
|
103 | else: | |
|
104 | print_status('OpenSSL', OpenSSL.__version__) | |
|
105 | return True | |
|
106 | ||
|
107 | def check_for_sphinx(): | |
|
108 | try: | |
|
109 | import sphinx | |
|
110 | except ImportError: | |
|
111 | print_status('sphinx', "Not found (required for building the IPtyhon documentation)") | |
|
112 | return False | |
|
113 | else: | |
|
114 | print_status('sphinx', sphinx.__version__) | |
|
115 | return True | |
|
116 | ||
|
117 | def check_for_pygments(): | |
|
118 | try: | |
|
119 | import pygments | |
|
120 | except ImportError: | |
|
121 | print_status('pygments', "Not found (required for syntax highlighting of code in the IPtyhon documentation)") | |
|
122 | return False | |
|
123 | else: | |
|
124 | print_status('pygments', pygments.__version__) | |
|
125 | return True | |
|
126 | ||
|
127 | def check_for_nose(): | |
|
128 | try: | |
|
129 | import nose | |
|
130 | except ImportError: | |
|
131 | print_status('nose', "Not found (required for running the IPython test suite)") | |
|
132 | return False | |
|
133 | else: | |
|
134 | print_status('nose', nose.__version__) | |
|
135 | return True | |
|
136 | ||
|
137 | def check_for_pexpect(): | |
|
138 | try: | |
|
139 | import pexpect | |
|
140 | except ImportError: | |
|
141 | print_status("pexpect", "no (required for running standalone doctests)") | |
|
142 | return False | |
|
143 | else: | |
|
144 | print_status("pexpect", pexpect.__version__) | |
|
145 | return True | |
|
146 | ||
|
147 | def check_for_httplib2(): | |
|
148 | try: | |
|
149 | import httplib2 | |
|
150 | except ImportError: | |
|
151 | print_status("httplib2", "no (required for blocking http clients)") | |
|
152 | return False | |
|
153 | else: | |
|
154 | print_status("httplib2","yes") | |
|
155 | return True | |
|
156 | ||
|
157 | def check_for_sqlalchemy(): | |
|
158 | try: | |
|
159 | import sqlalchemy | |
|
160 | except ImportError: | |
|
161 | print_status("sqlalchemy", "no (required for the ipython1 notebook)") | |
|
162 | return False | |
|
163 | else: | |
|
164 | print_status("sqlalchemy","yes") | |
|
165 | return True | |
|
166 | ||
|
167 | def check_for_simplejson(): | |
|
168 | try: | |
|
169 | import simplejson | |
|
170 | except ImportError: | |
|
171 | print_status("simplejson", "no (required for the ipython1 notebook)") | |
|
172 | return False | |
|
173 | else: | |
|
174 | print_status("simplejson","yes") | |
|
175 | return True | |
|
176 | ||
|
177 | No newline at end of file |
@@ -1,89 +1,95 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """Release data for the IPython project. |
|
3 | 3 | |
|
4 | 4 | $Id: Release.py 3002 2008-02-01 07:17:00Z fperez $""" |
|
5 | 5 | |
|
6 | 6 | #***************************************************************************** |
|
7 | 7 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
8 | 8 | # |
|
9 | 9 | # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray |
|
10 | 10 | # <n8gray@caltech.edu> |
|
11 | 11 | # |
|
12 | 12 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | 13 | # the file COPYING, distributed as part of this software. |
|
14 | 14 | #***************************************************************************** |
|
15 | 15 | |
|
16 | 16 | # Name of the package for release purposes. This is the name which labels |
|
17 | 17 | # the tarballs and RPMs made by distutils, so it's best to lowercase it. |
|
18 | 18 | name = 'ipython' |
|
19 | 19 | |
|
20 | 20 | # For versions with substrings (like 0.6.16.svn), use an extra . to separate |
|
21 | 21 | # the new substring. We have to avoid using either dashes or underscores, |
|
22 | 22 | # because bdist_rpm does not accept dashes (an RPM) convention, and |
|
23 | 23 | # bdist_deb does not accept underscores (a Debian convention). |
|
24 | 24 | |
|
25 | 25 | revision = '128' |
|
26 | 26 | branch = 'ipython' |
|
27 | 27 | |
|
28 | 28 | if branch == 'ipython': |
|
29 | 29 | version = '0.8.4.bzr.r' + revision |
|
30 | 30 | else: |
|
31 | 31 | version = '0.8.4.bzr.r%s.%s' % (revision,branch) |
|
32 | 32 | |
|
33 | 33 | version = '0.8.4' |
|
34 | 34 | |
|
35 |
description = " |
|
|
35 | description = "Tools for interactive development in Python." | |
|
36 | 36 | |
|
37 | 37 | long_description = \ |
|
38 | 38 | """ |
|
39 | 39 | IPython provides a replacement for the interactive Python interpreter with |
|
40 | 40 | extra functionality. |
|
41 | 41 | |
|
42 | 42 | Main features: |
|
43 | 43 | |
|
44 | 44 | * Comprehensive object introspection. |
|
45 | 45 | |
|
46 | 46 | * Input history, persistent across sessions. |
|
47 | 47 | |
|
48 | 48 | * Caching of output results during a session with automatically generated |
|
49 | 49 | references. |
|
50 | 50 | |
|
51 | 51 | * Readline based name completion. |
|
52 | 52 | |
|
53 | 53 | * Extensible system of 'magic' commands for controlling the environment and |
|
54 | 54 | performing many tasks related either to IPython or the operating system. |
|
55 | 55 | |
|
56 | 56 | * Configuration system with easy switching between different setups (simpler |
|
57 | 57 | than changing $PYTHONSTARTUP environment variables every time). |
|
58 | 58 | |
|
59 | 59 | * Session logging and reloading. |
|
60 | 60 | |
|
61 | 61 | * Extensible syntax processing for special purpose situations. |
|
62 | 62 | |
|
63 | 63 | * Access to the system shell with user-extensible alias system. |
|
64 | 64 | |
|
65 | 65 | * Easily embeddable in other Python programs. |
|
66 | 66 | |
|
67 | 67 | * Integrated access to the pdb debugger and the Python profiler. |
|
68 | 68 | |
|
69 | 69 | The latest development version is always available at the IPython subversion |
|
70 | 70 | repository_. |
|
71 | 71 | |
|
72 | 72 | .. _repository: http://ipython.scipy.org/svn/ipython/ipython/trunk#egg=ipython-dev |
|
73 | 73 | """ |
|
74 | 74 | |
|
75 | 75 | license = 'BSD' |
|
76 | 76 | |
|
77 | 77 | authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'), |
|
78 | 78 | 'Janko' : ('Janko Hauser','jhauser@zscout.de'), |
|
79 | 79 | 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'), |
|
80 |
'Ville' : ('Ville Vainio','vivainio@gmail.com') |
|
|
80 | 'Ville' : ('Ville Vainio','vivainio@gmail.com'), | |
|
81 | 'Brian' : ('Brian E Granger', 'ellisonbg@gmail.com'), | |
|
82 | 'Min' : ('Min Ragan-Kelley', 'benjaminrk@gmail.com') | |
|
81 | 83 | } |
|
82 | 84 | |
|
85 | author = 'The IPython Development Team' | |
|
86 | ||
|
87 | author_email = 'ipython-dev@scipy.org' | |
|
88 | ||
|
83 | 89 | url = 'http://ipython.scipy.org' |
|
84 | 90 | |
|
85 | 91 | download_url = 'http://ipython.scipy.org/dist' |
|
86 | 92 | |
|
87 | 93 | platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME'] |
|
88 | 94 | |
|
89 | keywords = ['Interactive','Interpreter','Shell'] | |
|
95 | keywords = ['Interactive','Interpreter','Shell','Parallel','Distributed'] |
@@ -1,102 +1,102 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the kernel.engineservice.py module. |
|
4 | 4 | |
|
5 | 5 | Things that should be tested: |
|
6 | 6 | |
|
7 | 7 | - Should the EngineService return Deferred objects? |
|
8 | 8 | - Run the same tests that are run in shell.py. |
|
9 | 9 | - Make sure that the Interface is really implemented. |
|
10 | 10 | - The startService and stopService methods. |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | from twisted.internet import defer |
|
27 | 27 | import zope.interface as zi |
|
28 | 28 | |
|
29 | 29 | from IPython.kernel import engineservice as es |
|
30 | 30 | from IPython.kernel import error |
|
31 |
from IPython.test |
|
|
31 | from IPython.testing.util import DeferredTestCase | |
|
32 | 32 | from IPython.kernel.controllerservice import \ |
|
33 | 33 | IControllerCore |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | class IControllerCoreTestCase(object): |
|
37 | 37 | """Tests for objects that implement IControllerCore. |
|
38 | 38 | |
|
39 | 39 | This test assumes that self.controller is defined and implements |
|
40 | 40 | IControllerCore. |
|
41 | 41 | """ |
|
42 | 42 | |
|
43 | 43 | def testIControllerCoreInterface(self): |
|
44 | 44 | """Does self.engine claim to implement IEngineCore?""" |
|
45 | 45 | self.assert_(IControllerCore.providedBy(self.controller)) |
|
46 | 46 | |
|
47 | 47 | def testIControllerCoreInterfaceMethods(self): |
|
48 | 48 | """Does self.engine have the methods and attributes in IEngireCore.""" |
|
49 | 49 | for m in list(IControllerCore): |
|
50 | 50 | self.assert_(hasattr(self.controller, m)) |
|
51 | 51 | |
|
52 | 52 | def testRegisterUnregisterEngine(self): |
|
53 | 53 | engine = es.EngineService() |
|
54 | 54 | qengine = es.QueuedEngine(engine) |
|
55 | 55 | regDict = self.controller.register_engine(qengine, 0) |
|
56 | 56 | self.assert_(isinstance(regDict, dict)) |
|
57 | 57 | self.assert_(regDict.has_key('id')) |
|
58 | 58 | self.assert_(regDict['id']==0) |
|
59 | 59 | self.controller.unregister_engine(0) |
|
60 | 60 | self.assert_(self.controller.engines.get(0, None) == None) |
|
61 | 61 | |
|
62 | 62 | def testRegisterUnregisterMultipleEngines(self): |
|
63 | 63 | e1 = es.EngineService() |
|
64 | 64 | qe1 = es.QueuedEngine(e1) |
|
65 | 65 | e2 = es.EngineService() |
|
66 | 66 | qe2 = es.QueuedEngine(e2) |
|
67 | 67 | rd1 = self.controller.register_engine(qe1, 0) |
|
68 | 68 | self.assertEquals(rd1['id'], 0) |
|
69 | 69 | rd2 = self.controller.register_engine(qe2, 1) |
|
70 | 70 | self.assertEquals(rd2['id'], 1) |
|
71 | 71 | self.controller.unregister_engine(0) |
|
72 | 72 | rd1 = self.controller.register_engine(qe1, 0) |
|
73 | 73 | self.assertEquals(rd1['id'], 0) |
|
74 | 74 | self.controller.unregister_engine(1) |
|
75 | 75 | rd2 = self.controller.register_engine(qe2, 0) |
|
76 | 76 | self.assertEquals(rd2['id'], 1) |
|
77 | 77 | self.controller.unregister_engine(0) |
|
78 | 78 | self.controller.unregister_engine(1) |
|
79 | 79 | self.assertEquals(self.controller.engines,{}) |
|
80 | 80 | |
|
81 | 81 | def testRegisterCallables(self): |
|
82 | 82 | e1 = es.EngineService() |
|
83 | 83 | qe1 = es.QueuedEngine(e1) |
|
84 | 84 | self.registerCallableCalled = ';lkj' |
|
85 | 85 | self.unregisterCallableCalled = ';lkj' |
|
86 | 86 | self.controller.on_register_engine_do(self._registerCallable, False) |
|
87 | 87 | self.controller.on_unregister_engine_do(self._unregisterCallable, False) |
|
88 | 88 | self.controller.register_engine(qe1, 0) |
|
89 | 89 | self.assertEquals(self.registerCallableCalled, 'asdf') |
|
90 | 90 | self.controller.unregister_engine(0) |
|
91 | 91 | self.assertEquals(self.unregisterCallableCalled, 'asdf') |
|
92 | 92 | self.controller.on_register_engine_do_not(self._registerCallable) |
|
93 | 93 | self.controller.on_unregister_engine_do_not(self._unregisterCallable) |
|
94 | 94 | |
|
95 | 95 | def _registerCallable(self): |
|
96 | 96 | self.registerCallableCalled = 'asdf' |
|
97 | 97 | |
|
98 | 98 | def _unregisterCallable(self): |
|
99 | 99 | self.unregisterCallableCalled = 'asdf' |
|
100 | 100 | |
|
101 | 101 | def testBadUnregister(self): |
|
102 | 102 | self.assertRaises(AssertionError, self.controller.unregister_engine, 'foo') No newline at end of file |
@@ -1,373 +1,373 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """Test template for complete engine object""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | import cPickle as pickle |
|
19 | 19 | |
|
20 | 20 | from twisted.internet import defer, reactor |
|
21 | 21 | from twisted.python import failure |
|
22 | 22 | from twisted.application import service |
|
23 | 23 | import zope.interface as zi |
|
24 | 24 | |
|
25 | 25 | from IPython.kernel import newserialized |
|
26 | 26 | from IPython.kernel import error |
|
27 | 27 | from IPython.kernel.pickleutil import can, uncan |
|
28 | 28 | import IPython.kernel.engineservice as es |
|
29 | 29 | from IPython.kernel.core.interpreter import Interpreter |
|
30 |
from IPython.test |
|
|
30 | from IPython.testing.parametric import Parametric, parametric | |
|
31 | 31 | |
|
32 | 32 | #------------------------------------------------------------------------------- |
|
33 | 33 | # Tests |
|
34 | 34 | #------------------------------------------------------------------------------- |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | # A sequence of valid commands run through execute |
|
38 | 38 | validCommands = ['a=5', |
|
39 | 39 | 'b=10', |
|
40 | 40 | 'a=5; b=10; c=a+b', |
|
41 | 41 | 'import math; 2.0*math.pi', |
|
42 | 42 | """def f(): |
|
43 | 43 | result = 0.0 |
|
44 | 44 | for i in range(10): |
|
45 | 45 | result += i |
|
46 | 46 | """, |
|
47 | 47 | 'if 1<2: a=5', |
|
48 | 48 | """import time |
|
49 | 49 | time.sleep(0.1)""", |
|
50 | 50 | """from math import cos; |
|
51 | 51 | x = 1.0*cos(0.5)""", # Semicolons lead to Discard ast nodes that should be discarded |
|
52 | 52 | """from sets import Set |
|
53 | 53 | s = Set() |
|
54 | 54 | """, # Trailing whitespace should be allowed. |
|
55 | 55 | """import math |
|
56 | 56 | math.cos(1.0)""", # Test a method call with a discarded return value |
|
57 | 57 | """x=1.0234 |
|
58 | 58 | a=5; b=10""", # Test an embedded semicolon |
|
59 | 59 | """x=1.0234 |
|
60 | 60 | a=5; b=10;""" # Test both an embedded and trailing semicolon |
|
61 | 61 | ] |
|
62 | 62 | |
|
63 | 63 | # A sequence of commands that raise various exceptions |
|
64 | 64 | invalidCommands = [('a=1/0',ZeroDivisionError), |
|
65 | 65 | ('print v',NameError), |
|
66 | 66 | ('l=[];l[0]',IndexError), |
|
67 | 67 | ("d={};d['a']",KeyError), |
|
68 | 68 | ("assert 1==0",AssertionError), |
|
69 | 69 | ("import abababsdbfsbaljasdlja",ImportError), |
|
70 | 70 | ("raise Exception()",Exception)] |
|
71 | 71 | |
|
72 | 72 | def testf(x): |
|
73 | 73 | return 2.0*x |
|
74 | 74 | |
|
75 | 75 | globala = 99 |
|
76 | 76 | |
|
77 | 77 | def testg(x): |
|
78 | 78 | return globala*x |
|
79 | 79 | |
|
80 | 80 | class IEngineCoreTestCase(object): |
|
81 | 81 | """Test an IEngineCore implementer.""" |
|
82 | 82 | |
|
83 | 83 | def createShell(self): |
|
84 | 84 | return Interpreter() |
|
85 | 85 | |
|
86 | 86 | def catchQueueCleared(self, f): |
|
87 | 87 | try: |
|
88 | 88 | f.raiseException() |
|
89 | 89 | except error.QueueCleared: |
|
90 | 90 | pass |
|
91 | 91 | |
|
92 | 92 | def testIEngineCoreInterface(self): |
|
93 | 93 | """Does self.engine claim to implement IEngineCore?""" |
|
94 | 94 | self.assert_(es.IEngineCore.providedBy(self.engine)) |
|
95 | 95 | |
|
96 | 96 | def testIEngineCoreInterfaceMethods(self): |
|
97 | 97 | """Does self.engine have the methods and attributes in IEngineCore.""" |
|
98 | 98 | for m in list(es.IEngineCore): |
|
99 | 99 | self.assert_(hasattr(self.engine, m)) |
|
100 | 100 | |
|
101 | 101 | def testIEngineCoreDeferreds(self): |
|
102 | 102 | d = self.engine.execute('a=5') |
|
103 | 103 | d.addCallback(lambda _: self.engine.pull('a')) |
|
104 | 104 | d.addCallback(lambda _: self.engine.get_result()) |
|
105 | 105 | d.addCallback(lambda _: self.engine.keys()) |
|
106 | 106 | d.addCallback(lambda _: self.engine.push(dict(a=10))) |
|
107 | 107 | return d |
|
108 | 108 | |
|
109 | 109 | def runTestExecute(self, cmd): |
|
110 | 110 | self.shell = Interpreter() |
|
111 | 111 | actual = self.shell.execute(cmd) |
|
112 | 112 | def compare(computed): |
|
113 | 113 | actual['id'] = computed['id'] |
|
114 | 114 | self.assertEquals(actual, computed) |
|
115 | 115 | d = self.engine.execute(cmd) |
|
116 | 116 | d.addCallback(compare) |
|
117 | 117 | return d |
|
118 | 118 | |
|
119 | 119 | @parametric |
|
120 | 120 | def testExecute(cls): |
|
121 | 121 | return [(cls.runTestExecute, cmd) for cmd in validCommands] |
|
122 | 122 | |
|
123 | 123 | def runTestExecuteFailures(self, cmd, exc): |
|
124 | 124 | def compare(f): |
|
125 | 125 | self.assertRaises(exc, f.raiseException) |
|
126 | 126 | d = self.engine.execute(cmd) |
|
127 | 127 | d.addErrback(compare) |
|
128 | 128 | return d |
|
129 | 129 | |
|
130 | 130 | @parametric |
|
131 | 131 | def testExecuteFailures(cls): |
|
132 | 132 | return [(cls.runTestExecuteFailures, cmd, exc) for cmd, exc in invalidCommands] |
|
133 | 133 | |
|
134 | 134 | def runTestPushPull(self, o): |
|
135 | 135 | d = self.engine.push(dict(a=o)) |
|
136 | 136 | d.addCallback(lambda r: self.engine.pull('a')) |
|
137 | 137 | d.addCallback(lambda r: self.assertEquals(o,r)) |
|
138 | 138 | return d |
|
139 | 139 | |
|
140 | 140 | @parametric |
|
141 | 141 | def testPushPull(cls): |
|
142 | 142 | objs = [10,"hi there",1.2342354,{"p":(1,2)},None] |
|
143 | 143 | return [(cls.runTestPushPull, o) for o in objs] |
|
144 | 144 | |
|
145 | 145 | def testPullNameError(self): |
|
146 | 146 | d = self.engine.push(dict(a=5)) |
|
147 | 147 | d.addCallback(lambda _:self.engine.reset()) |
|
148 | 148 | d.addCallback(lambda _: self.engine.pull("a")) |
|
149 | 149 | d.addErrback(lambda f: self.assertRaises(NameError, f.raiseException)) |
|
150 | 150 | return d |
|
151 | 151 | |
|
152 | 152 | def testPushPullFailures(self): |
|
153 | 153 | d = self.engine.pull('a') |
|
154 | 154 | d.addErrback(lambda f: self.assertRaises(NameError, f.raiseException)) |
|
155 | 155 | d.addCallback(lambda _: self.engine.execute('l = lambda x: x')) |
|
156 | 156 | d.addCallback(lambda _: self.engine.pull('l')) |
|
157 | 157 | d.addErrback(lambda f: self.assertRaises(pickle.PicklingError, f.raiseException)) |
|
158 | 158 | d.addCallback(lambda _: self.engine.push(dict(l=lambda x: x))) |
|
159 | 159 | d.addErrback(lambda f: self.assertRaises(pickle.PicklingError, f.raiseException)) |
|
160 | 160 | return d |
|
161 | 161 | |
|
162 | 162 | def testPushPullArray(self): |
|
163 | 163 | try: |
|
164 | 164 | import numpy |
|
165 | 165 | except: |
|
166 | 166 | print 'no numpy, ', |
|
167 | 167 | return |
|
168 | 168 | a = numpy.random.random(1000) |
|
169 | 169 | d = self.engine.push(dict(a=a)) |
|
170 | 170 | d.addCallback(lambda _: self.engine.pull('a')) |
|
171 | 171 | d.addCallback(lambda b: b==a) |
|
172 | 172 | d.addCallback(lambda c: c.all()) |
|
173 | 173 | return self.assertDeferredEquals(d, True) |
|
174 | 174 | |
|
175 | 175 | def testPushFunction(self): |
|
176 | 176 | |
|
177 | 177 | d = self.engine.push_function(dict(f=testf)) |
|
178 | 178 | d.addCallback(lambda _: self.engine.execute('result = f(10)')) |
|
179 | 179 | d.addCallback(lambda _: self.engine.pull('result')) |
|
180 | 180 | d.addCallback(lambda r: self.assertEquals(r, testf(10))) |
|
181 | 181 | return d |
|
182 | 182 | |
|
183 | 183 | def testPullFunction(self): |
|
184 | 184 | d = self.engine.push_function(dict(f=testf, g=testg)) |
|
185 | 185 | d.addCallback(lambda _: self.engine.pull_function(('f','g'))) |
|
186 | 186 | d.addCallback(lambda r: self.assertEquals(r[0](10), testf(10))) |
|
187 | 187 | return d |
|
188 | 188 | |
|
189 | 189 | def testPushFunctionGlobal(self): |
|
190 | 190 | """Make sure that pushed functions pick up the user's namespace for globals.""" |
|
191 | 191 | d = self.engine.push(dict(globala=globala)) |
|
192 | 192 | d.addCallback(lambda _: self.engine.push_function(dict(g=testg))) |
|
193 | 193 | d.addCallback(lambda _: self.engine.execute('result = g(10)')) |
|
194 | 194 | d.addCallback(lambda _: self.engine.pull('result')) |
|
195 | 195 | d.addCallback(lambda r: self.assertEquals(r, testg(10))) |
|
196 | 196 | return d |
|
197 | 197 | |
|
198 | 198 | def testGetResultFailure(self): |
|
199 | 199 | d = self.engine.get_result(None) |
|
200 | 200 | d.addErrback(lambda f: self.assertRaises(IndexError, f.raiseException)) |
|
201 | 201 | d.addCallback(lambda _: self.engine.get_result(10)) |
|
202 | 202 | d.addErrback(lambda f: self.assertRaises(IndexError, f.raiseException)) |
|
203 | 203 | return d |
|
204 | 204 | |
|
205 | 205 | def runTestGetResult(self, cmd): |
|
206 | 206 | self.shell = Interpreter() |
|
207 | 207 | actual = self.shell.execute(cmd) |
|
208 | 208 | def compare(computed): |
|
209 | 209 | actual['id'] = computed['id'] |
|
210 | 210 | self.assertEquals(actual, computed) |
|
211 | 211 | d = self.engine.execute(cmd) |
|
212 | 212 | d.addCallback(lambda r: self.engine.get_result(r['number'])) |
|
213 | 213 | d.addCallback(compare) |
|
214 | 214 | return d |
|
215 | 215 | |
|
216 | 216 | @parametric |
|
217 | 217 | def testGetResult(cls): |
|
218 | 218 | return [(cls.runTestGetResult, cmd) for cmd in validCommands] |
|
219 | 219 | |
|
220 | 220 | def testGetResultDefault(self): |
|
221 | 221 | cmd = 'a=5' |
|
222 | 222 | shell = self.createShell() |
|
223 | 223 | shellResult = shell.execute(cmd) |
|
224 | 224 | def popit(dikt, key): |
|
225 | 225 | dikt.pop(key) |
|
226 | 226 | return dikt |
|
227 | 227 | d = self.engine.execute(cmd) |
|
228 | 228 | d.addCallback(lambda _: self.engine.get_result()) |
|
229 | 229 | d.addCallback(lambda r: self.assertEquals(shellResult, popit(r,'id'))) |
|
230 | 230 | return d |
|
231 | 231 | |
|
232 | 232 | def testKeys(self): |
|
233 | 233 | d = self.engine.keys() |
|
234 | 234 | d.addCallback(lambda s: isinstance(s, list)) |
|
235 | 235 | d.addCallback(lambda r: self.assertEquals(r, True)) |
|
236 | 236 | return d |
|
237 | 237 | |
|
238 | 238 | Parametric(IEngineCoreTestCase) |
|
239 | 239 | |
|
240 | 240 | class IEngineSerializedTestCase(object): |
|
241 | 241 | """Test an IEngineCore implementer.""" |
|
242 | 242 | |
|
243 | 243 | def testIEngineSerializedInterface(self): |
|
244 | 244 | """Does self.engine claim to implement IEngineCore?""" |
|
245 | 245 | self.assert_(es.IEngineSerialized.providedBy(self.engine)) |
|
246 | 246 | |
|
247 | 247 | def testIEngineSerializedInterfaceMethods(self): |
|
248 | 248 | """Does self.engine have the methods and attributes in IEngireCore.""" |
|
249 | 249 | for m in list(es.IEngineSerialized): |
|
250 | 250 | self.assert_(hasattr(self.engine, m)) |
|
251 | 251 | |
|
252 | 252 | def testIEngineSerializedDeferreds(self): |
|
253 | 253 | dList = [] |
|
254 | 254 | d = self.engine.push_serialized(dict(key=newserialized.serialize(12345))) |
|
255 | 255 | self.assert_(isinstance(d, defer.Deferred)) |
|
256 | 256 | dList.append(d) |
|
257 | 257 | d = self.engine.pull_serialized('key') |
|
258 | 258 | self.assert_(isinstance(d, defer.Deferred)) |
|
259 | 259 | dList.append(d) |
|
260 | 260 | D = defer.DeferredList(dList) |
|
261 | 261 | return D |
|
262 | 262 | |
|
263 | 263 | def testPushPullSerialized(self): |
|
264 | 264 | objs = [10,"hi there",1.2342354,{"p":(1,2)}] |
|
265 | 265 | d = defer.succeed(None) |
|
266 | 266 | for o in objs: |
|
267 | 267 | self.engine.push_serialized(dict(key=newserialized.serialize(o))) |
|
268 | 268 | value = self.engine.pull_serialized('key') |
|
269 | 269 | value.addCallback(lambda serial: newserialized.IUnSerialized(serial).getObject()) |
|
270 | 270 | d = self.assertDeferredEquals(value,o,d) |
|
271 | 271 | return d |
|
272 | 272 | |
|
273 | 273 | def testPullSerializedFailures(self): |
|
274 | 274 | d = self.engine.pull_serialized('a') |
|
275 | 275 | d.addErrback(lambda f: self.assertRaises(NameError, f.raiseException)) |
|
276 | 276 | d.addCallback(lambda _: self.engine.execute('l = lambda x: x')) |
|
277 | 277 | d.addCallback(lambda _: self.engine.pull_serialized('l')) |
|
278 | 278 | d.addErrback(lambda f: self.assertRaises(pickle.PicklingError, f.raiseException)) |
|
279 | 279 | return d |
|
280 | 280 | |
|
281 | 281 | Parametric(IEngineSerializedTestCase) |
|
282 | 282 | |
|
283 | 283 | class IEngineQueuedTestCase(object): |
|
284 | 284 | """Test an IEngineQueued implementer.""" |
|
285 | 285 | |
|
286 | 286 | def testIEngineQueuedInterface(self): |
|
287 | 287 | """Does self.engine claim to implement IEngineQueued?""" |
|
288 | 288 | self.assert_(es.IEngineQueued.providedBy(self.engine)) |
|
289 | 289 | |
|
290 | 290 | def testIEngineQueuedInterfaceMethods(self): |
|
291 | 291 | """Does self.engine have the methods and attributes in IEngireQueued.""" |
|
292 | 292 | for m in list(es.IEngineQueued): |
|
293 | 293 | self.assert_(hasattr(self.engine, m)) |
|
294 | 294 | |
|
295 | 295 | def testIEngineQueuedDeferreds(self): |
|
296 | 296 | dList = [] |
|
297 | 297 | d = self.engine.clear_queue() |
|
298 | 298 | self.assert_(isinstance(d, defer.Deferred)) |
|
299 | 299 | dList.append(d) |
|
300 | 300 | d = self.engine.queue_status() |
|
301 | 301 | self.assert_(isinstance(d, defer.Deferred)) |
|
302 | 302 | dList.append(d) |
|
303 | 303 | D = defer.DeferredList(dList) |
|
304 | 304 | return D |
|
305 | 305 | |
|
306 | 306 | def testClearQueue(self): |
|
307 | 307 | result = self.engine.clear_queue() |
|
308 | 308 | d1 = self.assertDeferredEquals(result, None) |
|
309 | 309 | d1.addCallback(lambda _: self.engine.queue_status()) |
|
310 | 310 | d2 = self.assertDeferredEquals(d1, {'queue':[], 'pending':'None'}) |
|
311 | 311 | return d2 |
|
312 | 312 | |
|
313 | 313 | def testQueueStatus(self): |
|
314 | 314 | result = self.engine.queue_status() |
|
315 | 315 | result.addCallback(lambda r: 'queue' in r and 'pending' in r) |
|
316 | 316 | d = self.assertDeferredEquals(result, True) |
|
317 | 317 | return d |
|
318 | 318 | |
|
319 | 319 | Parametric(IEngineQueuedTestCase) |
|
320 | 320 | |
|
321 | 321 | class IEnginePropertiesTestCase(object): |
|
322 | 322 | """Test an IEngineProperties implementor.""" |
|
323 | 323 | |
|
324 | 324 | def testIEnginePropertiesInterface(self): |
|
325 | 325 | """Does self.engine claim to implement IEngineProperties?""" |
|
326 | 326 | self.assert_(es.IEngineProperties.providedBy(self.engine)) |
|
327 | 327 | |
|
328 | 328 | def testIEnginePropertiesInterfaceMethods(self): |
|
329 | 329 | """Does self.engine have the methods and attributes in IEngireProperties.""" |
|
330 | 330 | for m in list(es.IEngineProperties): |
|
331 | 331 | self.assert_(hasattr(self.engine, m)) |
|
332 | 332 | |
|
333 | 333 | def testGetSetProperties(self): |
|
334 | 334 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
335 | 335 | d = self.engine.set_properties(dikt) |
|
336 | 336 | d.addCallback(lambda r: self.engine.get_properties()) |
|
337 | 337 | d = self.assertDeferredEquals(d, dikt) |
|
338 | 338 | d.addCallback(lambda r: self.engine.get_properties(('c',))) |
|
339 | 339 | d = self.assertDeferredEquals(d, {'c': dikt['c']}) |
|
340 | 340 | d.addCallback(lambda r: self.engine.set_properties(dict(c=False))) |
|
341 | 341 | d.addCallback(lambda r: self.engine.get_properties(('c', 'd'))) |
|
342 | 342 | d = self.assertDeferredEquals(d, dict(c=False, d=None)) |
|
343 | 343 | return d |
|
344 | 344 | |
|
345 | 345 | def testClearProperties(self): |
|
346 | 346 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
347 | 347 | d = self.engine.set_properties(dikt) |
|
348 | 348 | d.addCallback(lambda r: self.engine.clear_properties()) |
|
349 | 349 | d.addCallback(lambda r: self.engine.get_properties()) |
|
350 | 350 | d = self.assertDeferredEquals(d, {}) |
|
351 | 351 | return d |
|
352 | 352 | |
|
353 | 353 | def testDelHasProperties(self): |
|
354 | 354 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
355 | 355 | d = self.engine.set_properties(dikt) |
|
356 | 356 | d.addCallback(lambda r: self.engine.del_properties(('b','e'))) |
|
357 | 357 | d.addCallback(lambda r: self.engine.has_properties(('a','b','c','d','e'))) |
|
358 | 358 | d = self.assertDeferredEquals(d, [True, False, True, True, False]) |
|
359 | 359 | return d |
|
360 | 360 | |
|
361 | 361 | def testStrictDict(self): |
|
362 | 362 | s = """from IPython.kernel.engineservice import get_engine |
|
363 | 363 | p = get_engine(%s).properties"""%self.engine.id |
|
364 | 364 | d = self.engine.execute(s) |
|
365 | 365 | d.addCallback(lambda r: self.engine.execute("p['a'] = lambda _:None")) |
|
366 | 366 | d = self.assertDeferredRaises(d, error.InvalidProperty) |
|
367 | 367 | d.addCallback(lambda r: self.engine.execute("p['a'] = range(5)")) |
|
368 | 368 | d.addCallback(lambda r: self.engine.execute("p['a'].append(5)")) |
|
369 | 369 | d.addCallback(lambda r: self.engine.get_properties('a')) |
|
370 | 370 | d = self.assertDeferredEquals(d, dict(a=range(5))) |
|
371 | 371 | return d |
|
372 | 372 | |
|
373 | 373 | Parametric(IEnginePropertiesTestCase) |
@@ -1,838 +1,838 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | from twisted.internet import defer |
|
19 | 19 | |
|
20 | 20 | from IPython.kernel import engineservice as es |
|
21 | 21 | from IPython.kernel import multiengine as me |
|
22 | 22 | from IPython.kernel import newserialized |
|
23 | 23 | from IPython.kernel.error import NotDefined |
|
24 |
from IPython.test |
|
|
25 |
from IPython.test |
|
|
24 | from IPython.testing import util | |
|
25 | from IPython.testing.parametric import parametric, Parametric | |
|
26 | 26 | from IPython.kernel import newserialized |
|
27 | 27 | from IPython.kernel.util import printer |
|
28 | 28 | from IPython.kernel.error import (InvalidEngineID, |
|
29 | 29 | NoEnginesRegistered, |
|
30 | 30 | CompositeError, |
|
31 | 31 | InvalidDeferredID) |
|
32 | 32 | from IPython.kernel.tests.engineservicetest import validCommands, invalidCommands |
|
33 | 33 | from IPython.kernel.core.interpreter import Interpreter |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | #------------------------------------------------------------------------------- |
|
37 | 37 | # Base classes and utilities |
|
38 | 38 | #------------------------------------------------------------------------------- |
|
39 | 39 | |
|
40 | 40 | class IMultiEngineBaseTestCase(object): |
|
41 | 41 | """Basic utilities for working with multiengine tests. |
|
42 | 42 | |
|
43 | 43 | Some subclass should define: |
|
44 | 44 | |
|
45 | 45 | * self.multiengine |
|
46 | 46 | * self.engines to keep track of engines for clean up""" |
|
47 | 47 | |
|
48 | 48 | def createShell(self): |
|
49 | 49 | return Interpreter() |
|
50 | 50 | |
|
51 | 51 | def addEngine(self, n=1): |
|
52 | 52 | for i in range(n): |
|
53 | 53 | e = es.EngineService() |
|
54 | 54 | e.startService() |
|
55 | 55 | regDict = self.controller.register_engine(es.QueuedEngine(e), None) |
|
56 | 56 | e.id = regDict['id'] |
|
57 | 57 | self.engines.append(e) |
|
58 | 58 | |
|
59 | 59 | |
|
60 | 60 | def testf(x): |
|
61 | 61 | return 2.0*x |
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | globala = 99 |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | def testg(x): |
|
68 | 68 | return globala*x |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | def isdid(did): |
|
72 | 72 | if not isinstance(did, str): |
|
73 | 73 | return False |
|
74 | 74 | if not len(did)==40: |
|
75 | 75 | return False |
|
76 | 76 | return True |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | def _raise_it(f): |
|
80 | 80 | try: |
|
81 | 81 | f.raiseException() |
|
82 | 82 | except CompositeError, e: |
|
83 | 83 | e.raise_exception() |
|
84 | 84 | |
|
85 | 85 | #------------------------------------------------------------------------------- |
|
86 | 86 | # IMultiEngineTestCase |
|
87 | 87 | #------------------------------------------------------------------------------- |
|
88 | 88 | |
|
89 | 89 | class IMultiEngineTestCase(IMultiEngineBaseTestCase): |
|
90 | 90 | """A test for any object that implements IEngineMultiplexer. |
|
91 | 91 | |
|
92 | 92 | self.multiengine must be defined and implement IEngineMultiplexer. |
|
93 | 93 | """ |
|
94 | 94 | |
|
95 | 95 | def testIMultiEngineInterface(self): |
|
96 | 96 | """Does self.engine claim to implement IEngineCore?""" |
|
97 | 97 | self.assert_(me.IEngineMultiplexer.providedBy(self.multiengine)) |
|
98 | 98 | self.assert_(me.IMultiEngine.providedBy(self.multiengine)) |
|
99 | 99 | |
|
100 | 100 | def testIEngineMultiplexerInterfaceMethods(self): |
|
101 | 101 | """Does self.engine have the methods and attributes in IEngineCore.""" |
|
102 | 102 | for m in list(me.IEngineMultiplexer): |
|
103 | 103 | self.assert_(hasattr(self.multiengine, m)) |
|
104 | 104 | |
|
105 | 105 | def testIEngineMultiplexerDeferreds(self): |
|
106 | 106 | self.addEngine(1) |
|
107 | 107 | d= self.multiengine.execute('a=5', targets=0) |
|
108 | 108 | d.addCallback(lambda _: self.multiengine.push(dict(a=5),targets=0)) |
|
109 | 109 | d.addCallback(lambda _: self.multiengine.push(dict(a=5, b='asdf', c=[1,2,3]),targets=0)) |
|
110 | 110 | d.addCallback(lambda _: self.multiengine.pull(('a','b','c'),targets=0)) |
|
111 | 111 | d.addCallback(lambda _: self.multiengine.get_result(targets=0)) |
|
112 | 112 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
113 | 113 | d.addCallback(lambda _: self.multiengine.keys(targets=0)) |
|
114 | 114 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(a=newserialized.serialize(10)),targets=0)) |
|
115 | 115 | d.addCallback(lambda _: self.multiengine.pull_serialized('a',targets=0)) |
|
116 | 116 | d.addCallback(lambda _: self.multiengine.clear_queue(targets=0)) |
|
117 | 117 | d.addCallback(lambda _: self.multiengine.queue_status(targets=0)) |
|
118 | 118 | return d |
|
119 | 119 | |
|
120 | 120 | def testInvalidEngineID(self): |
|
121 | 121 | self.addEngine(1) |
|
122 | 122 | badID = 100 |
|
123 | 123 | d = self.multiengine.execute('a=5', targets=badID) |
|
124 | 124 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
125 | 125 | d.addCallback(lambda _: self.multiengine.push(dict(a=5), targets=badID)) |
|
126 | 126 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
127 | 127 | d.addCallback(lambda _: self.multiengine.pull('a', targets=badID)) |
|
128 | 128 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
129 | 129 | d.addCallback(lambda _: self.multiengine.reset(targets=badID)) |
|
130 | 130 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
131 | 131 | d.addCallback(lambda _: self.multiengine.keys(targets=badID)) |
|
132 | 132 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
133 | 133 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(a=newserialized.serialize(10)), targets=badID)) |
|
134 | 134 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
135 | 135 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=badID)) |
|
136 | 136 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
137 | 137 | d.addCallback(lambda _: self.multiengine.queue_status(targets=badID)) |
|
138 | 138 | d.addErrback(lambda f: self.assertRaises(InvalidEngineID, f.raiseException)) |
|
139 | 139 | return d |
|
140 | 140 | |
|
141 | 141 | def testNoEnginesRegistered(self): |
|
142 | 142 | badID = 'all' |
|
143 | 143 | d= self.multiengine.execute('a=5', targets=badID) |
|
144 | 144 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
145 | 145 | d.addCallback(lambda _: self.multiengine.push(dict(a=5), targets=badID)) |
|
146 | 146 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
147 | 147 | d.addCallback(lambda _: self.multiengine.pull('a', targets=badID)) |
|
148 | 148 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
149 | 149 | d.addCallback(lambda _: self.multiengine.get_result(targets=badID)) |
|
150 | 150 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
151 | 151 | d.addCallback(lambda _: self.multiengine.reset(targets=badID)) |
|
152 | 152 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
153 | 153 | d.addCallback(lambda _: self.multiengine.keys(targets=badID)) |
|
154 | 154 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
155 | 155 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(a=newserialized.serialize(10)), targets=badID)) |
|
156 | 156 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
157 | 157 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=badID)) |
|
158 | 158 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
159 | 159 | d.addCallback(lambda _: self.multiengine.queue_status(targets=badID)) |
|
160 | 160 | d.addErrback(lambda f: self.assertRaises(NoEnginesRegistered, f.raiseException)) |
|
161 | 161 | return d |
|
162 | 162 | |
|
163 | 163 | def runExecuteAll(self, d, cmd, shell): |
|
164 | 164 | actual = shell.execute(cmd) |
|
165 | 165 | d.addCallback(lambda _: self.multiengine.execute(cmd)) |
|
166 | 166 | def compare(result): |
|
167 | 167 | for r in result: |
|
168 | 168 | actual['id'] = r['id'] |
|
169 | 169 | self.assertEquals(r, actual) |
|
170 | 170 | d.addCallback(compare) |
|
171 | 171 | |
|
172 | 172 | def testExecuteAll(self): |
|
173 | 173 | self.addEngine(4) |
|
174 | 174 | d= defer.Deferred() |
|
175 | 175 | shell = Interpreter() |
|
176 | 176 | for cmd in validCommands: |
|
177 | 177 | self.runExecuteAll(d, cmd, shell) |
|
178 | 178 | d.callback(None) |
|
179 | 179 | return d |
|
180 | 180 | |
|
181 | 181 | # The following two methods show how to do parametrized |
|
182 | 182 | # tests. This is really slick! Same is used above. |
|
183 | 183 | def runExecuteFailures(self, cmd, exc): |
|
184 | 184 | self.addEngine(4) |
|
185 | 185 | d= self.multiengine.execute(cmd) |
|
186 | 186 | d.addErrback(lambda f: self.assertRaises(exc, _raise_it, f)) |
|
187 | 187 | return d |
|
188 | 188 | |
|
189 | 189 | @parametric |
|
190 | 190 | def testExecuteFailures(cls): |
|
191 | 191 | return [(cls.runExecuteFailures,cmd,exc) for |
|
192 | 192 | cmd,exc in invalidCommands] |
|
193 | 193 | |
|
194 | 194 | def testPushPull(self): |
|
195 | 195 | self.addEngine(1) |
|
196 | 196 | objs = [10,"hi there",1.2342354,{"p":(1,2)}] |
|
197 | 197 | d= self.multiengine.push(dict(key=objs[0]), targets=0) |
|
198 | 198 | d.addCallback(lambda _: self.multiengine.pull('key', targets=0)) |
|
199 | 199 | d.addCallback(lambda r: self.assertEquals(r, [objs[0]])) |
|
200 | 200 | d.addCallback(lambda _: self.multiengine.push(dict(key=objs[1]), targets=0)) |
|
201 | 201 | d.addCallback(lambda _: self.multiengine.pull('key', targets=0)) |
|
202 | 202 | d.addCallback(lambda r: self.assertEquals(r, [objs[1]])) |
|
203 | 203 | d.addCallback(lambda _: self.multiengine.push(dict(key=objs[2]), targets=0)) |
|
204 | 204 | d.addCallback(lambda _: self.multiengine.pull('key', targets=0)) |
|
205 | 205 | d.addCallback(lambda r: self.assertEquals(r, [objs[2]])) |
|
206 | 206 | d.addCallback(lambda _: self.multiengine.push(dict(key=objs[3]), targets=0)) |
|
207 | 207 | d.addCallback(lambda _: self.multiengine.pull('key', targets=0)) |
|
208 | 208 | d.addCallback(lambda r: self.assertEquals(r, [objs[3]])) |
|
209 | 209 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
210 | 210 | d.addCallback(lambda _: self.multiengine.pull('a', targets=0)) |
|
211 | 211 | d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f)) |
|
212 | 212 | d.addCallback(lambda _: self.multiengine.push(dict(a=10,b=20))) |
|
213 | 213 | d.addCallback(lambda _: self.multiengine.pull(('a','b'))) |
|
214 | 214 | d.addCallback(lambda r: self.assertEquals(r, [[10,20]])) |
|
215 | 215 | return d |
|
216 | 216 | |
|
217 | 217 | def testPushPullAll(self): |
|
218 | 218 | self.addEngine(4) |
|
219 | 219 | d= self.multiengine.push(dict(a=10)) |
|
220 | 220 | d.addCallback(lambda _: self.multiengine.pull('a')) |
|
221 | 221 | d.addCallback(lambda r: self.assert_(r==[10,10,10,10])) |
|
222 | 222 | d.addCallback(lambda _: self.multiengine.push(dict(a=10, b=20))) |
|
223 | 223 | d.addCallback(lambda _: self.multiengine.pull(('a','b'))) |
|
224 | 224 | d.addCallback(lambda r: self.assert_(r==4*[[10,20]])) |
|
225 | 225 | d.addCallback(lambda _: self.multiengine.push(dict(a=10, b=20), targets=0)) |
|
226 | 226 | d.addCallback(lambda _: self.multiengine.pull(('a','b'), targets=0)) |
|
227 | 227 | d.addCallback(lambda r: self.assert_(r==[[10,20]])) |
|
228 | 228 | d.addCallback(lambda _: self.multiengine.push(dict(a=None, b=None), targets=0)) |
|
229 | 229 | d.addCallback(lambda _: self.multiengine.pull(('a','b'), targets=0)) |
|
230 | 230 | d.addCallback(lambda r: self.assert_(r==[[None,None]])) |
|
231 | 231 | return d |
|
232 | 232 | |
|
233 | 233 | def testPushPullSerialized(self): |
|
234 | 234 | self.addEngine(1) |
|
235 | 235 | objs = [10,"hi there",1.2342354,{"p":(1,2)}] |
|
236 | 236 | d= self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[0])), targets=0) |
|
237 | 237 | d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0)) |
|
238 | 238 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
239 | 239 | d.addCallback(lambda r: self.assertEquals(r, objs[0])) |
|
240 | 240 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[1])), targets=0)) |
|
241 | 241 | d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0)) |
|
242 | 242 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
243 | 243 | d.addCallback(lambda r: self.assertEquals(r, objs[1])) |
|
244 | 244 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[2])), targets=0)) |
|
245 | 245 | d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0)) |
|
246 | 246 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
247 | 247 | d.addCallback(lambda r: self.assertEquals(r, objs[2])) |
|
248 | 248 | d.addCallback(lambda _: self.multiengine.push_serialized(dict(key=newserialized.serialize(objs[3])), targets=0)) |
|
249 | 249 | d.addCallback(lambda _: self.multiengine.pull_serialized('key', targets=0)) |
|
250 | 250 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
251 | 251 | d.addCallback(lambda r: self.assertEquals(r, objs[3])) |
|
252 | 252 | d.addCallback(lambda _: self.multiengine.push(dict(a=10,b=range(5)), targets=0)) |
|
253 | 253 | d.addCallback(lambda _: self.multiengine.pull_serialized(('a','b'), targets=0)) |
|
254 | 254 | d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]]) |
|
255 | 255 | d.addCallback(lambda r: self.assertEquals(r, [10, range(5)])) |
|
256 | 256 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
257 | 257 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0)) |
|
258 | 258 | d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f)) |
|
259 | 259 | return d |
|
260 | 260 | |
|
261 | 261 | objs = [10,"hi there",1.2342354,{"p":(1,2)}] |
|
262 | 262 | d= defer.succeed(None) |
|
263 | 263 | for o in objs: |
|
264 | 264 | self.multiengine.push_serialized(0, key=newserialized.serialize(o)) |
|
265 | 265 | value = self.multiengine.pull_serialized(0, 'key') |
|
266 | 266 | value.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
267 | 267 | d = self.assertDeferredEquals(value,o,d) |
|
268 | 268 | return d |
|
269 | 269 | |
|
270 | 270 | def runGetResultAll(self, d, cmd, shell): |
|
271 | 271 | actual = shell.execute(cmd) |
|
272 | 272 | d.addCallback(lambda _: self.multiengine.execute(cmd)) |
|
273 | 273 | d.addCallback(lambda _: self.multiengine.get_result()) |
|
274 | 274 | def compare(result): |
|
275 | 275 | for r in result: |
|
276 | 276 | actual['id'] = r['id'] |
|
277 | 277 | self.assertEquals(r, actual) |
|
278 | 278 | d.addCallback(compare) |
|
279 | 279 | |
|
280 | 280 | def testGetResultAll(self): |
|
281 | 281 | self.addEngine(4) |
|
282 | 282 | d= defer.Deferred() |
|
283 | 283 | shell = Interpreter() |
|
284 | 284 | for cmd in validCommands: |
|
285 | 285 | self.runGetResultAll(d, cmd, shell) |
|
286 | 286 | d.callback(None) |
|
287 | 287 | return d |
|
288 | 288 | |
|
289 | 289 | def testGetResultDefault(self): |
|
290 | 290 | self.addEngine(1) |
|
291 | 291 | target = 0 |
|
292 | 292 | cmd = 'a=5' |
|
293 | 293 | shell = self.createShell() |
|
294 | 294 | shellResult = shell.execute(cmd) |
|
295 | 295 | def popit(dikt, key): |
|
296 | 296 | dikt.pop(key) |
|
297 | 297 | return dikt |
|
298 | 298 | d= self.multiengine.execute(cmd, targets=target) |
|
299 | 299 | d.addCallback(lambda _: self.multiengine.get_result(targets=target)) |
|
300 | 300 | d.addCallback(lambda r: self.assertEquals(shellResult, popit(r[0],'id'))) |
|
301 | 301 | return d |
|
302 | 302 | |
|
303 | 303 | def testGetResultFailure(self): |
|
304 | 304 | self.addEngine(1) |
|
305 | 305 | d= self.multiengine.get_result(None, targets=0) |
|
306 | 306 | d.addErrback(lambda f: self.assertRaises(IndexError, _raise_it, f)) |
|
307 | 307 | d.addCallback(lambda _: self.multiengine.get_result(10, targets=0)) |
|
308 | 308 | d.addErrback(lambda f: self.assertRaises(IndexError, _raise_it, f)) |
|
309 | 309 | return d |
|
310 | 310 | |
|
311 | 311 | def testPushFunction(self): |
|
312 | 312 | self.addEngine(1) |
|
313 | 313 | d= self.multiengine.push_function(dict(f=testf), targets=0) |
|
314 | 314 | d.addCallback(lambda _: self.multiengine.execute('result = f(10)', targets=0)) |
|
315 | 315 | d.addCallback(lambda _: self.multiengine.pull('result', targets=0)) |
|
316 | 316 | d.addCallback(lambda r: self.assertEquals(r[0], testf(10))) |
|
317 | 317 | d.addCallback(lambda _: self.multiengine.push(dict(globala=globala), targets=0)) |
|
318 | 318 | d.addCallback(lambda _: self.multiengine.push_function(dict(g=testg), targets=0)) |
|
319 | 319 | d.addCallback(lambda _: self.multiengine.execute('result = g(10)', targets=0)) |
|
320 | 320 | d.addCallback(lambda _: self.multiengine.pull('result', targets=0)) |
|
321 | 321 | d.addCallback(lambda r: self.assertEquals(r[0], testg(10))) |
|
322 | 322 | return d |
|
323 | 323 | |
|
324 | 324 | def testPullFunction(self): |
|
325 | 325 | self.addEngine(1) |
|
326 | 326 | d= self.multiengine.push(dict(a=globala), targets=0) |
|
327 | 327 | d.addCallback(lambda _: self.multiengine.push_function(dict(f=testf), targets=0)) |
|
328 | 328 | d.addCallback(lambda _: self.multiengine.pull_function('f', targets=0)) |
|
329 | 329 | d.addCallback(lambda r: self.assertEquals(r[0](10), testf(10))) |
|
330 | 330 | d.addCallback(lambda _: self.multiengine.execute("def g(x): return x*x", targets=0)) |
|
331 | 331 | d.addCallback(lambda _: self.multiengine.pull_function(('f','g'),targets=0)) |
|
332 | 332 | d.addCallback(lambda r: self.assertEquals((r[0][0](10),r[0][1](10)), (testf(10), 100))) |
|
333 | 333 | return d |
|
334 | 334 | |
|
335 | 335 | def testPushFunctionAll(self): |
|
336 | 336 | self.addEngine(4) |
|
337 | 337 | d= self.multiengine.push_function(dict(f=testf)) |
|
338 | 338 | d.addCallback(lambda _: self.multiengine.execute('result = f(10)')) |
|
339 | 339 | d.addCallback(lambda _: self.multiengine.pull('result')) |
|
340 | 340 | d.addCallback(lambda r: self.assertEquals(r, 4*[testf(10)])) |
|
341 | 341 | d.addCallback(lambda _: self.multiengine.push(dict(globala=globala))) |
|
342 | 342 | d.addCallback(lambda _: self.multiengine.push_function(dict(testg=testg))) |
|
343 | 343 | d.addCallback(lambda _: self.multiengine.execute('result = testg(10)')) |
|
344 | 344 | d.addCallback(lambda _: self.multiengine.pull('result')) |
|
345 | 345 | d.addCallback(lambda r: self.assertEquals(r, 4*[testg(10)])) |
|
346 | 346 | return d |
|
347 | 347 | |
|
348 | 348 | def testPullFunctionAll(self): |
|
349 | 349 | self.addEngine(4) |
|
350 | 350 | d= self.multiengine.push_function(dict(f=testf)) |
|
351 | 351 | d.addCallback(lambda _: self.multiengine.pull_function('f')) |
|
352 | 352 | d.addCallback(lambda r: self.assertEquals([func(10) for func in r], 4*[testf(10)])) |
|
353 | 353 | return d |
|
354 | 354 | |
|
355 | 355 | def testGetIDs(self): |
|
356 | 356 | self.addEngine(1) |
|
357 | 357 | d= self.multiengine.get_ids() |
|
358 | 358 | d.addCallback(lambda r: self.assertEquals(r, [0])) |
|
359 | 359 | d.addCallback(lambda _: self.addEngine(3)) |
|
360 | 360 | d.addCallback(lambda _: self.multiengine.get_ids()) |
|
361 | 361 | d.addCallback(lambda r: self.assertEquals(r, [0,1,2,3])) |
|
362 | 362 | return d |
|
363 | 363 | |
|
364 | 364 | def testClearQueue(self): |
|
365 | 365 | self.addEngine(4) |
|
366 | 366 | d= self.multiengine.clear_queue() |
|
367 | 367 | d.addCallback(lambda r: self.assertEquals(r,4*[None])) |
|
368 | 368 | return d |
|
369 | 369 | |
|
370 | 370 | def testQueueStatus(self): |
|
371 | 371 | self.addEngine(4) |
|
372 | 372 | d= self.multiengine.queue_status(targets=0) |
|
373 | 373 | d.addCallback(lambda r: self.assert_(isinstance(r[0],tuple))) |
|
374 | 374 | return d |
|
375 | 375 | |
|
376 | 376 | def testGetSetProperties(self): |
|
377 | 377 | self.addEngine(4) |
|
378 | 378 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
379 | 379 | d= self.multiengine.set_properties(dikt) |
|
380 | 380 | d.addCallback(lambda r: self.multiengine.get_properties()) |
|
381 | 381 | d.addCallback(lambda r: self.assertEquals(r, 4*[dikt])) |
|
382 | 382 | d.addCallback(lambda r: self.multiengine.get_properties(('c',))) |
|
383 | 383 | d.addCallback(lambda r: self.assertEquals(r, 4*[{'c': dikt['c']}])) |
|
384 | 384 | d.addCallback(lambda r: self.multiengine.set_properties(dict(c=False))) |
|
385 | 385 | d.addCallback(lambda r: self.multiengine.get_properties(('c', 'd'))) |
|
386 | 386 | d.addCallback(lambda r: self.assertEquals(r, 4*[dict(c=False, d=None)])) |
|
387 | 387 | return d |
|
388 | 388 | |
|
389 | 389 | def testClearProperties(self): |
|
390 | 390 | self.addEngine(4) |
|
391 | 391 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
392 | 392 | d= self.multiengine.set_properties(dikt) |
|
393 | 393 | d.addCallback(lambda r: self.multiengine.clear_properties()) |
|
394 | 394 | d.addCallback(lambda r: self.multiengine.get_properties()) |
|
395 | 395 | d.addCallback(lambda r: self.assertEquals(r, 4*[{}])) |
|
396 | 396 | return d |
|
397 | 397 | |
|
398 | 398 | def testDelHasProperties(self): |
|
399 | 399 | self.addEngine(4) |
|
400 | 400 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
401 | 401 | d= self.multiengine.set_properties(dikt) |
|
402 | 402 | d.addCallback(lambda r: self.multiengine.del_properties(('b','e'))) |
|
403 | 403 | d.addCallback(lambda r: self.multiengine.has_properties(('a','b','c','d','e'))) |
|
404 | 404 | d.addCallback(lambda r: self.assertEquals(r, 4*[[True, False, True, True, False]])) |
|
405 | 405 | return d |
|
406 | 406 | |
|
407 | 407 | Parametric(IMultiEngineTestCase) |
|
408 | 408 | |
|
409 | 409 | #------------------------------------------------------------------------------- |
|
410 | 410 | # ISynchronousMultiEngineTestCase |
|
411 | 411 | #------------------------------------------------------------------------------- |
|
412 | 412 | |
|
413 | 413 | class ISynchronousMultiEngineTestCase(IMultiEngineBaseTestCase): |
|
414 | 414 | |
|
415 | 415 | def testISynchronousMultiEngineInterface(self): |
|
416 | 416 | """Does self.engine claim to implement IEngineCore?""" |
|
417 | 417 | self.assert_(me.ISynchronousEngineMultiplexer.providedBy(self.multiengine)) |
|
418 | 418 | self.assert_(me.ISynchronousMultiEngine.providedBy(self.multiengine)) |
|
419 | 419 | |
|
420 | 420 | def testExecute(self): |
|
421 | 421 | self.addEngine(4) |
|
422 | 422 | execute = self.multiengine.execute |
|
423 | 423 | d= execute('a=5', targets=0, block=True) |
|
424 | 424 | d.addCallback(lambda r: self.assert_(len(r)==1)) |
|
425 | 425 | d.addCallback(lambda _: execute('b=10')) |
|
426 | 426 | d.addCallback(lambda r: self.assert_(len(r)==4)) |
|
427 | 427 | d.addCallback(lambda _: execute('c=30', block=False)) |
|
428 | 428 | d.addCallback(lambda did: self.assert_(isdid(did))) |
|
429 | 429 | d.addCallback(lambda _: execute('d=[0,1,2]', block=False)) |
|
430 | 430 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
431 | 431 | d.addCallback(lambda r: self.assert_(len(r)==4)) |
|
432 | 432 | return d |
|
433 | 433 | |
|
434 | 434 | def testPushPull(self): |
|
435 | 435 | data = dict(a=10, b=1.05, c=range(10), d={'e':(1,2),'f':'hi'}) |
|
436 | 436 | self.addEngine(4) |
|
437 | 437 | push = self.multiengine.push |
|
438 | 438 | pull = self.multiengine.pull |
|
439 | 439 | d= push({'data':data}, targets=0) |
|
440 | 440 | d.addCallback(lambda r: pull('data', targets=0)) |
|
441 | 441 | d.addCallback(lambda r: self.assertEqual(r,[data])) |
|
442 | 442 | d.addCallback(lambda _: push({'data':data})) |
|
443 | 443 | d.addCallback(lambda r: pull('data')) |
|
444 | 444 | d.addCallback(lambda r: self.assertEqual(r,4*[data])) |
|
445 | 445 | d.addCallback(lambda _: push({'data':data}, block=False)) |
|
446 | 446 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
447 | 447 | d.addCallback(lambda _: pull('data', block=False)) |
|
448 | 448 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
449 | 449 | d.addCallback(lambda r: self.assertEqual(r,4*[data])) |
|
450 | 450 | d.addCallback(lambda _: push(dict(a=10,b=20))) |
|
451 | 451 | d.addCallback(lambda _: pull(('a','b'))) |
|
452 | 452 | d.addCallback(lambda r: self.assertEquals(r, 4*[[10,20]])) |
|
453 | 453 | return d |
|
454 | 454 | |
|
455 | 455 | def testPushPullFunction(self): |
|
456 | 456 | self.addEngine(4) |
|
457 | 457 | pushf = self.multiengine.push_function |
|
458 | 458 | pullf = self.multiengine.pull_function |
|
459 | 459 | push = self.multiengine.push |
|
460 | 460 | pull = self.multiengine.pull |
|
461 | 461 | execute = self.multiengine.execute |
|
462 | 462 | d= pushf({'testf':testf}, targets=0) |
|
463 | 463 | d.addCallback(lambda r: pullf('testf', targets=0)) |
|
464 | 464 | d.addCallback(lambda r: self.assertEqual(r[0](1.0), testf(1.0))) |
|
465 | 465 | d.addCallback(lambda _: execute('r = testf(10)', targets=0)) |
|
466 | 466 | d.addCallback(lambda _: pull('r', targets=0)) |
|
467 | 467 | d.addCallback(lambda r: self.assertEquals(r[0], testf(10))) |
|
468 | 468 | d.addCallback(lambda _: pushf({'testf':testf}, block=False)) |
|
469 | 469 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
470 | 470 | d.addCallback(lambda _: pullf('testf', block=False)) |
|
471 | 471 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
472 | 472 | d.addCallback(lambda r: self.assertEqual(r[0](1.0), testf(1.0))) |
|
473 | 473 | d.addCallback(lambda _: execute("def g(x): return x*x", targets=0)) |
|
474 | 474 | d.addCallback(lambda _: pullf(('testf','g'),targets=0)) |
|
475 | 475 | d.addCallback(lambda r: self.assertEquals((r[0][0](10),r[0][1](10)), (testf(10), 100))) |
|
476 | 476 | return d |
|
477 | 477 | |
|
478 | 478 | def testGetResult(self): |
|
479 | 479 | shell = Interpreter() |
|
480 | 480 | result1 = shell.execute('a=10') |
|
481 | 481 | result1['id'] = 0 |
|
482 | 482 | result2 = shell.execute('b=20') |
|
483 | 483 | result2['id'] = 0 |
|
484 | 484 | execute= self.multiengine.execute |
|
485 | 485 | get_result = self.multiengine.get_result |
|
486 | 486 | self.addEngine(1) |
|
487 | 487 | d= execute('a=10') |
|
488 | 488 | d.addCallback(lambda _: get_result()) |
|
489 | 489 | d.addCallback(lambda r: self.assertEquals(r[0], result1)) |
|
490 | 490 | d.addCallback(lambda _: execute('b=20')) |
|
491 | 491 | d.addCallback(lambda _: get_result(1)) |
|
492 | 492 | d.addCallback(lambda r: self.assertEquals(r[0], result1)) |
|
493 | 493 | d.addCallback(lambda _: get_result(2, block=False)) |
|
494 | 494 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
495 | 495 | d.addCallback(lambda r: self.assertEquals(r[0], result2)) |
|
496 | 496 | return d |
|
497 | 497 | |
|
498 | 498 | def testResetAndKeys(self): |
|
499 | 499 | self.addEngine(1) |
|
500 | 500 | |
|
501 | 501 | #Blocking mode |
|
502 | 502 | d= self.multiengine.push(dict(a=10, b=20, c=range(10)), targets=0) |
|
503 | 503 | d.addCallback(lambda _: self.multiengine.keys(targets=0)) |
|
504 | 504 | def keys_found(keys): |
|
505 | 505 | self.assert_('a' in keys[0]) |
|
506 | 506 | self.assert_('b' in keys[0]) |
|
507 | 507 | self.assert_('b' in keys[0]) |
|
508 | 508 | d.addCallback(keys_found) |
|
509 | 509 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
510 | 510 | d.addCallback(lambda _: self.multiengine.keys(targets=0)) |
|
511 | 511 | def keys_not_found(keys): |
|
512 | 512 | self.assert_('a' not in keys[0]) |
|
513 | 513 | self.assert_('b' not in keys[0]) |
|
514 | 514 | self.assert_('b' not in keys[0]) |
|
515 | 515 | d.addCallback(keys_not_found) |
|
516 | 516 | |
|
517 | 517 | #Non-blocking mode |
|
518 | 518 | d.addCallback(lambda _: self.multiengine.push(dict(a=10, b=20, c=range(10)), targets=0)) |
|
519 | 519 | d.addCallback(lambda _: self.multiengine.keys(targets=0, block=False)) |
|
520 | 520 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
521 | 521 | def keys_found(keys): |
|
522 | 522 | self.assert_('a' in keys[0]) |
|
523 | 523 | self.assert_('b' in keys[0]) |
|
524 | 524 | self.assert_('b' in keys[0]) |
|
525 | 525 | d.addCallback(keys_found) |
|
526 | 526 | d.addCallback(lambda _: self.multiengine.reset(targets=0, block=False)) |
|
527 | 527 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
528 | 528 | d.addCallback(lambda _: self.multiengine.keys(targets=0, block=False)) |
|
529 | 529 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
530 | 530 | def keys_not_found(keys): |
|
531 | 531 | self.assert_('a' not in keys[0]) |
|
532 | 532 | self.assert_('b' not in keys[0]) |
|
533 | 533 | self.assert_('b' not in keys[0]) |
|
534 | 534 | d.addCallback(keys_not_found) |
|
535 | 535 | |
|
536 | 536 | return d |
|
537 | 537 | |
|
538 | 538 | def testPushPullSerialized(self): |
|
539 | 539 | self.addEngine(1) |
|
540 | 540 | dikt = dict(a=10,b='hi there',c=1.2345,d={'p':(1,2)}) |
|
541 | 541 | sdikt = {} |
|
542 | 542 | for k,v in dikt.iteritems(): |
|
543 | 543 | sdikt[k] = newserialized.serialize(v) |
|
544 | 544 | d= self.multiengine.push_serialized(dict(a=sdikt['a']), targets=0) |
|
545 | 545 | d.addCallback(lambda _: self.multiengine.pull('a',targets=0)) |
|
546 | 546 | d.addCallback(lambda r: self.assertEquals(r[0], dikt['a'])) |
|
547 | 547 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0)) |
|
548 | 548 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
549 | 549 | d.addCallback(lambda r: self.assertEquals(r, dikt['a'])) |
|
550 | 550 | d.addCallback(lambda _: self.multiengine.push_serialized(sdikt, targets=0)) |
|
551 | 551 | d.addCallback(lambda _: self.multiengine.pull_serialized(sdikt.keys(), targets=0)) |
|
552 | 552 | d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]]) |
|
553 | 553 | d.addCallback(lambda r: self.assertEquals(r, dikt.values())) |
|
554 | 554 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
555 | 555 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0)) |
|
556 | 556 | d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f)) |
|
557 | 557 | |
|
558 | 558 | #Non-blocking mode |
|
559 | 559 | d.addCallback(lambda r: self.multiengine.push_serialized(dict(a=sdikt['a']), targets=0, block=False)) |
|
560 | 560 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
561 | 561 | d.addCallback(lambda _: self.multiengine.pull('a',targets=0)) |
|
562 | 562 | d.addCallback(lambda r: self.assertEquals(r[0], dikt['a'])) |
|
563 | 563 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0, block=False)) |
|
564 | 564 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
565 | 565 | d.addCallback(lambda serial: newserialized.IUnSerialized(serial[0]).getObject()) |
|
566 | 566 | d.addCallback(lambda r: self.assertEquals(r, dikt['a'])) |
|
567 | 567 | d.addCallback(lambda _: self.multiengine.push_serialized(sdikt, targets=0, block=False)) |
|
568 | 568 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
569 | 569 | d.addCallback(lambda _: self.multiengine.pull_serialized(sdikt.keys(), targets=0, block=False)) |
|
570 | 570 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
571 | 571 | d.addCallback(lambda serial: [newserialized.IUnSerialized(s).getObject() for s in serial[0]]) |
|
572 | 572 | d.addCallback(lambda r: self.assertEquals(r, dikt.values())) |
|
573 | 573 | d.addCallback(lambda _: self.multiengine.reset(targets=0)) |
|
574 | 574 | d.addCallback(lambda _: self.multiengine.pull_serialized('a', targets=0, block=False)) |
|
575 | 575 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
576 | 576 | d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f)) |
|
577 | 577 | return d |
|
578 | 578 | |
|
579 | 579 | def testClearQueue(self): |
|
580 | 580 | self.addEngine(4) |
|
581 | 581 | d= self.multiengine.clear_queue() |
|
582 | 582 | d.addCallback(lambda r: self.multiengine.clear_queue(block=False)) |
|
583 | 583 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
584 | 584 | d.addCallback(lambda r: self.assertEquals(r,4*[None])) |
|
585 | 585 | return d |
|
586 | 586 | |
|
587 | 587 | def testQueueStatus(self): |
|
588 | 588 | self.addEngine(4) |
|
589 | 589 | d= self.multiengine.queue_status(targets=0) |
|
590 | 590 | d.addCallback(lambda r: self.assert_(isinstance(r[0],tuple))) |
|
591 | 591 | d.addCallback(lambda r: self.multiengine.queue_status(targets=0, block=False)) |
|
592 | 592 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
593 | 593 | d.addCallback(lambda r: self.assert_(isinstance(r[0],tuple))) |
|
594 | 594 | return d |
|
595 | 595 | |
|
596 | 596 | def testGetIDs(self): |
|
597 | 597 | self.addEngine(1) |
|
598 | 598 | d= self.multiengine.get_ids() |
|
599 | 599 | d.addCallback(lambda r: self.assertEquals(r, [0])) |
|
600 | 600 | d.addCallback(lambda _: self.addEngine(3)) |
|
601 | 601 | d.addCallback(lambda _: self.multiengine.get_ids()) |
|
602 | 602 | d.addCallback(lambda r: self.assertEquals(r, [0,1,2,3])) |
|
603 | 603 | return d |
|
604 | 604 | |
|
605 | 605 | def testGetSetProperties(self): |
|
606 | 606 | self.addEngine(4) |
|
607 | 607 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
608 | 608 | d= self.multiengine.set_properties(dikt) |
|
609 | 609 | d.addCallback(lambda r: self.multiengine.get_properties()) |
|
610 | 610 | d.addCallback(lambda r: self.assertEquals(r, 4*[dikt])) |
|
611 | 611 | d.addCallback(lambda r: self.multiengine.get_properties(('c',))) |
|
612 | 612 | d.addCallback(lambda r: self.assertEquals(r, 4*[{'c': dikt['c']}])) |
|
613 | 613 | d.addCallback(lambda r: self.multiengine.set_properties(dict(c=False))) |
|
614 | 614 | d.addCallback(lambda r: self.multiengine.get_properties(('c', 'd'))) |
|
615 | 615 | d.addCallback(lambda r: self.assertEquals(r, 4*[dict(c=False, d=None)])) |
|
616 | 616 | |
|
617 | 617 | #Non-blocking |
|
618 | 618 | d.addCallback(lambda r: self.multiengine.set_properties(dikt, block=False)) |
|
619 | 619 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
620 | 620 | d.addCallback(lambda r: self.multiengine.get_properties(block=False)) |
|
621 | 621 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
622 | 622 | d.addCallback(lambda r: self.assertEquals(r, 4*[dikt])) |
|
623 | 623 | d.addCallback(lambda r: self.multiengine.get_properties(('c',), block=False)) |
|
624 | 624 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
625 | 625 | d.addCallback(lambda r: self.assertEquals(r, 4*[{'c': dikt['c']}])) |
|
626 | 626 | d.addCallback(lambda r: self.multiengine.set_properties(dict(c=False), block=False)) |
|
627 | 627 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
628 | 628 | d.addCallback(lambda r: self.multiengine.get_properties(('c', 'd'), block=False)) |
|
629 | 629 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
630 | 630 | d.addCallback(lambda r: self.assertEquals(r, 4*[dict(c=False, d=None)])) |
|
631 | 631 | return d |
|
632 | 632 | |
|
633 | 633 | def testClearProperties(self): |
|
634 | 634 | self.addEngine(4) |
|
635 | 635 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
636 | 636 | d= self.multiengine.set_properties(dikt) |
|
637 | 637 | d.addCallback(lambda r: self.multiengine.clear_properties()) |
|
638 | 638 | d.addCallback(lambda r: self.multiengine.get_properties()) |
|
639 | 639 | d.addCallback(lambda r: self.assertEquals(r, 4*[{}])) |
|
640 | 640 | |
|
641 | 641 | #Non-blocking |
|
642 | 642 | d.addCallback(lambda r: self.multiengine.set_properties(dikt, block=False)) |
|
643 | 643 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
644 | 644 | d.addCallback(lambda r: self.multiengine.clear_properties(block=False)) |
|
645 | 645 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
646 | 646 | d.addCallback(lambda r: self.multiengine.get_properties(block=False)) |
|
647 | 647 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
648 | 648 | d.addCallback(lambda r: self.assertEquals(r, 4*[{}])) |
|
649 | 649 | return d |
|
650 | 650 | |
|
651 | 651 | def testDelHasProperties(self): |
|
652 | 652 | self.addEngine(4) |
|
653 | 653 | dikt = dict(a=5, b='asdf', c=True, d=None, e=range(5)) |
|
654 | 654 | d= self.multiengine.set_properties(dikt) |
|
655 | 655 | d.addCallback(lambda r: self.multiengine.del_properties(('b','e'))) |
|
656 | 656 | d.addCallback(lambda r: self.multiengine.has_properties(('a','b','c','d','e'))) |
|
657 | 657 | d.addCallback(lambda r: self.assertEquals(r, 4*[[True, False, True, True, False]])) |
|
658 | 658 | |
|
659 | 659 | #Non-blocking |
|
660 | 660 | d.addCallback(lambda r: self.multiengine.set_properties(dikt, block=False)) |
|
661 | 661 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
662 | 662 | d.addCallback(lambda r: self.multiengine.del_properties(('b','e'), block=False)) |
|
663 | 663 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
664 | 664 | d.addCallback(lambda r: self.multiengine.has_properties(('a','b','c','d','e'), block=False)) |
|
665 | 665 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
666 | 666 | d.addCallback(lambda r: self.assertEquals(r, 4*[[True, False, True, True, False]])) |
|
667 | 667 | return d |
|
668 | 668 | |
|
669 | 669 | def test_clear_pending_deferreds(self): |
|
670 | 670 | self.addEngine(4) |
|
671 | 671 | did_list = [] |
|
672 | 672 | d= self.multiengine.execute('a=10',block=False) |
|
673 | 673 | d.addCallback(lambda did: did_list.append(did)) |
|
674 | 674 | d.addCallback(lambda _: self.multiengine.push(dict(b=10),block=False)) |
|
675 | 675 | d.addCallback(lambda did: did_list.append(did)) |
|
676 | 676 | d.addCallback(lambda _: self.multiengine.pull(('a','b'),block=False)) |
|
677 | 677 | d.addCallback(lambda did: did_list.append(did)) |
|
678 | 678 | d.addCallback(lambda _: self.multiengine.clear_pending_deferreds()) |
|
679 | 679 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[0],True)) |
|
680 | 680 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
681 | 681 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[1],True)) |
|
682 | 682 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
683 | 683 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[2],True)) |
|
684 | 684 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
685 | 685 | return d |
|
686 | 686 | |
|
687 | 687 | #------------------------------------------------------------------------------- |
|
688 | 688 | # Coordinator test cases |
|
689 | 689 | #------------------------------------------------------------------------------- |
|
690 | 690 | |
|
691 | 691 | class IMultiEngineCoordinatorTestCase(object): |
|
692 | 692 | |
|
693 | 693 | def testScatterGather(self): |
|
694 | 694 | self.addEngine(4) |
|
695 | 695 | d= self.multiengine.scatter('a', range(16)) |
|
696 | 696 | d.addCallback(lambda r: self.multiengine.gather('a')) |
|
697 | 697 | d.addCallback(lambda r: self.assertEquals(r, range(16))) |
|
698 | 698 | d.addCallback(lambda _: self.multiengine.gather('asdf')) |
|
699 | 699 | d.addErrback(lambda f: self.assertRaises(NameError, _raise_it, f)) |
|
700 | 700 | return d |
|
701 | 701 | |
|
702 | 702 | def testScatterGatherNumpy(self): |
|
703 | 703 | try: |
|
704 | 704 | import numpy |
|
705 | 705 | from numpy.testing.utils import assert_array_equal, assert_array_almost_equal |
|
706 | 706 | except: |
|
707 | 707 | return |
|
708 | 708 | else: |
|
709 | 709 | self.addEngine(4) |
|
710 | 710 | a = numpy.arange(16) |
|
711 | 711 | d = self.multiengine.scatter('a', a) |
|
712 | 712 | d.addCallback(lambda r: self.multiengine.gather('a')) |
|
713 | 713 | d.addCallback(lambda r: assert_array_equal(r, a)) |
|
714 | 714 | return d |
|
715 | 715 | |
|
716 | 716 | def testMap(self): |
|
717 | 717 | self.addEngine(4) |
|
718 | 718 | def f(x): |
|
719 | 719 | return x**2 |
|
720 | 720 | data = range(16) |
|
721 | 721 | d= self.multiengine.map(f, data) |
|
722 | 722 | d.addCallback(lambda r: self.assertEquals(r,[f(x) for x in data])) |
|
723 | 723 | return d |
|
724 | 724 | |
|
725 | 725 | |
|
726 | 726 | class ISynchronousMultiEngineCoordinatorTestCase(IMultiEngineCoordinatorTestCase): |
|
727 | 727 | |
|
728 | 728 | def testScatterGatherNonblocking(self): |
|
729 | 729 | self.addEngine(4) |
|
730 | 730 | d= self.multiengine.scatter('a', range(16), block=False) |
|
731 | 731 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
732 | 732 | d.addCallback(lambda r: self.multiengine.gather('a', block=False)) |
|
733 | 733 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
734 | 734 | d.addCallback(lambda r: self.assertEquals(r, range(16))) |
|
735 | 735 | return d |
|
736 | 736 | |
|
737 | 737 | def testScatterGatherNumpyNonblocking(self): |
|
738 | 738 | try: |
|
739 | 739 | import numpy |
|
740 | 740 | from numpy.testing.utils import assert_array_equal, assert_array_almost_equal |
|
741 | 741 | except: |
|
742 | 742 | return |
|
743 | 743 | else: |
|
744 | 744 | self.addEngine(4) |
|
745 | 745 | a = numpy.arange(16) |
|
746 | 746 | d = self.multiengine.scatter('a', a, block=False) |
|
747 | 747 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
748 | 748 | d.addCallback(lambda r: self.multiengine.gather('a', block=False)) |
|
749 | 749 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
750 | 750 | d.addCallback(lambda r: assert_array_equal(r, a)) |
|
751 | 751 | return d |
|
752 | 752 | |
|
753 | 753 | def testMapNonblocking(self): |
|
754 | 754 | self.addEngine(4) |
|
755 | 755 | def f(x): |
|
756 | 756 | return x**2 |
|
757 | 757 | data = range(16) |
|
758 | 758 | d= self.multiengine.map(f, data, block=False) |
|
759 | 759 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
760 | 760 | d.addCallback(lambda r: self.assertEquals(r,[f(x) for x in data])) |
|
761 | 761 | return d |
|
762 | 762 | |
|
763 | 763 | def test_clear_pending_deferreds(self): |
|
764 | 764 | self.addEngine(4) |
|
765 | 765 | did_list = [] |
|
766 | 766 | d= self.multiengine.scatter('a',range(16),block=False) |
|
767 | 767 | d.addCallback(lambda did: did_list.append(did)) |
|
768 | 768 | d.addCallback(lambda _: self.multiengine.gather('a',block=False)) |
|
769 | 769 | d.addCallback(lambda did: did_list.append(did)) |
|
770 | 770 | d.addCallback(lambda _: self.multiengine.map(lambda x: x, range(16),block=False)) |
|
771 | 771 | d.addCallback(lambda did: did_list.append(did)) |
|
772 | 772 | d.addCallback(lambda _: self.multiengine.clear_pending_deferreds()) |
|
773 | 773 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[0],True)) |
|
774 | 774 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
775 | 775 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[1],True)) |
|
776 | 776 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
777 | 777 | d.addCallback(lambda _: self.multiengine.get_pending_deferred(did_list[2],True)) |
|
778 | 778 | d.addErrback(lambda f: self.assertRaises(InvalidDeferredID, f.raiseException)) |
|
779 | 779 | return d |
|
780 | 780 | |
|
781 | 781 | #------------------------------------------------------------------------------- |
|
782 | 782 | # Extras test cases |
|
783 | 783 | #------------------------------------------------------------------------------- |
|
784 | 784 | |
|
785 | 785 | class IMultiEngineExtrasTestCase(object): |
|
786 | 786 | |
|
787 | 787 | def testZipPull(self): |
|
788 | 788 | self.addEngine(4) |
|
789 | 789 | d= self.multiengine.push(dict(a=10,b=20)) |
|
790 | 790 | d.addCallback(lambda r: self.multiengine.zip_pull(('a','b'))) |
|
791 | 791 | d.addCallback(lambda r: self.assert_(r, [4*[10],4*[20]])) |
|
792 | 792 | return d |
|
793 | 793 | |
|
794 | 794 | def testRun(self): |
|
795 | 795 | self.addEngine(4) |
|
796 | 796 | import tempfile |
|
797 | 797 | fname = tempfile.mktemp('foo.py') |
|
798 | 798 | f= open(fname, 'w') |
|
799 | 799 | f.write('a = 10\nb=30') |
|
800 | 800 | f.close() |
|
801 | 801 | d= self.multiengine.run(fname) |
|
802 | 802 | d.addCallback(lambda r: self.multiengine.pull(('a','b'))) |
|
803 | 803 | d.addCallback(lambda r: self.assertEquals(r, 4*[[10,30]])) |
|
804 | 804 | return d |
|
805 | 805 | |
|
806 | 806 | |
|
807 | 807 | class ISynchronousMultiEngineExtrasTestCase(IMultiEngineExtrasTestCase): |
|
808 | 808 | |
|
809 | 809 | def testZipPullNonblocking(self): |
|
810 | 810 | self.addEngine(4) |
|
811 | 811 | d= self.multiengine.push(dict(a=10,b=20)) |
|
812 | 812 | d.addCallback(lambda r: self.multiengine.zip_pull(('a','b'), block=False)) |
|
813 | 813 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
814 | 814 | d.addCallback(lambda r: self.assert_(r, [4*[10],4*[20]])) |
|
815 | 815 | return d |
|
816 | 816 | |
|
817 | 817 | def testRunNonblocking(self): |
|
818 | 818 | self.addEngine(4) |
|
819 | 819 | import tempfile |
|
820 | 820 | fname = tempfile.mktemp('foo.py') |
|
821 | 821 | f= open(fname, 'w') |
|
822 | 822 | f.write('a = 10\nb=30') |
|
823 | 823 | f.close() |
|
824 | 824 | d= self.multiengine.run(fname, block=False) |
|
825 | 825 | d.addCallback(lambda did: self.multiengine.get_pending_deferred(did, True)) |
|
826 | 826 | d.addCallback(lambda r: self.multiengine.pull(('a','b'))) |
|
827 | 827 | d.addCallback(lambda r: self.assertEquals(r, 4*[[10,30]])) |
|
828 | 828 | return d |
|
829 | 829 | |
|
830 | 830 | |
|
831 | 831 | #------------------------------------------------------------------------------- |
|
832 | 832 | # IFullSynchronousMultiEngineTestCase |
|
833 | 833 | #------------------------------------------------------------------------------- |
|
834 | 834 | |
|
835 | 835 | class IFullSynchronousMultiEngineTestCase(ISynchronousMultiEngineTestCase, |
|
836 | 836 | ISynchronousMultiEngineCoordinatorTestCase, |
|
837 | 837 | ISynchronousMultiEngineExtrasTestCase): |
|
838 | 838 | pass |
@@ -1,40 +1,40 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the kernel.engineservice.py module. |
|
4 | 4 | |
|
5 | 5 | Things that should be tested: |
|
6 | 6 | |
|
7 | 7 | - Should the EngineService return Deferred objects? |
|
8 | 8 | - Run the same tests that are run in shell.py. |
|
9 | 9 | - Make sure that the Interface is really implemented. |
|
10 | 10 | - The startService and stopService methods. |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | from twisted.application.service import IService |
|
27 | 27 | from IPython.kernel.controllerservice import ControllerService |
|
28 | 28 | from IPython.kernel.tests import multienginetest as met |
|
29 | 29 | from controllertest import IControllerCoreTestCase |
|
30 |
from IPython.test |
|
|
30 | from IPython.testing.util import DeferredTestCase | |
|
31 | 31 | |
|
32 | 32 | class BasicControllerServiceTest(DeferredTestCase, |
|
33 | 33 | IControllerCoreTestCase): |
|
34 | 34 | |
|
35 | 35 | def setUp(self): |
|
36 | 36 | self.controller = ControllerService() |
|
37 | 37 | self.controller.startService() |
|
38 | 38 | |
|
39 | 39 | def tearDown(self): |
|
40 | 40 | self.controller.stopService() |
@@ -1,89 +1,89 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the enginepb.py module.""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | from twisted.python import components |
|
20 | 20 | from twisted.internet import reactor, defer |
|
21 | 21 | from twisted.spread import pb |
|
22 | 22 | from twisted.internet.base import DelayedCall |
|
23 | 23 | DelayedCall.debug = True |
|
24 | 24 | |
|
25 | 25 | import zope.interface as zi |
|
26 | 26 | |
|
27 | 27 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
28 | 28 | from IPython.kernel import engineservice as es |
|
29 |
from IPython.test |
|
|
29 | from IPython.testing.util import DeferredTestCase | |
|
30 | 30 | from IPython.kernel.controllerservice import IControllerBase |
|
31 | 31 | from IPython.kernel.enginefc import FCRemoteEngineRefFromService, IEngineBase |
|
32 | 32 | from IPython.kernel.engineservice import IEngineQueued |
|
33 | 33 | from IPython.kernel.engineconnector import EngineConnector |
|
34 | 34 | |
|
35 | 35 | from IPython.kernel.tests.engineservicetest import \ |
|
36 | 36 | IEngineCoreTestCase, \ |
|
37 | 37 | IEngineSerializedTestCase, \ |
|
38 | 38 | IEngineQueuedTestCase |
|
39 | 39 | |
|
40 | 40 | class EngineFCTest(DeferredTestCase, |
|
41 | 41 | IEngineCoreTestCase, |
|
42 | 42 | IEngineSerializedTestCase, |
|
43 | 43 | IEngineQueuedTestCase |
|
44 | 44 | ): |
|
45 | 45 | |
|
46 | 46 | zi.implements(IControllerBase) |
|
47 | 47 | |
|
48 | 48 | def setUp(self): |
|
49 | 49 | |
|
50 | 50 | # Start a server and append to self.servers |
|
51 | 51 | self.controller_reference = FCRemoteEngineRefFromService(self) |
|
52 | 52 | self.controller_tub = Tub() |
|
53 | 53 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
54 | 54 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
55 | 55 | |
|
56 | 56 | furl = self.controller_tub.registerReference(self.controller_reference) |
|
57 | 57 | self.controller_tub.startService() |
|
58 | 58 | |
|
59 | 59 | # Start an EngineService and append to services/client |
|
60 | 60 | self.engine_service = es.EngineService() |
|
61 | 61 | self.engine_service.startService() |
|
62 | 62 | self.engine_tub = Tub() |
|
63 | 63 | self.engine_tub.startService() |
|
64 | 64 | engine_connector = EngineConnector(self.engine_tub) |
|
65 | 65 | d = engine_connector.connect_to_controller(self.engine_service, furl) |
|
66 | 66 | # This deferred doesn't fire until after register_engine has returned and |
|
67 | 67 | # thus, self.engine has been defined and the tets can proceed. |
|
68 | 68 | return d |
|
69 | 69 | |
|
70 | 70 | def tearDown(self): |
|
71 | 71 | dlist = [] |
|
72 | 72 | # Shut down the engine |
|
73 | 73 | d = self.engine_tub.stopService() |
|
74 | 74 | dlist.append(d) |
|
75 | 75 | # Shut down the controller |
|
76 | 76 | d = self.controller_tub.stopService() |
|
77 | 77 | dlist.append(d) |
|
78 | 78 | return defer.DeferredList(dlist) |
|
79 | 79 | |
|
80 | 80 | #--------------------------------------------------------------------------- |
|
81 | 81 | # Make me look like a basic controller |
|
82 | 82 | #--------------------------------------------------------------------------- |
|
83 | 83 | |
|
84 | 84 | def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None): |
|
85 | 85 | self.engine = IEngineQueued(IEngineBase(engine_ref)) |
|
86 | 86 | return {'id':id} |
|
87 | 87 | |
|
88 | 88 | def unregister_engine(self, id): |
|
89 | 89 | pass No newline at end of file |
@@ -1,64 +1,64 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the kernel.engineservice.py module. |
|
4 | 4 | |
|
5 | 5 | Things that should be tested: |
|
6 | 6 | |
|
7 | 7 | - Should the EngineService return Deferred objects? |
|
8 | 8 | - Run the same tests that are run in shell.py. |
|
9 | 9 | - Make sure that the Interface is really implemented. |
|
10 | 10 | - The startService and stopService methods. |
|
11 | 11 | """ |
|
12 | 12 | |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2008 The IPython Development Team |
|
17 | 17 | # |
|
18 | 18 | # Distributed under the terms of the BSD License. The full license is in |
|
19 | 19 | # the file COPYING, distributed as part of this software. |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | # Imports |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | |
|
26 | 26 | from twisted.internet import defer |
|
27 | 27 | from twisted.application.service import IService |
|
28 | 28 | |
|
29 | 29 | from IPython.kernel import engineservice as es |
|
30 |
from IPython.test |
|
|
30 | from IPython.testing.util import DeferredTestCase | |
|
31 | 31 | from IPython.kernel.tests.engineservicetest import \ |
|
32 | 32 | IEngineCoreTestCase, \ |
|
33 | 33 | IEngineSerializedTestCase, \ |
|
34 | 34 | IEngineQueuedTestCase, \ |
|
35 | 35 | IEnginePropertiesTestCase |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | class BasicEngineServiceTest(DeferredTestCase, |
|
39 | 39 | IEngineCoreTestCase, |
|
40 | 40 | IEngineSerializedTestCase, |
|
41 | 41 | IEnginePropertiesTestCase): |
|
42 | 42 | |
|
43 | 43 | def setUp(self): |
|
44 | 44 | self.engine = es.EngineService() |
|
45 | 45 | self.engine.startService() |
|
46 | 46 | |
|
47 | 47 | def tearDown(self): |
|
48 | 48 | return self.engine.stopService() |
|
49 | 49 | |
|
50 | 50 | class QueuedEngineServiceTest(DeferredTestCase, |
|
51 | 51 | IEngineCoreTestCase, |
|
52 | 52 | IEngineSerializedTestCase, |
|
53 | 53 | IEnginePropertiesTestCase, |
|
54 | 54 | IEngineQueuedTestCase): |
|
55 | 55 | |
|
56 | 56 | def setUp(self): |
|
57 | 57 | self.rawEngine = es.EngineService() |
|
58 | 58 | self.rawEngine.startService() |
|
59 | 59 | self.engine = es.IEngineQueued(self.rawEngine) |
|
60 | 60 | |
|
61 | 61 | def tearDown(self): |
|
62 | 62 | return self.rawEngine.stopService() |
|
63 | 63 | |
|
64 | 64 |
@@ -1,52 +1,52 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | from twisted.internet import defer |
|
19 |
from IPython.test |
|
|
19 | from IPython.testing.util import DeferredTestCase | |
|
20 | 20 | from IPython.kernel.controllerservice import ControllerService |
|
21 | 21 | from IPython.kernel import multiengine as me |
|
22 | 22 | from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase, |
|
23 | 23 | ISynchronousMultiEngineTestCase) |
|
24 | 24 | |
|
25 | 25 | |
|
26 | 26 | class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase): |
|
27 | 27 | |
|
28 | 28 | def setUp(self): |
|
29 | 29 | self.controller = ControllerService() |
|
30 | 30 | self.controller.startService() |
|
31 | 31 | self.multiengine = me.IMultiEngine(self.controller) |
|
32 | 32 | self.engines = [] |
|
33 | 33 | |
|
34 | 34 | def tearDown(self): |
|
35 | 35 | self.controller.stopService() |
|
36 | 36 | for e in self.engines: |
|
37 | 37 | e.stopService() |
|
38 | 38 | |
|
39 | 39 | |
|
40 | 40 | class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase): |
|
41 | 41 | |
|
42 | 42 | def setUp(self): |
|
43 | 43 | self.controller = ControllerService() |
|
44 | 44 | self.controller.startService() |
|
45 | 45 | self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller)) |
|
46 | 46 | self.engines = [] |
|
47 | 47 | |
|
48 | 48 | def tearDown(self): |
|
49 | 49 | self.controller.stopService() |
|
50 | 50 | for e in self.engines: |
|
51 | 51 | e.stopService() |
|
52 | 52 |
@@ -1,68 +1,68 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | |
|
4 | 4 | __docformat__ = "restructuredtext en" |
|
5 | 5 | |
|
6 | 6 | #------------------------------------------------------------------------------- |
|
7 | 7 | # Copyright (C) 2008 The IPython Development Team |
|
8 | 8 | # |
|
9 | 9 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | 10 | # the file COPYING, distributed as part of this software. |
|
11 | 11 | #------------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #------------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | from twisted.internet import defer, reactor |
|
18 | 18 | |
|
19 | 19 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
20 | 20 | |
|
21 |
from IPython.test |
|
|
21 | from IPython.testing.util import DeferredTestCase | |
|
22 | 22 | from IPython.kernel.controllerservice import ControllerService |
|
23 | 23 | from IPython.kernel.multiengine import IMultiEngine |
|
24 | 24 | from IPython.kernel.tests.multienginetest import IFullSynchronousMultiEngineTestCase |
|
25 | 25 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine |
|
26 | 26 | from IPython.kernel import multiengine as me |
|
27 | 27 | from IPython.kernel.clientconnector import ClientConnector |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase): |
|
31 | 31 | |
|
32 | 32 | def setUp(self): |
|
33 | 33 | |
|
34 | 34 | self.engines = [] |
|
35 | 35 | |
|
36 | 36 | self.controller = ControllerService() |
|
37 | 37 | self.controller.startService() |
|
38 | 38 | self.imultiengine = IMultiEngine(self.controller) |
|
39 | 39 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) |
|
40 | 40 | |
|
41 | 41 | self.controller_tub = Tub() |
|
42 | 42 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
43 | 43 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
44 | 44 | |
|
45 | 45 | furl = self.controller_tub.registerReference(self.mec_referenceable) |
|
46 | 46 | self.controller_tub.startService() |
|
47 | 47 | |
|
48 | 48 | self.client_tub = ClientConnector() |
|
49 | 49 | d = self.client_tub.get_multiengine_client(furl) |
|
50 | 50 | d.addCallback(self.handle_got_client) |
|
51 | 51 | return d |
|
52 | 52 | |
|
53 | 53 | def handle_got_client(self, client): |
|
54 | 54 | self.multiengine = client |
|
55 | 55 | |
|
56 | 56 | def tearDown(self): |
|
57 | 57 | dlist = [] |
|
58 | 58 | # Shut down the multiengine client |
|
59 | 59 | d = self.client_tub.tub.stopService() |
|
60 | 60 | dlist.append(d) |
|
61 | 61 | # Shut down the engines |
|
62 | 62 | for e in self.engines: |
|
63 | 63 | e.stopService() |
|
64 | 64 | # Shut down the controller |
|
65 | 65 | d = self.controller_tub.stopService() |
|
66 | 66 | d.addBoth(lambda _: self.controller.stopService()) |
|
67 | 67 | dlist.append(d) |
|
68 | 68 | return defer.DeferredList(dlist) |
@@ -1,99 +1,99 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the shell.py module.""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | import zope.interface as zi |
|
19 | 19 | from twisted.trial import unittest |
|
20 |
from IPython.test |
|
|
20 | from IPython.testing.util import DeferredTestCase | |
|
21 | 21 | |
|
22 | 22 | from IPython.kernel.newserialized import \ |
|
23 | 23 | ISerialized, \ |
|
24 | 24 | IUnSerialized, \ |
|
25 | 25 | Serialized, \ |
|
26 | 26 | UnSerialized, \ |
|
27 | 27 | SerializeIt, \ |
|
28 | 28 | UnSerializeIt |
|
29 | 29 | |
|
30 | 30 | #------------------------------------------------------------------------------- |
|
31 | 31 | # Tests |
|
32 | 32 | #------------------------------------------------------------------------------- |
|
33 | 33 | |
|
34 | 34 | class SerializedTestCase(unittest.TestCase): |
|
35 | 35 | |
|
36 | 36 | def setUp(self): |
|
37 | 37 | pass |
|
38 | 38 | |
|
39 | 39 | def tearDown(self): |
|
40 | 40 | pass |
|
41 | 41 | |
|
42 | 42 | def testSerializedInterfaces(self): |
|
43 | 43 | |
|
44 | 44 | us = UnSerialized({'a':10, 'b':range(10)}) |
|
45 | 45 | s = ISerialized(us) |
|
46 | 46 | uss = IUnSerialized(s) |
|
47 | 47 | self.assert_(ISerialized.providedBy(s)) |
|
48 | 48 | self.assert_(IUnSerialized.providedBy(us)) |
|
49 | 49 | self.assert_(IUnSerialized.providedBy(uss)) |
|
50 | 50 | for m in list(ISerialized): |
|
51 | 51 | self.assert_(hasattr(s, m)) |
|
52 | 52 | for m in list(IUnSerialized): |
|
53 | 53 | self.assert_(hasattr(us, m)) |
|
54 | 54 | for m in list(IUnSerialized): |
|
55 | 55 | self.assert_(hasattr(uss, m)) |
|
56 | 56 | |
|
57 | 57 | def testPickleSerialized(self): |
|
58 | 58 | obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L} |
|
59 | 59 | original = UnSerialized(obj) |
|
60 | 60 | originalSer = ISerialized(original) |
|
61 | 61 | firstData = originalSer.getData() |
|
62 | 62 | firstTD = originalSer.getTypeDescriptor() |
|
63 | 63 | firstMD = originalSer.getMetadata() |
|
64 | 64 | self.assert_(firstTD == 'pickle') |
|
65 | 65 | self.assert_(firstMD == {}) |
|
66 | 66 | unSerialized = IUnSerialized(originalSer) |
|
67 | 67 | secondObj = unSerialized.getObject() |
|
68 | 68 | for k, v in secondObj.iteritems(): |
|
69 | 69 | self.assert_(obj[k] == v) |
|
70 | 70 | secondSer = ISerialized(UnSerialized(secondObj)) |
|
71 | 71 | self.assert_(firstData == secondSer.getData()) |
|
72 | 72 | self.assert_(firstTD == secondSer.getTypeDescriptor() ) |
|
73 | 73 | self.assert_(firstMD == secondSer.getMetadata()) |
|
74 | 74 | |
|
75 | 75 | def testNDArraySerialized(self): |
|
76 | 76 | try: |
|
77 | 77 | import numpy |
|
78 | 78 | except ImportError: |
|
79 | 79 | pass |
|
80 | 80 | else: |
|
81 | 81 | a = numpy.linspace(0.0, 1.0, 1000) |
|
82 | 82 | unSer1 = UnSerialized(a) |
|
83 | 83 | ser1 = ISerialized(unSer1) |
|
84 | 84 | td = ser1.getTypeDescriptor() |
|
85 | 85 | self.assert_(td == 'ndarray') |
|
86 | 86 | md = ser1.getMetadata() |
|
87 | 87 | self.assert_(md['shape'] == a.shape) |
|
88 | 88 | self.assert_(md['dtype'] == a.dtype.str) |
|
89 | 89 | buff = ser1.getData() |
|
90 | 90 | self.assert_(buff == numpy.getbuffer(a)) |
|
91 | 91 | s = Serialized(buff, td, md) |
|
92 | 92 | us = IUnSerialized(s) |
|
93 | 93 | final = us.getObject() |
|
94 | 94 | self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final)) |
|
95 | 95 | self.assert_(a.dtype.str == final.dtype.str) |
|
96 | 96 | self.assert_(a.shape == final.shape) |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | No newline at end of file |
@@ -1,215 +1,215 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | |
|
4 | 4 | """Tests for pendingdeferred.py""" |
|
5 | 5 | |
|
6 | 6 | __docformat__ = "restructuredtext en" |
|
7 | 7 | |
|
8 | 8 | #------------------------------------------------------------------------------- |
|
9 | 9 | # Copyright (C) 2008 The IPython Development Team |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 12 | # the file COPYING, distributed as part of this software. |
|
13 | 13 | #------------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #------------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | from twisted.internet import defer |
|
20 | 20 | from twisted.python import failure |
|
21 | 21 | |
|
22 |
from IPython.test |
|
|
23 |
from IPython.test |
|
|
24 |
from IPython.test |
|
|
22 | from IPython.testing import tcommon | |
|
23 | from IPython.testing.tcommon import * | |
|
24 | from IPython.testing.util import DeferredTestCase | |
|
25 | 25 | import IPython.kernel.pendingdeferred as pd |
|
26 | 26 | from IPython.kernel import error |
|
27 | 27 | from IPython.kernel.util import printer |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | #------------------------------------------------------------------------------- |
|
31 | 31 | # Setup for inline and standalone doctests |
|
32 | 32 | #------------------------------------------------------------------------------- |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | # If you have standalone doctests in a separate file, set their names in the |
|
36 | 36 | # dt_files variable (as a single string or a list thereof): |
|
37 | 37 | dt_files = [] |
|
38 | 38 | |
|
39 | 39 | # If you have any modules whose docstrings should be scanned for embedded tests |
|
40 | 40 | # as examples accorging to standard doctest practice, set them here (as a |
|
41 | 41 | # single string or a list thereof): |
|
42 | 42 | dt_modules = [] |
|
43 | 43 | |
|
44 | 44 | #------------------------------------------------------------------------------- |
|
45 | 45 | # Regular Unittests |
|
46 | 46 | #------------------------------------------------------------------------------- |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | class Foo(object): |
|
50 | 50 | |
|
51 | 51 | def bar(self, bahz): |
|
52 | 52 | return defer.succeed('blahblah: %s' % bahz) |
|
53 | 53 | |
|
54 | 54 | class TwoPhaseFoo(pd.PendingDeferredManager): |
|
55 | 55 | |
|
56 | 56 | def __init__(self, foo): |
|
57 | 57 | self.foo = foo |
|
58 | 58 | pd.PendingDeferredManager.__init__(self) |
|
59 | 59 | |
|
60 | 60 | @pd.two_phase |
|
61 | 61 | def bar(self, bahz): |
|
62 | 62 | return self.foo.bar(bahz) |
|
63 | 63 | |
|
64 | 64 | class PendingDeferredManagerTest(DeferredTestCase): |
|
65 | 65 | |
|
66 | 66 | def setUp(self): |
|
67 | 67 | self.pdm = pd.PendingDeferredManager() |
|
68 | 68 | |
|
69 | 69 | def tearDown(self): |
|
70 | 70 | pass |
|
71 | 71 | |
|
72 | 72 | def testBasic(self): |
|
73 | 73 | dDict = {} |
|
74 | 74 | # Create 10 deferreds and save them |
|
75 | 75 | for i in range(10): |
|
76 | 76 | d = defer.Deferred() |
|
77 | 77 | did = self.pdm.save_pending_deferred(d) |
|
78 | 78 | dDict[did] = d |
|
79 | 79 | # Make sure they are begin saved |
|
80 | 80 | for k in dDict.keys(): |
|
81 | 81 | self.assert_(self.pdm.quick_has_id(k)) |
|
82 | 82 | # Get the pending deferred (block=True), then callback with 'foo' and compare |
|
83 | 83 | for did in dDict.keys()[0:5]: |
|
84 | 84 | d = self.pdm.get_pending_deferred(did,block=True) |
|
85 | 85 | dDict[did].callback('foo') |
|
86 | 86 | d.addCallback(lambda r: self.assert_(r=='foo')) |
|
87 | 87 | # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised |
|
88 | 88 | for did in dDict.keys()[5:10]: |
|
89 | 89 | d = self.pdm.get_pending_deferred(did,block=False) |
|
90 | 90 | d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
91 | 91 | # Now callback the last 5, get them and compare. |
|
92 | 92 | for did in dDict.keys()[5:10]: |
|
93 | 93 | dDict[did].callback('foo') |
|
94 | 94 | d = self.pdm.get_pending_deferred(did,block=False) |
|
95 | 95 | d.addCallback(lambda r: self.assert_(r=='foo')) |
|
96 | 96 | |
|
97 | 97 | def test_save_then_delete(self): |
|
98 | 98 | d = defer.Deferred() |
|
99 | 99 | did = self.pdm.save_pending_deferred(d) |
|
100 | 100 | self.assert_(self.pdm.quick_has_id(did)) |
|
101 | 101 | self.pdm.delete_pending_deferred(did) |
|
102 | 102 | self.assert_(not self.pdm.quick_has_id(did)) |
|
103 | 103 | |
|
104 | 104 | def test_save_get_delete(self): |
|
105 | 105 | d = defer.Deferred() |
|
106 | 106 | did = self.pdm.save_pending_deferred(d) |
|
107 | 107 | d2 = self.pdm.get_pending_deferred(did,True) |
|
108 | 108 | d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException)) |
|
109 | 109 | self.pdm.delete_pending_deferred(did) |
|
110 | 110 | return d2 |
|
111 | 111 | |
|
112 | 112 | def test_double_get(self): |
|
113 | 113 | d = defer.Deferred() |
|
114 | 114 | did = self.pdm.save_pending_deferred(d) |
|
115 | 115 | d2 = self.pdm.get_pending_deferred(did,True) |
|
116 | 116 | d3 = self.pdm.get_pending_deferred(did,True) |
|
117 | 117 | d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException)) |
|
118 | 118 | |
|
119 | 119 | def test_get_after_callback(self): |
|
120 | 120 | d = defer.Deferred() |
|
121 | 121 | did = self.pdm.save_pending_deferred(d) |
|
122 | 122 | d.callback('foo') |
|
123 | 123 | d2 = self.pdm.get_pending_deferred(did,True) |
|
124 | 124 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
125 | 125 | self.assert_(not self.pdm.quick_has_id(did)) |
|
126 | 126 | |
|
127 | 127 | def test_get_before_callback(self): |
|
128 | 128 | d = defer.Deferred() |
|
129 | 129 | did = self.pdm.save_pending_deferred(d) |
|
130 | 130 | d2 = self.pdm.get_pending_deferred(did,True) |
|
131 | 131 | d.callback('foo') |
|
132 | 132 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
133 | 133 | self.assert_(not self.pdm.quick_has_id(did)) |
|
134 | 134 | d = defer.Deferred() |
|
135 | 135 | did = self.pdm.save_pending_deferred(d) |
|
136 | 136 | d2 = self.pdm.get_pending_deferred(did,True) |
|
137 | 137 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
138 | 138 | d.callback('foo') |
|
139 | 139 | self.assert_(not self.pdm.quick_has_id(did)) |
|
140 | 140 | |
|
141 | 141 | def test_get_after_errback(self): |
|
142 | 142 | class MyError(Exception): |
|
143 | 143 | pass |
|
144 | 144 | d = defer.Deferred() |
|
145 | 145 | did = self.pdm.save_pending_deferred(d) |
|
146 | 146 | d.errback(failure.Failure(MyError('foo'))) |
|
147 | 147 | d2 = self.pdm.get_pending_deferred(did,True) |
|
148 | 148 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
149 | 149 | self.assert_(not self.pdm.quick_has_id(did)) |
|
150 | 150 | |
|
151 | 151 | def test_get_before_errback(self): |
|
152 | 152 | class MyError(Exception): |
|
153 | 153 | pass |
|
154 | 154 | d = defer.Deferred() |
|
155 | 155 | did = self.pdm.save_pending_deferred(d) |
|
156 | 156 | d2 = self.pdm.get_pending_deferred(did,True) |
|
157 | 157 | d.errback(failure.Failure(MyError('foo'))) |
|
158 | 158 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
159 | 159 | self.assert_(not self.pdm.quick_has_id(did)) |
|
160 | 160 | d = defer.Deferred() |
|
161 | 161 | did = self.pdm.save_pending_deferred(d) |
|
162 | 162 | d2 = self.pdm.get_pending_deferred(did,True) |
|
163 | 163 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
164 | 164 | d.errback(failure.Failure(MyError('foo'))) |
|
165 | 165 | self.assert_(not self.pdm.quick_has_id(did)) |
|
166 | 166 | |
|
167 | 167 | def test_noresult_noblock(self): |
|
168 | 168 | d = defer.Deferred() |
|
169 | 169 | did = self.pdm.save_pending_deferred(d) |
|
170 | 170 | d2 = self.pdm.get_pending_deferred(did,False) |
|
171 | 171 | d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
172 | 172 | |
|
173 | 173 | def test_with_callbacks(self): |
|
174 | 174 | d = defer.Deferred() |
|
175 | 175 | d.addCallback(lambda r: r+' foo') |
|
176 | 176 | d.addCallback(lambda r: r+' bar') |
|
177 | 177 | did = self.pdm.save_pending_deferred(d) |
|
178 | 178 | d2 = self.pdm.get_pending_deferred(did,True) |
|
179 | 179 | d.callback('bam') |
|
180 | 180 | d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar')) |
|
181 | 181 | |
|
182 | 182 | def test_with_errbacks(self): |
|
183 | 183 | class MyError(Exception): |
|
184 | 184 | pass |
|
185 | 185 | d = defer.Deferred() |
|
186 | 186 | d.addCallback(lambda r: 'foo') |
|
187 | 187 | d.addErrback(lambda f: 'caught error') |
|
188 | 188 | did = self.pdm.save_pending_deferred(d) |
|
189 | 189 | d2 = self.pdm.get_pending_deferred(did,True) |
|
190 | 190 | d.errback(failure.Failure(MyError('bam'))) |
|
191 | 191 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
192 | 192 | |
|
193 | 193 | def test_nested_deferreds(self): |
|
194 | 194 | d = defer.Deferred() |
|
195 | 195 | d2 = defer.Deferred() |
|
196 | 196 | d.addCallback(lambda r: d2) |
|
197 | 197 | did = self.pdm.save_pending_deferred(d) |
|
198 | 198 | d.callback('foo') |
|
199 | 199 | d3 = self.pdm.get_pending_deferred(did,False) |
|
200 | 200 | d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
201 | 201 | d2.callback('bar') |
|
202 | 202 | d3 = self.pdm.get_pending_deferred(did,False) |
|
203 | 203 | d3.addCallback(lambda r: self.assertEquals(r,'bar')) |
|
204 | 204 | |
|
205 | 205 | #------------------------------------------------------------------------------- |
|
206 | 206 | # Regular Unittests |
|
207 | 207 | #------------------------------------------------------------------------------- |
|
208 | 208 | |
|
209 | 209 | # This ensures that the code will run either standalone as a script, or that it |
|
210 | 210 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. |
|
211 | 211 | if tcommon.pexpect is not None: |
|
212 | 212 | if __name__ == '__main__': |
|
213 | 213 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) |
|
214 | 214 | else: |
|
215 | 215 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
@@ -1,47 +1,47 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | |
|
3 | 3 | """This file contains unittests for the kernel.task.py module.""" |
|
4 | 4 | |
|
5 | 5 | __docformat__ = "restructuredtext en" |
|
6 | 6 | |
|
7 | 7 | #------------------------------------------------------------------------------- |
|
8 | 8 | # Copyright (C) 2008 The IPython Development Team |
|
9 | 9 | # |
|
10 | 10 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | 11 | # the file COPYING, distributed as part of this software. |
|
12 | 12 | #------------------------------------------------------------------------------- |
|
13 | 13 | |
|
14 | 14 | #------------------------------------------------------------------------------- |
|
15 | 15 | # Imports |
|
16 | 16 | #------------------------------------------------------------------------------- |
|
17 | 17 | |
|
18 | 18 | import time |
|
19 | 19 | |
|
20 | 20 | from twisted.internet import defer |
|
21 | 21 | from twisted.trial import unittest |
|
22 | 22 | |
|
23 | 23 | from IPython.kernel import task, controllerservice as cs, engineservice as es |
|
24 | 24 | from IPython.kernel.multiengine import IMultiEngine |
|
25 |
from IPython.test |
|
|
25 | from IPython.testing.util import DeferredTestCase | |
|
26 | 26 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase |
|
27 | 27 | |
|
28 | 28 | #------------------------------------------------------------------------------- |
|
29 | 29 | # Tests |
|
30 | 30 | #------------------------------------------------------------------------------- |
|
31 | 31 | |
|
32 | 32 | class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase): |
|
33 | 33 | |
|
34 | 34 | def setUp(self): |
|
35 | 35 | self.controller = cs.ControllerService() |
|
36 | 36 | self.controller.startService() |
|
37 | 37 | self.multiengine = IMultiEngine(self.controller) |
|
38 | 38 | self.tc = task.ITaskController(self.controller) |
|
39 | 39 | self.tc.failurePenalty = 0 |
|
40 | 40 | self.engines=[] |
|
41 | 41 | |
|
42 | 42 | def tearDown(self): |
|
43 | 43 | self.controller.stopService() |
|
44 | 44 | for e in self.engines: |
|
45 | 45 | e.stopService() |
|
46 | 46 | |
|
47 | 47 |
@@ -1,86 +1,86 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | |
|
4 | 4 | __docformat__ = "restructuredtext en" |
|
5 | 5 | |
|
6 | 6 | #------------------------------------------------------------------------------- |
|
7 | 7 | # Copyright (C) 2008 The IPython Development Team |
|
8 | 8 | # |
|
9 | 9 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | 10 | # the file COPYING, distributed as part of this software. |
|
11 | 11 | #------------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | #------------------------------------------------------------------------------- |
|
14 | 14 | # Imports |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | |
|
17 | 17 | import time |
|
18 | 18 | |
|
19 | 19 | from twisted.internet import defer, reactor |
|
20 | 20 | |
|
21 | 21 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
22 | 22 | |
|
23 | 23 | from IPython.kernel import task as taskmodule |
|
24 | 24 | from IPython.kernel import controllerservice as cs |
|
25 | 25 | import IPython.kernel.multiengine as me |
|
26 |
from IPython.test |
|
|
26 | from IPython.testing.util import DeferredTestCase | |
|
27 | 27 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine |
|
28 | 28 | from IPython.kernel.taskfc import IFCTaskController |
|
29 | 29 | from IPython.kernel.util import printer |
|
30 | 30 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase |
|
31 | 31 | from IPython.kernel.clientconnector import ClientConnector |
|
32 | 32 | |
|
33 | 33 | #------------------------------------------------------------------------------- |
|
34 | 34 | # Tests |
|
35 | 35 | #------------------------------------------------------------------------------- |
|
36 | 36 | |
|
37 | 37 | class TaskTest(DeferredTestCase, ITaskControllerTestCase): |
|
38 | 38 | |
|
39 | 39 | def setUp(self): |
|
40 | 40 | |
|
41 | 41 | self.engines = [] |
|
42 | 42 | |
|
43 | 43 | self.controller = cs.ControllerService() |
|
44 | 44 | self.controller.startService() |
|
45 | 45 | self.imultiengine = me.IMultiEngine(self.controller) |
|
46 | 46 | self.itc = taskmodule.ITaskController(self.controller) |
|
47 | 47 | self.itc.failurePenalty = 0 |
|
48 | 48 | |
|
49 | 49 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) |
|
50 | 50 | self.tc_referenceable = IFCTaskController(self.itc) |
|
51 | 51 | |
|
52 | 52 | self.controller_tub = Tub() |
|
53 | 53 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
54 | 54 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
55 | 55 | |
|
56 | 56 | mec_furl = self.controller_tub.registerReference(self.mec_referenceable) |
|
57 | 57 | tc_furl = self.controller_tub.registerReference(self.tc_referenceable) |
|
58 | 58 | self.controller_tub.startService() |
|
59 | 59 | |
|
60 | 60 | self.client_tub = ClientConnector() |
|
61 | 61 | d = self.client_tub.get_multiengine_client(mec_furl) |
|
62 | 62 | d.addCallback(self.handle_mec_client) |
|
63 | 63 | d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl)) |
|
64 | 64 | d.addCallback(self.handle_tc_client) |
|
65 | 65 | return d |
|
66 | 66 | |
|
67 | 67 | def handle_mec_client(self, client): |
|
68 | 68 | self.multiengine = client |
|
69 | 69 | |
|
70 | 70 | def handle_tc_client(self, client): |
|
71 | 71 | self.tc = client |
|
72 | 72 | |
|
73 | 73 | def tearDown(self): |
|
74 | 74 | dlist = [] |
|
75 | 75 | # Shut down the multiengine client |
|
76 | 76 | d = self.client_tub.tub.stopService() |
|
77 | 77 | dlist.append(d) |
|
78 | 78 | # Shut down the engines |
|
79 | 79 | for e in self.engines: |
|
80 | 80 | e.stopService() |
|
81 | 81 | # Shut down the controller |
|
82 | 82 | d = self.controller_tub.stopService() |
|
83 | 83 | d.addBoth(lambda _: self.controller.stopService()) |
|
84 | 84 | dlist.append(d) |
|
85 | 85 | return defer.DeferredList(dlist) |
|
86 | 86 |
@@ -1,36 +1,36 b'' | |||
|
1 | 1 | """Common utilities for testing IPython. |
|
2 | 2 | |
|
3 | 3 | This file is meant to be used as |
|
4 | 4 | |
|
5 |
from IPython.test |
|
|
5 | from IPython.testing.tcommon import * | |
|
6 | 6 | |
|
7 | 7 | by any test code. |
|
8 | 8 | |
|
9 | 9 | While a bit ugly, this helps us keep all testing facilities in one place, and |
|
10 | 10 | start coding standalone test scripts easily, which can then be pasted into the |
|
11 | 11 | larger test suites without any modifications required. |
|
12 | 12 | """ |
|
13 | 13 | |
|
14 | 14 | # Required modules and packages |
|
15 | 15 | |
|
16 | 16 | # Standard Python lib |
|
17 | 17 | import cPickle as pickle |
|
18 | 18 | import doctest |
|
19 | 19 | import math |
|
20 | 20 | import os |
|
21 | 21 | import sys |
|
22 | 22 | import unittest |
|
23 | 23 | |
|
24 | 24 | from pprint import pformat, pprint |
|
25 | 25 | |
|
26 | 26 | # From the IPython test lib |
|
27 | 27 | import tutils |
|
28 | 28 | from tutils import fullPath |
|
29 | 29 | |
|
30 | 30 | try: |
|
31 | 31 | import pexpect |
|
32 | 32 | except ImportError: |
|
33 | 33 | pexpect = None |
|
34 | 34 | else: |
|
35 |
from IPython.test |
|
|
35 | from IPython.testing.ipdoctest import IPDocTestLoader,makeTestSuite | |
|
36 | 36 |
@@ -1,66 +1,66 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """Simple template for unit tests. |
|
4 | 4 | |
|
5 | 5 | This file should be renamed to |
|
6 | 6 | |
|
7 | 7 | test_FEATURE.py |
|
8 | 8 | |
|
9 | 9 | so that it is recognized by the overall test driver (Twisted's 'trial'), which |
|
10 | 10 | looks for all test_*.py files in the current directory to extract tests from |
|
11 | 11 | them. |
|
12 | 12 | """ |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> |
|
17 | 17 | # Brian E Granger <ellisonbg@gmail.com> |
|
18 | 18 | # Benjamin Ragan-Kelley <benjaminrk@gmail.com> |
|
19 | 19 | # |
|
20 | 20 | # Distributed under the terms of the BSD License. The full license is in |
|
21 | 21 | # the file COPYING, distributed as part of this software. |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | # Imports |
|
26 | 26 | #------------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 |
from IPython.test |
|
|
29 |
from IPython.test |
|
|
28 | from IPython.testing import tcommon | |
|
29 | from IPython.testing.tcommon import * | |
|
30 | 30 | |
|
31 | 31 | #------------------------------------------------------------------------------- |
|
32 | 32 | # Setup for inline and standalone doctests |
|
33 | 33 | #------------------------------------------------------------------------------- |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | # If you have standalone doctests in a separate file, set their names in the |
|
37 | 37 | # dt_files variable (as a single string or a list thereof). The mkPath call |
|
38 | 38 | # forms an absolute path based on the current file, it is not needed if you |
|
39 | 39 | # provide the full pahts. |
|
40 | 40 | dt_files = fullPath(__file__,[]) |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | # If you have any modules whose docstrings should be scanned for embedded tests |
|
44 | 44 | # as examples accorging to standard doctest practice, set them here (as a |
|
45 | 45 | # single string or a list thereof): |
|
46 | 46 | dt_modules = [] |
|
47 | 47 | |
|
48 | 48 | #------------------------------------------------------------------------------- |
|
49 | 49 | # Regular Unittests |
|
50 | 50 | #------------------------------------------------------------------------------- |
|
51 | 51 | |
|
52 | 52 | class FooTestCase(unittest.TestCase): |
|
53 | 53 | def test_foo(self): |
|
54 | 54 | pass |
|
55 | 55 | |
|
56 | 56 | #------------------------------------------------------------------------------- |
|
57 | 57 | # Regular Unittests |
|
58 | 58 | #------------------------------------------------------------------------------- |
|
59 | 59 | |
|
60 | 60 | # This ensures that the code will run either standalone as a script, or that it |
|
61 | 61 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. |
|
62 | 62 | if tcommon.pexpect is not None: |
|
63 | 63 | if __name__ == '__main__': |
|
64 | 64 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) |
|
65 | 65 | else: |
|
66 | 66 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
@@ -1,66 +1,66 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | """Simple template for unit tests. |
|
4 | 4 | |
|
5 | 5 | This file should be renamed to |
|
6 | 6 | |
|
7 | 7 | test_FEATURE.py |
|
8 | 8 | |
|
9 | 9 | so that it is recognized by the overall test driver (Twisted's 'trial'), which |
|
10 | 10 | looks for all test_*.py files in the current directory to extract tests from |
|
11 | 11 | them. |
|
12 | 12 | """ |
|
13 | 13 | __docformat__ = "restructuredtext en" |
|
14 | 14 | |
|
15 | 15 | #------------------------------------------------------------------------------- |
|
16 | 16 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> |
|
17 | 17 | # Brian E Granger <ellisonbg@gmail.com> |
|
18 | 18 | # Benjamin Ragan-Kelley <benjaminrk@gmail.com> |
|
19 | 19 | # |
|
20 | 20 | # Distributed under the terms of the BSD License. The full license is in |
|
21 | 21 | # the file COPYING, distributed as part of this software. |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | |
|
24 | 24 | #------------------------------------------------------------------------------- |
|
25 | 25 | # Imports |
|
26 | 26 | #------------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 |
from IPython.test |
|
|
29 |
from IPython.test |
|
|
28 | from IPython.testing import tcommon | |
|
29 | from IPython.testing.tcommon import * | |
|
30 | 30 | |
|
31 | 31 | #------------------------------------------------------------------------------- |
|
32 | 32 | # Setup for inline and standalone doctests |
|
33 | 33 | #------------------------------------------------------------------------------- |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | # If you have standalone doctests in a separate file, set their names in the |
|
37 | 37 | # dt_files variable (as a single string or a list thereof). The mkPath call |
|
38 | 38 | # forms an absolute path based on the current file, it is not needed if you |
|
39 | 39 | # provide the full pahts. |
|
40 | 40 | dt_files = fullPath(__file__,[]) |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | # If you have any modules whose docstrings should be scanned for embedded tests |
|
44 | 44 | # as examples accorging to standard doctest practice, set them here (as a |
|
45 | 45 | # single string or a list thereof): |
|
46 |
dt_modules = ['IPython.test |
|
|
46 | dt_modules = ['IPython.testing.tutils'] | |
|
47 | 47 | |
|
48 | 48 | #------------------------------------------------------------------------------- |
|
49 | 49 | # Regular Unittests |
|
50 | 50 | #------------------------------------------------------------------------------- |
|
51 | 51 | |
|
52 | 52 | ## class FooTestCase(unittest.TestCase): |
|
53 | 53 | ## def test_foo(self): |
|
54 | 54 | ## pass |
|
55 | 55 | |
|
56 | 56 | #------------------------------------------------------------------------------- |
|
57 | 57 | # Regular Unittests |
|
58 | 58 | #------------------------------------------------------------------------------- |
|
59 | 59 | |
|
60 | 60 | # This ensures that the code will run either standalone as a script, or that it |
|
61 | 61 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. |
|
62 | 62 | if tcommon.pexpect is not None: |
|
63 | 63 | if __name__ == '__main__': |
|
64 | 64 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) |
|
65 | 65 | else: |
|
66 | 66 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
@@ -1,16 +1,16 b'' | |||
|
1 | 1 | """Run this file with |
|
2 | 2 | |
|
3 | 3 | irunner --python filename |
|
4 | 4 | |
|
5 | 5 | to generate valid doctest input. |
|
6 | 6 | |
|
7 | 7 | NOTE: make sure to ALWAYS have a blank line before comments, otherwise doctest |
|
8 | 8 | gets confused.""" |
|
9 | 9 | |
|
10 | 10 | #--------------------------------------------------------------------------- |
|
11 | 11 | |
|
12 | 12 | # Setup - all imports are done in tcommon |
|
13 | 13 | import tcommon; reload(tcommon) # for interactive use |
|
14 |
from IPython.test |
|
|
14 | from IPython.testing.tcommon import * | |
|
15 | 15 | |
|
16 | 16 | # Doctest code begins here |
@@ -1,24 +1,24 b'' | |||
|
1 | 1 | Doctests for the ``XXX`` module |
|
2 | 2 | ===================================== |
|
3 | 3 | |
|
4 | 4 | The way doctest loads these, the entire document is applied as a single test |
|
5 | 5 | rather than multiple individual ones, unfortunately. |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | Auto-generated tests |
|
9 | 9 | -------------------- |
|
10 | 10 | |
|
11 | 11 | The tests below are generated from the companion file |
|
12 | 12 | test_toeplitz_doctest.py, which is run via IPython's irunner script to create |
|
13 | 13 | valid doctest input automatically. |
|
14 | 14 | |
|
15 | 15 | # Setup - all imports are done in tcommon |
|
16 |
>>> from IPython.test |
|
|
16 | >>> from IPython.testing.tcommon import * | |
|
17 | 17 | |
|
18 | 18 | # Rest of doctest goes here... |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | Manually generated tests |
|
22 | 22 | ------------------------ |
|
23 | 23 | |
|
24 | 24 | These are one-off tests written by hand, copied from an interactive prompt. |
@@ -1,36 +1,36 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | """Testing script for the tools.utils module. |
|
3 | 3 | """ |
|
4 | 4 | |
|
5 | 5 | # Module imports |
|
6 |
from IPython.test |
|
|
7 |
from IPython.test |
|
|
6 | from IPython.testing import tcommon | |
|
7 | from IPython.testing.tcommon import * | |
|
8 | 8 | |
|
9 | 9 | # If you have standalone doctests in a separate file, set their names in the |
|
10 | 10 | # dt_files variable (as a single string or a list thereof). The mkPath call |
|
11 | 11 | # forms an absolute path based on the current file, it is not needed if you |
|
12 | 12 | # provide the full pahts. |
|
13 | 13 | dt_files = fullPath(__file__,['tst_tools_utils_doctest.txt', |
|
14 | 14 | 'tst_tools_utils_doctest2.txt']) |
|
15 | 15 | |
|
16 | 16 | # If you have any modules whose docstrings should be scanned for embedded tests |
|
17 | 17 | # as examples accorging to standard doctest practice, set them here (as a |
|
18 | 18 | # single string or a list thereof): |
|
19 | 19 | dt_modules = 'IPython.tools.utils' |
|
20 | 20 | |
|
21 | 21 | ########################################################################## |
|
22 | 22 | ### Regular unittest test classes go here |
|
23 | 23 | |
|
24 | 24 | ## class utilsTestCase(unittest.TestCase): |
|
25 | 25 | ## def test_foo(self): |
|
26 | 26 | ## pass |
|
27 | 27 | |
|
28 | 28 | ########################################################################## |
|
29 | 29 | ### Main |
|
30 | 30 | # This ensures that the code will run either standalone as a script, or that it |
|
31 | 31 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. |
|
32 | 32 | if tcommon.pexpect is not None: |
|
33 | 33 | if __name__ == '__main__': |
|
34 | 34 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) |
|
35 | 35 | else: |
|
36 | 36 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
@@ -1,12 +1,12 b'' | |||
|
1 | 1 | # Setup - all imports are done in tcommon |
|
2 |
from IPython.test |
|
|
3 |
from IPython.test |
|
|
2 | from IPython.testing import tcommon | |
|
3 | from IPython.testing.tcommon import * | |
|
4 | 4 | |
|
5 | 5 | # Doctest code begins here |
|
6 | 6 | from IPython.tools import utils |
|
7 | 7 | |
|
8 | 8 | for i in range(10): |
|
9 | 9 | print i, |
|
10 | 10 | print i+1 |
|
11 | 11 | |
|
12 | 12 | print 'simple loop is over' |
@@ -1,42 +1,42 b'' | |||
|
1 | 1 | |
|
2 | 2 | ========================= |
|
3 | 3 | Auto-generated doctests |
|
4 | 4 | ========================= |
|
5 | 5 | |
|
6 | 6 | This file was auto-generated by IPython in its entirety. If you need finer |
|
7 | 7 | control over the contents, simply make a manual template. See the |
|
8 | 8 | mkdoctests.py script for details. |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | ---------------------------------------------------------------------------- |
|
12 | 12 | |
|
13 | 13 | Begin included file tst_tools_utils_doctest.py:: |
|
14 | 14 | |
|
15 | 15 | # Setup - all imports are done in tcommon |
|
16 |
>>> from IPython.test |
|
|
17 |
>>> from IPython.test |
|
|
16 | >>> from IPython.testing import tcommon | |
|
17 | >>> from IPython.testing.tcommon import * | |
|
18 | 18 | |
|
19 | 19 | # Doctest code begins here |
|
20 | 20 | >>> from IPython.tools import utils |
|
21 | 21 | |
|
22 | 22 | >>> for i in range(10): |
|
23 | 23 | ... print i, |
|
24 | 24 | ... print i+1 |
|
25 | 25 | ... |
|
26 | 26 | 0 1 |
|
27 | 27 | 1 2 |
|
28 | 28 | 2 3 |
|
29 | 29 | 3 4 |
|
30 | 30 | 4 5 |
|
31 | 31 | 5 6 |
|
32 | 32 | 6 7 |
|
33 | 33 | 7 8 |
|
34 | 34 | 8 9 |
|
35 | 35 | 9 10 |
|
36 | 36 | >>> print 'simple loop is over' |
|
37 | 37 | simple loop is over |
|
38 | 38 | |
|
39 | 39 | End included file tst_tools_utils_doctest.py |
|
40 | 40 | |
|
41 | 41 | ---------------------------------------------------------------------------- |
|
42 | 42 |
@@ -1,13 +1,13 b'' | |||
|
1 | 1 | # Setup - all imports are done in tcommon |
|
2 |
from IPython.test |
|
|
3 |
from IPython.test |
|
|
2 | from IPython.testing import tcommon | |
|
3 | from IPython.testing.tcommon import * | |
|
4 | 4 | |
|
5 | 5 | # Doctest code begins here |
|
6 | 6 | from IPython.tools import utils |
|
7 | 7 | |
|
8 | 8 | # Some other tests for utils |
|
9 | 9 | |
|
10 | 10 | utils.marquee('Testing marquee') |
|
11 | 11 | |
|
12 | 12 | utils.marquee('Another test',30,'.') |
|
13 | 13 |
@@ -1,42 +1,42 b'' | |||
|
1 | 1 | ========================================= |
|
2 | 2 | Doctests for the ``tools.utils`` module |
|
3 | 3 | ========================================= |
|
4 | 4 | |
|
5 | 5 | The way doctest loads these, the entire document is applied as a single test |
|
6 | 6 | rather than multiple individual ones, unfortunately. |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | Auto-generated tests |
|
10 | 10 | ==================== |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | ---------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | Begin included file tst_tools_utils_doctest2.py:: |
|
16 | 16 | |
|
17 | 17 | # Setup - all imports are done in tcommon |
|
18 |
>>> from IPython.test |
|
|
19 |
>>> from IPython.test |
|
|
18 | >>> from IPython.testing import tcommon | |
|
19 | >>> from IPython.testing.tcommon import * | |
|
20 | 20 | |
|
21 | 21 | # Doctest code begins here |
|
22 | 22 | >>> from IPython.tools import utils |
|
23 | 23 | |
|
24 | 24 | # Some other tests for utils |
|
25 | 25 | |
|
26 | 26 | >>> utils.marquee('Testing marquee') |
|
27 | 27 | '****************************** Testing marquee ******************************' |
|
28 | 28 | |
|
29 | 29 | >>> utils.marquee('Another test',30,'.') |
|
30 | 30 | '........ Another test ........' |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | End included file tst_tools_utils_doctest2.py |
|
34 | 34 | |
|
35 | 35 | ---------------------------------------------------------------------------- |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | Manually generated tests |
|
40 | 40 | ======================== |
|
41 | 41 | |
|
42 | 42 | These are one-off tests written by hand, copied from an interactive prompt. |
@@ -1,186 +1,162 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # -*- coding: utf-8 -*- |
|
3 | 3 | """Setup script for IPython. |
|
4 | 4 | |
|
5 | 5 | Under Posix environments it works like a typical setup.py script. |
|
6 | 6 | Under Windows, the command sdist is not supported, since IPython |
|
7 | 7 | requires utilities which are not available under Windows.""" |
|
8 | 8 | |
|
9 | #***************************************************************************** | |
|
10 | # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu> | |
|
9 | #------------------------------------------------------------------------------- | |
|
10 | # Copyright (C) 2008 The IPython Development Team | |
|
11 | 11 | # |
|
12 | 12 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | 13 | # the file COPYING, distributed as part of this software. |
|
14 | #***************************************************************************** | |
|
14 | #------------------------------------------------------------------------------- | |
|
15 | ||
|
16 | #------------------------------------------------------------------------------- | |
|
17 | # Imports | |
|
18 | #------------------------------------------------------------------------------- | |
|
15 | 19 | |
|
16 | 20 | # Stdlib imports |
|
17 | 21 | import os |
|
18 | 22 | import sys |
|
19 | 23 | |
|
20 | 24 | from glob import glob |
|
21 | 25 | |
|
22 | 26 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
|
23 | 27 | # update it when the contents of directories change. |
|
24 | 28 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
|
25 | 29 | |
|
26 | 30 | from distutils.core import setup |
|
27 | from setupext import install_data_ext | |
|
28 | 31 | |
|
29 | 32 | # Local imports |
|
30 | 33 | from IPython.genutils import target_update |
|
31 | 34 | |
|
32 | # A few handy globals | |
|
35 | from setupbase import ( | |
|
36 | setup_args, | |
|
37 | find_packages, | |
|
38 | find_package_data, | |
|
39 | find_scripts, | |
|
40 | find_data_files, | |
|
41 | check_for_dependencies | |
|
42 | ) | |
|
43 | ||
|
33 | 44 | isfile = os.path.isfile |
|
34 | pjoin = os.path.join | |
|
35 | ||
|
36 | ############################################################################## | |
|
37 | # Utility functions | |
|
38 | def oscmd(s): | |
|
39 | print ">", s | |
|
40 | os.system(s) | |
|
41 | ||
|
42 | # A little utility we'll need below, since glob() does NOT allow you to do | |
|
43 | # exclusion on multiple endings! | |
|
44 | def file_doesnt_endwith(test,endings): | |
|
45 | """Return true if test is a file and its name does NOT end with any | |
|
46 | of the strings listed in endings.""" | |
|
47 | if not isfile(test): | |
|
48 | return False | |
|
49 | for e in endings: | |
|
50 | if test.endswith(e): | |
|
51 | return False | |
|
52 | return True | |
|
53 | ||
|
54 | ############################################################################### | |
|
55 | # Main code begins | |
|
45 | ||
|
46 | #------------------------------------------------------------------------------- | |
|
47 | # Handle OS specific things | |
|
48 | #------------------------------------------------------------------------------- | |
|
56 | 49 | |
|
57 | 50 | if os.name == 'posix': |
|
58 | 51 | os_name = 'posix' |
|
59 | 52 | elif os.name in ['nt','dos']: |
|
60 | 53 | os_name = 'windows' |
|
61 | 54 | else: |
|
62 | 55 | print 'Unsupported operating system:',os.name |
|
63 | 56 | sys.exit(1) |
|
64 | 57 | |
|
65 | 58 | # Under Windows, 'sdist' has not been supported. Now that the docs build with |
|
66 | 59 | # Sphinx it might work, but let's not turn it on until someone confirms that it |
|
67 | 60 | # actually works. |
|
68 | 61 | if os_name == 'windows' and 'sdist' in sys.argv: |
|
69 | 62 | print 'The sdist command is not available under Windows. Exiting.' |
|
70 | 63 | sys.exit(1) |
|
71 | 64 | |
|
65 | #------------------------------------------------------------------------------- | |
|
66 | # Things related to the IPython documentation | |
|
67 | #------------------------------------------------------------------------------- | |
|
68 | ||
|
72 | 69 | # update the manuals when building a source dist |
|
73 | 70 | if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): |
|
74 | 71 | import textwrap |
|
75 | 72 | |
|
76 | 73 | # List of things to be updated. Each entry is a triplet of args for |
|
77 | 74 | # target_update() |
|
78 | 75 | to_update = [ # The do_sphinx scripts builds html and pdf, so just one |
|
79 | 76 | # target is enough to cover all manual generation |
|
80 | 77 | ('doc/manual/ipython.pdf', |
|
81 | 78 | ['IPython/Release.py','doc/source/ipython.rst'], |
|
82 | 79 | "cd doc && python do_sphinx.py" ), |
|
83 | 80 | |
|
84 | 81 | # FIXME - Disabled for now: we need to redo an automatic way |
|
85 | 82 | # of generating the magic info inside the rst. |
|
86 | 83 | #('doc/magic.tex', |
|
87 | 84 | #['IPython/Magic.py'], |
|
88 | 85 | #"cd doc && ./update_magic.sh" ), |
|
89 | 86 | |
|
90 | 87 | ('doc/ipython.1.gz', |
|
91 | 88 | ['doc/ipython.1'], |
|
92 | 89 | "cd doc && gzip -9c ipython.1 > ipython.1.gz"), |
|
93 | 90 | |
|
94 | 91 | ('doc/pycolor.1.gz', |
|
95 | 92 | ['doc/pycolor.1'], |
|
96 | 93 | "cd doc && gzip -9c pycolor.1 > pycolor.1.gz"), |
|
97 | 94 | ] |
|
98 | 95 | |
|
99 | 96 | [ target_update(*t) for t in to_update ] |
|
100 | 97 | |
|
101 | # Release.py contains version, authors, license, url, keywords, etc. | |
|
102 | execfile(pjoin('IPython','Release.py')) | |
|
103 | ||
|
104 | # I can't find how to make distutils create a nested dir. structure, so | |
|
105 | # in the meantime do it manually. Butt ugly. | |
|
106 | # Note that http://www.redbrick.dcu.ie/~noel/distutils.html, ex. 2/3, contain | |
|
107 | # information on how to do this more cleanly once python 2.4 can be assumed. | |
|
108 | # Thanks to Noel for the tip. | |
|
109 | docdirbase = 'share/doc/ipython' | |
|
110 | manpagebase = 'share/man/man1' | |
|
111 | ||
|
112 | # We only need to exclude from this things NOT already excluded in the | |
|
113 | # MANIFEST.in file. | |
|
114 | exclude = ('.sh','.1.gz') | |
|
115 | docfiles = filter(lambda f:file_doesnt_endwith(f,exclude),glob('doc/*')) | |
|
116 | examfiles = filter(isfile, glob('doc/examples/*.py')) | |
|
117 | manfiles = filter(isfile, glob('doc/manual/*')) | |
|
118 | manstatic = filter(isfile, glob('doc/manual/_static/*')) | |
|
119 | manpages = filter(isfile, glob('doc/*.1.gz')) | |
|
98 | #--------------------------------------------------------------------------- | |
|
99 | # Find all the packages, package data, scripts and data_files | |
|
100 | #--------------------------------------------------------------------------- | |
|
120 | 101 | |
|
121 | cfgfiles = filter(isfile, glob('IPython/UserConfig/*')) | |
|
122 | scriptfiles = filter(isfile, ['scripts/ipython','scripts/pycolor', | |
|
123 | 'scripts/irunner']) | |
|
124 | ||
|
125 | igridhelpfiles = filter(isfile, glob('IPython/Extensions/igrid_help.*')) | |
|
126 | ||
|
127 | # Script to be run by the windows binary installer after the default setup | |
|
128 | # routine, to add shortcuts and similar windows-only things. Windows | |
|
129 | # post-install scripts MUST reside in the scripts/ dir, otherwise distutils | |
|
130 | # doesn't find them. | |
|
131 | if 'bdist_wininst' in sys.argv: | |
|
132 | if len(sys.argv) > 2 and ('sdist' in sys.argv or 'bdist_rpm' in sys.argv): | |
|
133 | print >> sys.stderr,"ERROR: bdist_wininst must be run alone. Exiting." | |
|
134 | sys.exit(1) | |
|
135 | scriptfiles.append('scripts/ipython_win_post_install.py') | |
|
136 | ||
|
137 | datafiles = [('data', docdirbase, docfiles), | |
|
138 | ('data', pjoin(docdirbase, 'examples'),examfiles), | |
|
139 | ('data', pjoin(docdirbase, 'manual'),manfiles), | |
|
140 | ('data', pjoin(docdirbase, 'manual/_static'),manstatic), | |
|
141 | ('data', manpagebase, manpages), | |
|
142 | ('data',pjoin(docdirbase, 'extensions'),igridhelpfiles), | |
|
143 | ] | |
|
102 | packages = find_packages() | |
|
103 | package_data = find_package_data() | |
|
104 | scripts = find_scripts() | |
|
105 | data_files = find_data_files() | |
|
106 | ||
|
107 | #--------------------------------------------------------------------------- | |
|
108 | # Handle dependencies and setuptools specific things | |
|
109 | #--------------------------------------------------------------------------- | |
|
110 | ||
|
111 | # This dict is used for passing extra arguments that are setuptools | |
|
112 | # specific to setup | |
|
113 | setuptools_extra_args = {} | |
|
144 | 114 | |
|
145 | 115 | if 'setuptools' in sys.modules: |
|
146 | # setuptools config for egg building | |
|
147 | egg_extra_kwds = { | |
|
148 | 'entry_points': { | |
|
116 | setuptools_extra_args['zip_safe'] = False | |
|
117 | setuptools_extra_args['entry_points'] = { | |
|
149 | 118 |
|
|
150 | 119 | 'ipython = IPython.ipapi:launch_new_instance', |
|
151 | 'pycolor = IPython.PyColorize:main' | |
|
152 | ]} | |
|
120 | 'pycolor = IPython.PyColorize:main', | |
|
121 | 'ipcontroller = IPython.kernel.scripts.ipcontroller:main', | |
|
122 | 'ipengine = IPython.kernel.scripts.ipengine:main', | |
|
123 | 'ipcluster = IPython.kernel.scripts.ipcluster:main' | |
|
124 | ] | |
|
153 | 125 |
|
|
154 | scriptfiles = [] | |
|
126 | setup_args["extras_require"] = dict( | |
|
127 | kernel = [ | |
|
128 | "zope.interface>=3.4.1", | |
|
129 | "Twisted>=8.0.1", | |
|
130 | "foolscap>=0.2.6" | |
|
131 | ], | |
|
132 | doc=['Sphinx>=0.3','pygments'], | |
|
133 | test='nose>=0.10.1', | |
|
134 | security=["pyOpenSSL>=0.6"] | |
|
135 | ) | |
|
136 | # Allow setuptools to handle the scripts | |
|
137 | scripts = [] | |
|
155 | 138 | # eggs will lack docs, examples |
|
156 | datafiles = [] | |
|
139 | data_files = [] | |
|
157 | 140 | else: |
|
158 | # Normal, non-setuptools install | |
|
159 | egg_extra_kwds = {} | |
|
160 | 141 | # package_data of setuptools was introduced to distutils in 2.4 |
|
142 | cfgfiles = filter(isfile, glob('IPython/UserConfig/*')) | |
|
161 | 143 | if sys.version_info < (2,4): |
|
162 | datafiles.append(('lib', 'IPython/UserConfig', cfgfiles)) | |
|
163 | ||
|
164 | # Call the setup() routine which does most of the work | |
|
165 | setup(name = name, | |
|
166 | version = version, | |
|
167 | description = description, | |
|
168 | long_description = long_description, | |
|
169 | author = authors['Fernando'][0], | |
|
170 | author_email = authors['Fernando'][1], | |
|
171 | url = url, | |
|
172 | download_url = download_url, | |
|
173 | license = license, | |
|
174 | platforms = platforms, | |
|
175 | keywords = keywords, | |
|
176 | packages = ['IPython', 'IPython.Extensions', 'IPython.external', | |
|
177 | 'IPython.gui', 'IPython.gui.wx', | |
|
178 | 'IPython.UserConfig'], | |
|
179 | scripts = scriptfiles, | |
|
180 | package_data = {'IPython.UserConfig' : ['*'] }, | |
|
181 | ||
|
182 | cmdclass = {'install_data': install_data_ext}, | |
|
183 | data_files = datafiles, | |
|
184 | # extra params needed for eggs | |
|
185 | **egg_extra_kwds | |
|
186 | ) | |
|
144 | data_files.append(('lib', 'IPython/UserConfig', cfgfiles)) | |
|
145 | # If we are running without setuptools, call this function which will | |
|
146 | # check for dependencies an inform the user what is needed. This is | |
|
147 | # just to make life easy for users. | |
|
148 | check_for_dependencies() | |
|
149 | ||
|
150 | ||
|
151 | #--------------------------------------------------------------------------- | |
|
152 | # Do the actual setup now | |
|
153 | #--------------------------------------------------------------------------- | |
|
154 | ||
|
155 | setup_args['packages'] = packages | |
|
156 | setup_args['package_data'] = package_data | |
|
157 | setup_args['scripts'] = scripts | |
|
158 | setup_args['data_files'] = data_files | |
|
159 | setup_args.update(setuptools_extra_args) | |
|
160 | ||
|
161 | if __name__ == '__main__': | |
|
162 | setup(**setup_args) |
General Comments 0
You need to be logged in to leave comments.
Login now