##// END OF EJS Templates
Robustness fixes in test suite machinery....
Fernando Perez -
r2494:c8938204
parent child
Show More
@@ -13,7 +13,7 class C(object):
13
13
14 def __del__(self):
14 def __del__(self):
15 print 'tclass.py: deleting object:',self.name
15 print 'tclass.py: deleting object:',self.name
16
16 sys.stdout.flush()
17
17
18 try:
18 try:
19 name = sys.argv[1]
19 name = sys.argv[1]
@@ -28,3 +28,4 else:
28 # This next print statement is NOT debugging, we're making the check on a
28 # This next print statement is NOT debugging, we're making the check on a
29 # completely separate process so we verify by capturing stdout:
29 # completely separate process so we verify by capturing stdout:
30 print 'ARGV 1-:', sys.argv[1:]
30 print 'ARGV 1-:', sys.argv[1:]
31 sys.stdout.flush()
@@ -57,6 +57,18 from IPython.testing.plugin.ipdoctest import IPythonDoctest
57
57
58 pjoin = path.join
58 pjoin = path.join
59
59
60
61 #-----------------------------------------------------------------------------
62 # Globals
63 #-----------------------------------------------------------------------------
64
65 # By default, we assume IPython has been installed. But if the test suite is
66 # being run from a source tree that has NOT been installed yet, this flag can
67 # be set to False by the entry point scripts, to let us know that we must call
68 # the source tree versions of the scripts which manipulate sys.path instead of
69 # assuming that things exist system-wide.
70 INSTALLED = True
71
60 #-----------------------------------------------------------------------------
72 #-----------------------------------------------------------------------------
61 # Warnings control
73 # Warnings control
62 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
@@ -88,7 +100,6 def test_for(mod):
88 else:
100 else:
89 return True
101 return True
90
102
91
92 have_curses = test_for('_curses')
103 have_curses = test_for('_curses')
93 have_wx = test_for('wx')
104 have_wx = test_for('wx')
94 have_wx_aui = test_for('wx.aui')
105 have_wx_aui = test_for('wx.aui')
@@ -100,6 +111,9 have_pexpect = test_for('pexpect')
100 have_gtk = test_for('gtk')
111 have_gtk = test_for('gtk')
101 have_gobject = test_for('gobject')
112 have_gobject = test_for('gobject')
102
113
114 #-----------------------------------------------------------------------------
115 # Functions and classes
116 #-----------------------------------------------------------------------------
103
117
104 def make_exclude():
118 def make_exclude():
105 """Make patterns of modules and packages to exclude from testing.
119 """Make patterns of modules and packages to exclude from testing.
@@ -190,10 +204,6 def make_exclude():
190 return exclusions
204 return exclusions
191
205
192
206
193 #-----------------------------------------------------------------------------
194 # Functions and classes
195 #-----------------------------------------------------------------------------
196
197 class IPTester(object):
207 class IPTester(object):
198 """Call that calls iptest or trial in a subprocess.
208 """Call that calls iptest or trial in a subprocess.
199 """
209 """
@@ -208,14 +218,22 class IPTester(object):
208
218
209 def __init__(self, runner='iptest', params=None):
219 def __init__(self, runner='iptest', params=None):
210 """Create new test runner."""
220 """Create new test runner."""
221 p = os.path
211 if runner == 'iptest':
222 if runner == 'iptest':
212 # Find our own 'iptest' script OS-level entry point. Don't look
223 if INSTALLED:
213 # system-wide, so we are sure we pick up *this one*. And pass
224 self.runner = tools.cmd2argv(
214 # through to subprocess call our own sys.argv
225 p.abspath(find_cmd('iptest'))) + sys.argv[1:]
215 self.runner = tools.cmd2argv(os.path.abspath(__file__)) + \
226 else:
216 sys.argv[1:]
227 # Find our own 'iptest' script OS-level entry point. Don't
228 # look system-wide, so we are sure we pick up *this one*. And
229 # pass through to subprocess call our own sys.argv
230 ippath = p.abspath(p.join(p.dirname(__file__),'..','..'))
231 script = p.join(ippath, 'iptest.py')
232 self.runner = tools.cmd2argv(script) + sys.argv[1:]
233
217 else:
234 else:
218 self.runner = tools.cmd2argv(os.path.abspath(find_cmd('trial')))
235 # For trial, it needs to be installed system-wide
236 self.runner = tools.cmd2argv(p.abspath(find_cmd('trial')))
219 if params is None:
237 if params is None:
220 params = []
238 params = []
221 if isinstance(params, str):
239 if isinstance(params, str):
@@ -296,7 +314,7 def make_runners():
296 trial_pkg_names.append('kernel')
314 trial_pkg_names.append('kernel')
297
315
298 # For debugging this code, only load quick stuff
316 # For debugging this code, only load quick stuff
299 #nose_pkg_names = ['core'] # dbg
317 #nose_pkg_names = ['core', 'extensions'] # dbg
300 #trial_pkg_names = [] # dbg
318 #trial_pkg_names = [] # dbg
301
319
302 # Make fully qualified package names prepending 'IPython.' to our name lists
320 # Make fully qualified package names prepending 'IPython.' to our name lists
@@ -322,19 +340,7 def run_iptest():
322 'This will be removed soon. Use IPython.testing.util instead')
340 'This will be removed soon. Use IPython.testing.util instead')
323
341
324 argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks
342 argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks
325
343
326 # I don't fully understand why we need this one, but
327 # depending on what directory the test suite is run
328 # from, if we don't give it, 0 tests get run.
329 # Specifically, if the test suite is run from the
330 # source dir with an argument (like 'iptest.py
331 # IPython.core', 0 tests are run, even if the same call
332 # done in this directory works fine). It appears that
333 # if the requested package is in the current dir,
334 # nose bails early by default. Since it's otherwise
335 # harmless, leave it in by default.
336 '--traverse-namespace',
337
338 # Loading ipdoctest causes problems with Twisted, but
344 # Loading ipdoctest causes problems with Twisted, but
339 # our test suite runner now separates things and runs
345 # our test suite runner now separates things and runs
340 # all Twisted tests with trial.
346 # all Twisted tests with trial.
@@ -350,6 +356,16 def run_iptest():
350 '--exe',
356 '--exe',
351 ]
357 ]
352
358
359 if nose.__version__ >= '0.11':
360 # I don't fully understand why we need this one, but depending on what
361 # directory the test suite is run from, if we don't give it, 0 tests
362 # get run. Specifically, if the test suite is run from the source dir
363 # with an argument (like 'iptest.py IPython.core', 0 tests are run,
364 # even if the same call done in this directory works fine). It appears
365 # that if the requested package is in the current dir, nose bails early
366 # by default. Since it's otherwise harmless, leave it in by default
367 # for nose >= 0.11, though unfortunately nose 0.10 doesn't support it.
368 argv.append('--traverse-namespace')
353
369
354 # Construct list of plugins, omitting the existing doctest plugin, which
370 # Construct list of plugins, omitting the existing doctest plugin, which
355 # ours replaces (and extends).
371 # ours replaces (and extends).
@@ -49,6 +49,13 from . import decorators as dec
49 # Globals
49 # Globals
50 #-----------------------------------------------------------------------------
50 #-----------------------------------------------------------------------------
51
51
52 # By default, we assume IPython has been installed. But if the test suite is
53 # being run from a source tree that has NOT been installed yet, this flag can
54 # be set to False by the entry point scripts, to let us know that we must call
55 # the source tree versions of the scripts which manipulate sys.path instead of
56 # assuming that things exist system-wide.
57 INSTALLED = True
58
52 # Make a bunch of nose.tools assert wrappers that can be used in test
59 # Make a bunch of nose.tools assert wrappers that can be used in test
53 # generators. This will expose an assert* function for each one in nose.tools.
60 # generators. This will expose an assert* function for each one in nose.tools.
54
61
@@ -248,16 +255,20 def ipexec(fname, options=None):
248 # Find the ipython script from the package we're using, so that the test
255 # Find the ipython script from the package we're using, so that the test
249 # suite can be run from the source tree without an installed IPython
256 # suite can be run from the source tree without an installed IPython
250 p = os.path
257 p = os.path
251 ippath = p.abspath(p.join(p.dirname(__file__),'..','..'))
258 if INSTALLED:
252 ipython_script = p.join(ippath, 'ipython.py')
259 ipython_cmd = platutils.find_cmd('ipython')
253 ipython_cmd = 'python "%s"' % ipython_script
260 else:
261 ippath = p.abspath(p.join(p.dirname(__file__),'..','..'))
262 ipython_script = p.join(ippath, 'ipython.py')
263 ipython_cmd = 'python "%s"' % ipython_script
254 # Absolute path for filename
264 # Absolute path for filename
255 full_fname = p.join(test_dir, fname)
265 full_fname = p.join(test_dir, fname)
256 full_cmd = '%s %s "%s"' % (ipython_cmd, cmdargs, full_fname)
266 full_cmd = '%s %s %s' % (ipython_cmd, cmdargs, full_fname)
267 #print >> sys.stderr, 'FULL CMD:', full_cmd # dbg
257 return genutils.getoutputerror(full_cmd)
268 return genutils.getoutputerror(full_cmd)
258
269
259
270
260 def ipexec_validate(fname, expected_out, expected_err=None,
271 def ipexec_validate(fname, expected_out, expected_err='',
261 options=None):
272 options=None):
262 """Utility to call 'ipython filename' and validate output/error.
273 """Utility to call 'ipython filename' and validate output/error.
263
274
@@ -287,9 +298,18 def ipexec_validate(fname, expected_out, expected_err=None,
287 import nose.tools as nt
298 import nose.tools as nt
288
299
289 out, err = ipexec(fname)
300 out, err = ipexec(fname)
301 #print 'OUT', out # dbg
302 #print 'ERR', err # dbg
303 # If there are any errors, we must check those befor stdout, as they may be
304 # more informative than simply having an empty stdout.
305 if err:
306 if expected_err:
307 nt.assert_equals(err.strip(), expected_err.strip())
308 else:
309 raise ValueError('Running file %r produced error: %r' %
310 (fname, err))
311 # If no errors or output on stderr was expected, match stdout
290 nt.assert_equals(out.strip(), expected_out.strip())
312 nt.assert_equals(out.strip(), expected_out.strip())
291 if expected_err:
292 nt.assert_equals(err.strip(), expected_err.strip())
293
313
294
314
295 class TempFileMixin(object):
315 class TempFileMixin(object):
@@ -17,5 +17,10 import os, sys
17 this_dir = os.path.dirname(os.path.abspath(__file__))
17 this_dir = os.path.dirname(os.path.abspath(__file__))
18 sys.path.insert(0, this_dir)
18 sys.path.insert(0, this_dir)
19
19
20 import IPython.testing.tools as t
21 import IPython.testing.iptest as ipt
22 t.INSTALLED = False
23 ipt.INSTALLED = False
24
20 # Now proceed with execution
25 # Now proceed with execution
21 execfile(os.path.join(this_dir, 'IPython', 'scripts', 'iptest'))
26 execfile(os.path.join(this_dir, 'IPython', 'scripts', 'iptest'))
General Comments 0
You need to be logged in to leave comments. Login now