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