##// END OF EJS Templates
Moving tests/test_magic.py and support files to core/tests.
Brian Granger -
Show More
1 NO CONTENT: file renamed from IPython/tests/obj_del.py to IPython/core/tests/obj_del.py
1 NO CONTENT: file renamed from IPython/tests/refbug.py to IPython/core/tests/refbug.py
1 NO CONTENT: file renamed from IPython/tests/tclass.py to IPython/core/tests/tclass.py
@@ -1,249 +1,249 b''
1 1 """Tests for various magic functions.
2 2
3 3 Needs to be run by nose (to make ipython session available).
4 4 """
5 5
6 6 import os
7 7 import sys
8 8 import tempfile
9 9 import types
10 10
11 11 import nose.tools as nt
12 12
13 13 from IPython.utils.platutils import find_cmd, get_long_path_name
14 14 from IPython.testing import decorators as dec
15 15 from IPython.testing import tools as tt
16 16
17 17 #-----------------------------------------------------------------------------
18 18 # Test functions begin
19 19
20 20 def test_rehashx():
21 21 # clear up everything
22 22 _ip.IP.alias_table.clear()
23 23 del _ip.db['syscmdlist']
24 24
25 25 _ip.magic('rehashx')
26 26 # Practically ALL ipython development systems will have more than 10 aliases
27 27
28 28 assert len(_ip.IP.alias_table) > 10
29 29 for key, val in _ip.IP.alias_table.items():
30 30 # we must strip dots from alias names
31 31 assert '.' not in key
32 32
33 33 # rehashx must fill up syscmdlist
34 34 scoms = _ip.db['syscmdlist']
35 35 assert len(scoms) > 10
36 36
37 37
38 38 def doctest_hist_f():
39 39 """Test %hist -f with temporary filename.
40 40
41 41 In [9]: import tempfile
42 42
43 43 In [10]: tfile = tempfile.mktemp('.py','tmp-ipython-')
44 44
45 45 In [11]: %history -n -f $tfile 3
46 46 """
47 47
48 48
49 49 def doctest_hist_r():
50 50 """Test %hist -r
51 51
52 52 XXX - This test is not recording the output correctly. Not sure why...
53 53
54 54 In [6]: x=1
55 55
56 56 In [7]: hist -n -r 2
57 57 x=1 # random
58 58 hist -n -r 2 # random
59 59 """
60 60
61 61 # This test is known to fail on win32.
62 62 # See ticket https://bugs.launchpad.net/bugs/366334
63 63 def test_obj_del():
64 64 """Test that object's __del__ methods are called on exit."""
65 65 test_dir = os.path.dirname(__file__)
66 66 del_file = os.path.join(test_dir,'obj_del.py')
67 67 ipython_cmd = find_cmd('ipython')
68 68 out = _ip.IP.getoutput('%s %s' % (ipython_cmd, del_file))
69 69 nt.assert_equals(out,'obj_del.py: object A deleted')
70 70
71 71
72 72 def test_shist():
73 73 # Simple tests of ShadowHist class - test generator.
74 74 import os, shutil, tempfile
75 75
76 76 from IPython.Extensions import pickleshare
77 from IPython.history import ShadowHist
77 from IPython.core.history import ShadowHist
78 78
79 79 tfile = tempfile.mktemp('','tmp-ipython-')
80 80
81 81 db = pickleshare.PickleShareDB(tfile)
82 82 s = ShadowHist(db)
83 83 s.add('hello')
84 84 s.add('world')
85 85 s.add('hello')
86 86 s.add('hello')
87 87 s.add('karhu')
88 88
89 89 yield nt.assert_equals,s.all(),[(1, 'hello'), (2, 'world'), (3, 'karhu')]
90 90
91 91 yield nt.assert_equal,s.get(2),'world'
92 92
93 93 shutil.rmtree(tfile)
94 94
95 95 @dec.skipif_not_numpy
96 96 def test_numpy_clear_array_undec():
97 97 _ip.ex('import numpy as np')
98 98 _ip.ex('a = np.empty(2)')
99 99
100 100 yield nt.assert_true,'a' in _ip.user_ns
101 101 _ip.magic('clear array')
102 102 yield nt.assert_false,'a' in _ip.user_ns
103 103
104 104
105 105 @dec.skip()
106 106 def test_fail_dec(*a,**k):
107 107 yield nt.assert_true, False
108 108
109 109 @dec.skip('This one shouldn not run')
110 110 def test_fail_dec2(*a,**k):
111 111 yield nt.assert_true, False
112 112
113 113 @dec.skipknownfailure
114 114 def test_fail_dec3(*a,**k):
115 115 yield nt.assert_true, False
116 116
117 117
118 118 def doctest_refbug():
119 119 """Very nasty problem with references held by multiple runs of a script.
120 120 See: https://bugs.launchpad.net/ipython/+bug/269966
121 121
122 122 In [1]: _ip.IP.clear_main_mod_cache()
123 123
124 124 In [2]: run refbug
125 125
126 126 In [3]: call_f()
127 127 lowercased: hello
128 128
129 129 In [4]: run refbug
130 130
131 131 In [5]: call_f()
132 132 lowercased: hello
133 133 lowercased: hello
134 134 """
135 135
136 136 #-----------------------------------------------------------------------------
137 137 # Tests for %run
138 138 #-----------------------------------------------------------------------------
139 139
140 140 # %run is critical enough that it's a good idea to have a solid collection of
141 141 # tests for it, some as doctests and some as normal tests.
142 142
143 143 def doctest_run_ns():
144 144 """Classes declared %run scripts must be instantiable afterwards.
145 145
146 146 In [11]: run tclass foo
147 147
148 148 In [12]: isinstance(f(),foo)
149 149 Out[12]: True
150 150 """
151 151
152 152
153 153 def doctest_run_ns2():
154 154 """Classes declared %run scripts must be instantiable afterwards.
155 155
156 156 In [4]: run tclass C-first_pass
157 157
158 158 In [5]: run tclass C-second_pass
159 159 tclass.py: deleting object: C-first_pass
160 160 """
161 161
162 162 @dec.skip_win32
163 163 def doctest_run_builtins():
164 164 """Check that %run doesn't damage __builtins__ via a doctest.
165 165
166 166 This is similar to the test_run_builtins, but I want *both* forms of the
167 167 test to catch any possible glitches in our testing machinery, since that
168 168 modifies %run somewhat. So for this, we have both a normal test (below)
169 169 and a doctest (this one).
170 170
171 171 In [1]: import tempfile
172 172
173 173 In [2]: bid1 = id(__builtins__)
174 174
175 175 In [3]: f = tempfile.NamedTemporaryFile()
176 176
177 177 In [4]: f.write('pass\\n')
178 178
179 179 In [5]: f.flush()
180 180
181 181 In [6]: print 'B1:',type(__builtins__)
182 182 B1: <type 'module'>
183 183
184 184 In [7]: %run $f.name
185 185
186 186 In [8]: bid2 = id(__builtins__)
187 187
188 188 In [9]: print 'B2:',type(__builtins__)
189 189 B2: <type 'module'>
190 190
191 191 In [10]: bid1 == bid2
192 192 Out[10]: True
193 193 """
194 194
195 195 # For some tests, it will be handy to organize them in a class with a common
196 196 # setup that makes a temp file
197 197
198 198 class TestMagicRun(object):
199 199
200 200 def setup(self):
201 201 """Make a valid python temp file."""
202 202 f = tempfile.NamedTemporaryFile()
203 203 f.write('pass\n')
204 204 f.flush()
205 205 self.tmpfile = f
206 206
207 207 def run_tmpfile(self):
208 208 # This fails on Windows if self.tmpfile.name has spaces or "~" in it.
209 209 # See below and ticket https://bugs.launchpad.net/bugs/366353
210 210 _ip.magic('run %s' % self.tmpfile.name)
211 211
212 212 # See https://bugs.launchpad.net/bugs/366353
213 213 @dec.skip_if_not_win32
214 214 def test_run_tempfile_path(self):
215 215 tt.assert_equals(True,False,"%run doesn't work with tempfile paths on win32.")
216 216
217 217 # See https://bugs.launchpad.net/bugs/366353
218 218 @dec.skip_win32
219 219 def test_builtins_id(self):
220 220 """Check that %run doesn't damage __builtins__ """
221 221
222 222 # Test that the id of __builtins__ is not modified by %run
223 223 bid1 = id(_ip.user_ns['__builtins__'])
224 224 self.run_tmpfile()
225 225 bid2 = id(_ip.user_ns['__builtins__'])
226 226 tt.assert_equals(bid1, bid2)
227 227
228 228 # See https://bugs.launchpad.net/bugs/366353
229 229 @dec.skip_win32
230 230 def test_builtins_type(self):
231 231 """Check that the type of __builtins__ doesn't change with %run.
232 232
233 233 However, the above could pass if __builtins__ was already modified to
234 234 be a dict (it should be a module) by a previous use of %run. So we
235 235 also check explicitly that it really is a module:
236 236 """
237 237 self.run_tmpfile()
238 238 tt.assert_equals(type(_ip.user_ns['__builtins__']),type(sys))
239 239
240 240 # See https://bugs.launchpad.net/bugs/366353
241 241 @dec.skip_win32
242 242 def test_prompts(self):
243 243 """Test that prompts correctly generate after %run"""
244 244 self.run_tmpfile()
245 245 p2 = str(_ip.IP.outputcache.prompt2).strip()
246 246 nt.assert_equals(p2[:3], '...')
247 247
248 248 def teardown(self):
249 249 self.tmpfile.close()
@@ -1,270 +1,263 b''
1 1 =============================
2 2 IPython module reorganization
3 3 =============================
4 4
5 5 Currently, IPython has many top-level modules that serve many different purposes.
6 6 The lack of organization make it very difficult for developers to work on IPython
7 7 and understand its design. This document contains notes about how we will reorganize
8 8 the modules into sub-packages.
9 9
10 10 .. warning::
11 11
12 12 This effort will possibly break third party packages that use IPython as
13 13 a library or hack on the IPython internals.
14 14
15 15 .. warning::
16 16
17 17 This effort will result in the removal from IPython of certain modules
18 18 that are not used anymore, don't currently work, are unmaintained, etc.
19 19
20 20
21 21 Current subpackges
22 22 ==================
23 23
24 24 IPython currently has the following sub-packages:
25 25
26 26 * :mod:`IPython.config`
27 27
28 28 * :mod:`IPython.Extensions`
29 29
30 30 * :mod:`IPython.external`
31 31
32 32 * :mod:`IPython.frontend`
33 33
34 34 * :mod:`IPython.gui`
35 35
36 36 * :mod:`IPython.kernel`
37 37
38 38 * :mod:`IPython.testing`
39 39
40 40 * :mod:`IPython.tests`
41 41
42 42 * :mod:`IPython.tools`
43 43
44 44 * :mod:`IPython.UserConfig`
45 45
46 46 New Subpackages to be created
47 47 =============================
48 48
49 49 We propose to create the following new sub-packages:
50 50
51 51 * :mod:`IPython.core`. This sub-package will contain the core of the IPython
52 52 interpreter, but none of its extended capabilities.
53 53
54 54 * :mod:`IPython.lib`. IPython has many extended capabilities that are not part
55 55 of the IPython core. These things will go here. Any better names than
56 56 :mod:`IPython.lib`?
57 57
58 58 * :mod:`IPython.utils`. This sub-package will contain anything that might
59 59 eventually be found in the Python standard library, like things in
60 60 :mod:`genutils`. Each sub-module in this sub-package should contain
61 61 functions and classes that serve a single purpose.
62 62
63 63 * :mod:`IPython.deathrow`. This is for code that is untested and/or rotting
64 64 and needs to be removed from IPython. Eventually all this code will either
65 65 i) be revived by someone willing to maintain it with tests and docs and
66 66 re-included into IPython or 2) be removed from IPython proper, but put into
67 67 a separate top-level (not IPython) package that we keep around. No new code
68 68 will be allowed here.
69 69
70 70 * :mod:`IPython.quarantine`. This is for code that doesn't meet IPython's
71 71 standards, but that we plan on keeping. To be moved out of this sub-package
72 72 a module needs to have a maintainer, tests and documentation.
73 73
74 74 Prodecure
75 75 =========
76 76
77 77 1. Move the file to its new location with its new name.
78 78 2. Rename all import statements to reflect the change.
79 79 3. Run PyFlakes on each changes module.
80 80 3. Add tests/test_imports.py to test it.
81 81
82 82 Need to modify iptests to properly skip modules that are no longer top
83 83 level modules.
84 84
85 85 Need to update the top level IPython/__init__.py file.
86 86
87 87 Where things will be moved
88 88 ==========================
89 89
90 Top-level modules:
91
90 92 * :file:`background_jobs.py`. Move to :file:`IPython/lib/backgroundjobs.py`.
91 93
92 94 * :file:`ColorANSI.py`. Move to :file:`IPython/utils/coloransi.py`.
93 95
94 96 * :file:`completer.py`. Move to :file:`IPython/core/completer.py`.
95 97
96 98 * :file:`ConfigLoader.py`. Move to :file:`IPython/config/configloader.py`.
97 99
98 100 * :file:`CrashHandler.py`. Move to :file:`IPython/core/crashhandler`.
99 101
100 102 * :file:`Debugger.py`. Move to :file:`IPython/core/debugger.py`.
101 103
102 104 * :file:`deep_reload.py`. Move to :file:`IPython/lib/deepreload.py`.
103 105
104 106 * :file:`demo.py`. Move to :file:`IPython/lib/demo.py`.
105 107
106 108 * :file:`DPyGetOpt.py`. Move to :mod:`IPython.utils` and replace with newer options parser.
107 109
108 110 * :file:`dtutils.py`. Move to :file:`IPython.deathrow`.
109 111
110 112 * :file:`excolors.py`. Move to :file:`IPython.core` or :file:`IPython.config`.
111 113 Maybe move to :mod:`IPython.lib` or :mod:`IPython.python`?
112 114
113 115 * :file:`FakeModule.py`. Move to :file:`IPython/core/fakemodule.py`.
114 116
115 117 * :file:`generics.py`. Move to :file:`IPython.python`.
116 118
117 119 * :file:`genutils.py`. Move to :file:`IPython.utils`.
118 120
119 121 * :file:`Gnuplot2.py`. Move to :file:`IPython.sandbox`.
120 122
121 123 * :file:`GnuplotInteractive.py`. Move to :file:`IPython.sandbox`.
122 124
123 125 * :file:`GnuplotRuntime.py`. Move to :file:`IPython.sandbox`.
124 126
125 127 * :file:`numutils.py`. Move to :file:`IPython.sandbox`.
126 128
127 129 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
128 130
129 131 * :file:`Extensions`. This needs to be gone through separately. Minimally,
130 132 the package should be renamed to :file:`extensions`.
131 133
132 134 * :file:`history.py`. Move to :file:`IPython.core`.
133 135
134 136 * :file:`hooks.py`. Move to :file:`IPython.core`.
135 137
136 138 * :file:`ipapi.py`. Move to :file:`IPython.core`.
137 139
138 140 * :file:`iplib.py`. Move to :file:`IPython.core`.
139 141
140 142 * :file:`ipmaker.py`: Move to :file:`IPython.core`.
141 143
142 144 * :file:`ipstruct.py`. Move to :file:`IPython.python`.
143 145
144 146 * :file:`irunner.py`. Move to :file:`IPython.scripts`. ???
145 147
146 148 * :file:`Itpl.py`. Move to :file:`deathrow/Itpl.py`. Copy already in
147 149 :file:`IPython.external`.
148 150
149 151 * :file:`Logger.py`. Move to :file:`IPython/core/logger.py`.
150 152
151 153 * :file:`macro.py`. Move to :file:`IPython.core`.
152 154
153 155 * :file:`Magic.py`. Move to :file:`IPython/core/magic.py`.
154 156
155 157 * :file:`OInspect.py`. Move to :file:`IPython/core/oinspect.py`.
156 158
157 159 * :file:`OutputTrap.py`. Move to :file:`IPython/core/outputtrap.py`.
158 160
159 161 * :file:`platutils.py`. Move to :file:`IPython.python`.
160 162
161 163 * :file:`platutils_dummy.py`. Move to :file:`IPython.python`.
162 164
163 165 * :file:`platutils_posix.py`. Move to :file:`IPython.python`.
164 166
165 167 * :file:`platutils_win32.py`. Move to :file:`IPython.python`.
166 168
167 169 * :file:`prefilter.py`: Move to :file:`IPython.core`.
168 170
169 171 * :file:`Prompts.py`. Move to :file:`IPython/core/prompts.py` or
170 172 :file:`IPython/frontend/prompts.py`.
171 173
172 174 * :file:`PyColorize.py`. Replace with pygments? If not, move to
173 175 :file:`IPython/core/pycolorize.py`. Maybe move to :mod:`IPython.lib` or
174 176 :mod:`IPython.python`?
175 177
176 178 * :file:`Release.py`. Move to ??? or remove?
177 179
178 180 * :file:`rlineimpl.py`. Move to :file:`IPython.core`.
179 181
180 182 * :file:`shadowns.py`. Move to :file:`IPython.core`.
181 183
182 184 * :file:`Shell.py`. Move to :file:`IPython.core.shell.py` or
183 185 :file:`IPython/frontend/shell.py`.
184 186
185 187 * :file:`shellglobals.py`. Move to :file:`IPython.core`.
186 188
187 189 * :file:`strdispatch.py`. Move to :file:`IPython.python`.
188 190
191 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
192
193 * :file:`ultraTB.py`. Move to :file:`IPython/core/ultratb.py`.
194
195 * :file:`upgrade_dir.py`. Move to :file:`IPython/utils/upgradedir.py`.
196
197 * :file:`usage.py`. Move to :file:`IPython.core`.
198
199 * :file:`wildcard.py`. Move to :file:`IPython.utils`.
200
201 * :file:`winconsole.py`. Move to :file:`IPython.utils`.
202
203 Top-level sub-packages:
204
189 205 * :file:`testing`. Good where it is.
190 206
191 207 * :file:`tests`. Good where it is.
192 208
193 209 * :file:`tools`. Things in here need to be looked at and moved elsewhere like
194 :file:`IPython.python`.
210 :file:`IPython.utils`.
195 211
196 212 * :file:`UserConfig`. Move to a subdirectory of :file:`IPython.config`.
197 213
198
199
200
201 214 * :file:`config`. Good where it is!
202 215
203 216 * :file:`external`. Good where it is!
204 217
205 218 * :file:`frontend`. Good where it is!
206 219
207 220
208 221
209 222 * :file:`gui`. Eventually this should be moved to a subdir of
210 223 :file:`IPython.frontend`.
211 224
212
213
214
215
216
217
218
219
220
221
222 225 * :file:`kernel`. Good where it is.
223 226
224 227
225 228
226 229
227 230
228 231
229 232
230 233
231 234
232 235
233 236
234 237
235 238
236 239
237 240
238 * :file:`twshell.py`. Move to :file:`IPython.sandbox`.
239
240 * :file:`ultraTB.py`. Move to :file:`IPython/core/ultratb.py`.
241
242 * :file:`upgrade_dir.py`. Move to :file:`IPython/utils/upgradedir.py`.
243
244 * :file:`usage.py`. Move to :file:`IPython.core`.
245
246 * :file:`wildcard.py`. Move to :file:`IPython.utils`.
247 241
248 * :file:`winconsole.py`. Move to :file:`IPython.lib`.
249 242
250 243 Other things
251 244 ============
252 245
253 246 When these files are moved around, a number of other things will happen at the same time:
254 247
255 248 1. Test files will be created for each module in IPython. Minimally, all
256 249 modules will be imported as a part of the test. This will serve as a
257 250 test of the module reorganization. These tests will be put into new
258 251 :file:`tests` subdirectories that each package will have.
259 252
260 253 2. PyFlakes and other code checkers will be run to look for problems.
261 254
262 255 3. Modules will be renamed to comply with PEP 8 naming conventions: all
263 256 lowercase and no special characters like ``-`` or ``_``.
264 257
265 258 4. Existing tests will be moved to the appropriate :file:`tests`
266 259 subdirectories.
267 260
268 261
269 262
270 263
General Comments 0
You need to be logged in to leave comments. Login now