diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 90aa93e..df4b41e 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -71,6 +71,10 @@ warnings.filterwarnings('ignore', 'the sets module is deprecated', warnings.filterwarnings('ignore', 'the sha module is deprecated', DeprecationWarning) +# Wx on Fedora11 spits these out +warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch', + UserWarning) + #----------------------------------------------------------------------------- # Logic for skipping doctests #----------------------------------------------------------------------------- @@ -274,33 +278,34 @@ def make_runners(): """Define the top-level packages that need to be tested. """ - nose_packages = ['config', 'core', 'extensions', 'frontend', 'lib', - 'scripts', 'testing', 'utils', - # Note that we list the kernel here, though the bulk of it - # is twisted-based, because nose picks up doctests that - # twisted doesn't. - 'kernel'] + # Packages to be tested via nose, that only depend on the stdlib + nose_pkg_names = ['config', 'core', 'extensions', 'frontend', 'lib', + 'scripts', 'testing', 'utils' ] # The machinery in kernel needs twisted for real testing - trial_packages = ['kernel'] + trial_pkg_names = [] if have_wx: - nose_packages.append('gui') - - #nose_packages = ['config', 'utils'] # dbg - #trial_packages = [] # dbg - - nose_packages = ['IPython.%s' % m for m in nose_packages ] - trial_packages = ['IPython.%s' % m for m in trial_packages ] + nose_pkg_names.append('gui') - # Make runners, most with nose - nose_testers = [IPTester(params=v) for v in nose_packages] - runners = zip(nose_packages, nose_testers) - # And add twisted ones if conditions are met if have_zi and have_twisted and have_foolscap: - trial_testers = [IPTester('trial', params=v) for v in trial_packages] - runners.extend(zip(trial_packages, trial_testers)) - + # Note that we list the kernel here, though the bulk of it is + # twisted-based, because nose picks up doctests that twisted doesn't. + nose_pkg_names.append('kernel') + trial_pkg_names.append('kernel') + + # For debugging this code, only load quick stuff + #nose_pkg_names = ['config', 'utils'] # dbg + #trial_pkg_names = [] # dbg + + # Make fully qualified package names prepending 'IPython.' to our name lists + nose_packages = ['IPython.%s' % m for m in nose_pkg_names ] + trial_packages = ['IPython.%s' % m for m in trial_pkg_names ] + + # Make runners + runners = [ (v, IPTester('iptest', params=v)) for v in nose_packages ] + runners.extend([ (v, IPTester('trial', params=v)) for v in trial_packages ]) + return runners diff --git a/IPython/utils/baseutils.py b/IPython/utils/baseutils.py new file mode 100644 index 0000000..18979a1 --- /dev/null +++ b/IPython/utils/baseutils.py @@ -0,0 +1,51 @@ +"""Base utilities support for IPython. + +Warning: this is a module that other utilities modules will import from, so it +can ONLY depend on the standard library, and NOTHING ELSE. In particular, this +module can NOT import anything from IPython, or circular dependencies will arise. +""" + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +import subprocess + +#----------------------------------------------------------------------------- +# Functions +#----------------------------------------------------------------------------- + +def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): + """Return (standard output,standard error) of executing cmd in a shell. + + Accepts the same arguments as system(), plus: + + - split(0): if true, each of stdout/err is returned as a list split on + newlines. + + Note: a stateful version of this function is available through the + SystemExec class.""" + + if verbose or debug: print header+cmd + if not cmd: + if split: + return [],[] + else: + return '','' + if not debug: + p = subprocess.Popen(cmd, shell=True, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True) + pin, pout, perr = (p.stdin, p.stdout, p.stderr) + + tout = pout.read().rstrip() + terr = perr.read().rstrip() + pin.close() + pout.close() + perr.close() + if split: + return tout.split('\n'),terr.split('\n') + else: + return tout,terr diff --git a/IPython/utils/genutils.py b/IPython/utils/genutils.py index f4f5fa4..1757204 100644 --- a/IPython/utils/genutils.py +++ b/IPython/utils/genutils.py @@ -11,6 +11,7 @@ these things are also convenient when working at the command line. # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. #***************************************************************************** +from __future__ import absolute_import #**************************************************************************** # required modules from the Python standard library @@ -45,7 +46,7 @@ from IPython.external.Itpl import itpl,printpl from IPython.utils import platutils from IPython.utils.generics import result_display from IPython.external.path import path - +from .baseutils import getoutputerror #**************************************************************************** # Exceptions @@ -194,16 +195,19 @@ def warn(msg,level=2,exit_val=1): print >> Term.cerr,'Exiting.\n' sys.exit(exit_val) + def info(msg): """Equivalent to warn(msg,level=1).""" warn(msg,level=1) + def error(msg): """Equivalent to warn(msg,level=3).""" warn(msg,level=3) + def fatal(msg,exit_val=1): """Equivalent to warn(msg,exit_val=exit_val,level=4).""" @@ -282,6 +286,7 @@ except ImportError: This just returns clock() and zero.""" return time.clock(),0.0 + def timings_out(reps,func,*args,**kw): """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output) @@ -310,6 +315,7 @@ def timings_out(reps,func,*args,**kw): av_time = tot_time / reps return tot_time,av_time,out + def timings(reps,func,*args,**kw): """timings(reps,func,*args,**kw) -> (t_total,t_per_call) @@ -319,6 +325,7 @@ def timings(reps,func,*args,**kw): return timings_out(reps,func,*args,**kw)[0:2] + def timing(func,*args,**kw): """timing(func,*args,**kw) -> t_total @@ -348,6 +355,7 @@ def arg_split(s,posix=False): lex.whitespace_split = True return list(lex) + def system(cmd,verbose=0,debug=0,header=''): """Execute a system command, return its exit status. @@ -369,6 +377,7 @@ def system(cmd,verbose=0,debug=0,header=''): if not debug: stat = os.system(cmd) return stat + def abbrev_cwd(): """ Return abbreviated version of cwd, e.g. d:mydir """ cwd = os.getcwd().replace('\\','/') @@ -439,6 +448,7 @@ if os.name in ('nt','dos'): shell.__doc__ = shell_ori.__doc__ + def getoutput(cmd,verbose=0,debug=0,header='',split=0): """Dummy substitute for perl's backquotes. @@ -468,45 +478,11 @@ def getoutput(cmd,verbose=0,debug=0,header='',split=0): else: return output -def getoutputerror(cmd,verbose=0,debug=0,header='',split=0): - """Return (standard output,standard error) of executing cmd in a shell. - - Accepts the same arguments as system(), plus: - - - split(0): if true, each of stdout/err is returned as a list split on - newlines. - - Note: a stateful version of this function is available through the - SystemExec class.""" - - if verbose or debug: print header+cmd - if not cmd: - if split: - return [],[] - else: - return '','' - if not debug: - p = subprocess.Popen(cmd, shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - close_fds=True) - pin, pout, perr = (p.stdin, p.stdout, p.stderr) - - tout = pout.read().rstrip() - terr = perr.read().rstrip() - pin.close() - pout.close() - perr.close() - if split: - return tout.split('\n'),terr.split('\n') - else: - return tout,terr - # for compatibility with older naming conventions xsys = system bq = getoutput + class SystemExec: """Access the system and getoutput functions through a stateful interface. diff --git a/IPython/utils/platutils_posix.py b/IPython/utils/platutils_posix.py index a618d15..9a6a62d 100644 --- a/IPython/utils/platutils_posix.py +++ b/IPython/utils/platutils_posix.py @@ -11,12 +11,25 @@ to use these functions in platform agnostic fashion. # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. #***************************************************************************** +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- +from __future__ import absolute_import import sys import os +from .baseutils import getoutputerror + +#----------------------------------------------------------------------------- +# Globals +#----------------------------------------------------------------------------- + ignore_termtitle = True +#----------------------------------------------------------------------------- +# Functions +#----------------------------------------------------------------------------- def _dummy_op(*a, **b): """ A no-op function """ @@ -36,7 +49,7 @@ else: def find_cmd(cmd): """Find the full path to a command using which.""" - return os.popen('which %s' % cmd).read().strip() + return getoutputerror('which %s' % cmd)[0] def get_long_path_name(path):