home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1917 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  7.7 KB  |  274 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import os.path as path
  6. import sys
  7. import subprocess
  8. import tempfile
  9. import time
  10. import warnings
  11. import nose.plugins.builtin as nose
  12. from nose.core import TestProgram
  13. from IPython.platutils import find_cmd
  14. from IPython.testing.plugin.ipdoctest import IPythonDoctest
  15. pjoin = path.join
  16.  
  17. def test_for(mod):
  18.     
  19.     try:
  20.         __import__(mod)
  21.     except ImportError:
  22.         return False
  23.  
  24.     return True
  25.  
  26. have_curses = test_for('_curses')
  27. have_wx = test_for('wx')
  28. have_wx_aui = test_for('wx.aui')
  29. have_zi = test_for('zope.interface')
  30. have_twisted = test_for('twisted')
  31. have_foolscap = test_for('foolscap')
  32. have_objc = test_for('objc')
  33. have_pexpect = test_for('pexpect')
  34. EXCLUDE = [
  35.     pjoin('IPython', 'external'),
  36.     pjoin('IPython', 'frontend', 'process', 'winprocess.py'),
  37.     pjoin('IPython_doctest_plugin'),
  38.     pjoin('IPython', 'Gnuplot'),
  39.     pjoin('IPython', 'Extensions', 'ipy_'),
  40.     pjoin('IPython', 'Extensions', 'PhysicalQInput'),
  41.     pjoin('IPython', 'Extensions', 'PhysicalQInteractive'),
  42.     pjoin('IPython', 'Extensions', 'InterpreterPasteInput'),
  43.     pjoin('IPython', 'Extensions', 'scitedirector'),
  44.     pjoin('IPython', 'Extensions', 'numeric_formats'),
  45.     pjoin('IPython', 'testing', 'attic'),
  46.     pjoin('IPython', 'testing', 'tutils'),
  47.     pjoin('IPython', 'testing', 'tools'),
  48.     pjoin('IPython', 'testing', 'mkdoctests')]
  49. if not have_wx:
  50.     EXCLUDE.append(pjoin('IPython', 'Extensions', 'igrid'))
  51.     EXCLUDE.append(pjoin('IPython', 'gui'))
  52.     EXCLUDE.append(pjoin('IPython', 'frontend', 'wx'))
  53.  
  54. if not have_wx_aui:
  55.     EXCLUDE.append(pjoin('IPython', 'gui', 'wx', 'wxIPython'))
  56.  
  57. if not have_objc:
  58.     EXCLUDE.append(pjoin('IPython', 'frontend', 'cocoa'))
  59.  
  60. if not have_curses:
  61.     EXCLUDE.append(pjoin('IPython', 'Extensions', 'ibrowse'))
  62.  
  63. if not sys.platform == 'win32':
  64.     EXCLUDE.append(pjoin('IPython', 'platutils_win32'))
  65.  
  66. if sys.platform == 'win32':
  67.     EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'test_exampleip'))
  68.     EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'dtexample'))
  69.  
  70. if not os.name == 'posix':
  71.     EXCLUDE.append(pjoin('IPython', 'platutils_posix'))
  72.  
  73. if not have_pexpect:
  74.     EXCLUDE.append(pjoin('IPython', 'irunner'))
  75.  
  76. if not have_twisted:
  77.     EXCLUDE.append(pjoin('IPython', 'frontend', 'asyncfrontendbase'))
  78.     EXCLUDE.append(pjoin('IPython', 'frontend', 'prefilterfrontend'))
  79.     EXCLUDE.append(pjoin('IPython', 'frontend', 'frontendbase'))
  80.     EXCLUDE.append(pjoin('IPython', 'frontend', 'linefrontendbase'))
  81.     EXCLUDE.append(pjoin('IPython', 'frontend', 'tests', 'test_linefrontend'))
  82.     EXCLUDE.append(pjoin('IPython', 'frontend', 'tests', 'test_frontendbase'))
  83.     EXCLUDE.append(pjoin('IPython', 'frontend', 'tests', 'test_prefilterfrontend'))
  84.     EXCLUDE.append(pjoin('IPython', 'frontend', 'tests', 'test_asyncfrontendbase'))
  85.     EXCLUDE.append(pjoin('IPython', 'kernel', 'error'))
  86.     EXCLUDE.append(pjoin('IPython', 'testing', 'parametric'))
  87.     EXCLUDE.append(pjoin('IPython', 'testing', 'util'))
  88.     EXCLUDE.append(pjoin('IPython', 'testing', 'tests', 'test_decorators_trial'))
  89.  
  90.  
  91. def run_iptest():
  92.     warnings.filterwarnings('ignore', 'This will be removed soon.  Use IPython.testing.util instead')
  93.     argv = sys.argv + [
  94.         '--with-ipdoctest',
  95.         '--ipdoctest-tests',
  96.         '--ipdoctest-extension=txt',
  97.         '--detailed-errors',
  98.         '--exe']
  99.     has_tests = False
  100.     for arg in sys.argv:
  101.         if ('IPython' in arg and arg.endswith('.py') or ':' in arg) and '.py' in arg:
  102.             has_tests = True
  103.             break
  104.             continue
  105.     
  106.     if not has_tests:
  107.         argv.append('IPython')
  108.     
  109.     plugins = [
  110.         IPythonDoctest(EXCLUDE)]
  111.     for p in nose.plugins.builtin.plugins:
  112.         plug = p()
  113.         if plug.name == 'doctest':
  114.             continue
  115.         
  116.         plugins.append(plug)
  117.     
  118.     TestProgram(argv = argv, plugins = plugins)
  119.  
  120.  
  121. class IPTester(object):
  122.     
  123.     def __init__(self, runner = 'iptest', params = None):
  124.         if runner == 'iptest':
  125.             self.runner = [
  126.                 'iptest',
  127.                 '-v']
  128.         else:
  129.             self.runner = [
  130.                 find_cmd('trial')]
  131.         if params is None:
  132.             params = []
  133.         
  134.         if isinstance(params, str):
  135.             params = [
  136.                 params]
  137.         
  138.         self.params = params
  139.         self.call_args = self.runner + self.params
  140.  
  141.     if sys.platform == 'win32':
  142.         
  143.         def run(self):
  144.             curdir = os.getcwd()
  145.             os.chdir(tempfile.gettempdir())
  146.             stat = os.system(' '.join(self.call_args))
  147.             os.chdir(curdir)
  148.             return stat
  149.  
  150.     else:
  151.         
  152.         def run(self):
  153.             return subprocess.call(self.call_args)
  154.  
  155.  
  156.  
  157. def make_runners():
  158.     top_mod = [
  159.         'background_jobs.py',
  160.         'ColorANSI.py',
  161.         'completer.py',
  162.         'ConfigLoader.py',
  163.         'CrashHandler.py',
  164.         'Debugger.py',
  165.         'deep_reload.py',
  166.         'demo.py',
  167.         'DPyGetOpt.py',
  168.         'dtutils.py',
  169.         'excolors.py',
  170.         'FakeModule.py',
  171.         'generics.py',
  172.         'genutils.py',
  173.         'history.py',
  174.         'hooks.py',
  175.         'ipapi.py',
  176.         'iplib.py',
  177.         'ipmaker.py',
  178.         'ipstruct.py',
  179.         'Itpl.py',
  180.         'Logger.py',
  181.         'macro.py',
  182.         'Magic.py',
  183.         'OInspect.py',
  184.         'OutputTrap.py',
  185.         'platutils.py',
  186.         'prefilter.py',
  187.         'Prompts.py',
  188.         'PyColorize.py',
  189.         'Release.py',
  190.         'rlineimpl.py',
  191.         'shadowns.py',
  192.         'shellglobals.py',
  193.         'strdispatch.py',
  194.         'ultraTB.py',
  195.         'upgrade_dir.py',
  196.         'usage.py',
  197.         'wildcard.py',
  198.         'winconsole.py']
  199.     if have_twisted:
  200.         top_mod.append('twshell.py')
  201.     
  202.     if have_pexpect:
  203.         top_mod.append('irunner.py')
  204.     
  205.     if sys.platform == 'win32':
  206.         top_mod.append('platutils_win32.py')
  207.     elif os.name == 'posix':
  208.         top_mod.append('platutils_posix.py')
  209.     else:
  210.         top_mod.append('platutils_dummy.py')
  211.     top_pack = [
  212.         'config',
  213.         'Extensions',
  214.         'frontend',
  215.         'testing',
  216.         'tests',
  217.         'tools',
  218.         'UserConfig']
  219.     if have_wx:
  220.         top_pack.append('gui')
  221.     
  222.     modules = [ 'IPython.%s' % m[:-3] for m in top_mod ]
  223.     packages = [ 'IPython.%s' % m for m in top_pack ]
  224.     runners = top_pack([]([], [ IPTester(params = v) for v in packages ]))
  225.     runners['modules'] = IPTester(params = modules)
  226.     return runners
  227.  
  228.  
  229. def run_iptestall():
  230.     runners = make_runners()
  231.     failed = { }
  232.     t_start = time.time()
  233.     for name, runner in runners.iteritems():
  234.         print '*' * 77
  235.         print 'IPython test group:', name
  236.         res = runner.run()
  237.         if res:
  238.             failed[name] = res
  239.             continue
  240.     
  241.     t_end = time.time()
  242.     t_tests = t_end - t_start
  243.     nrunners = len(runners)
  244.     nfail = len(failed)
  245.     print 
  246.     print '*' * 77
  247.     print 'Ran %s test groups in %.3fs' % (nrunners, t_tests)
  248.     print 
  249.     if not failed:
  250.         print 'OK'
  251.     else:
  252.         print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners)
  253.         for name in failed:
  254.             failed_runner = runners[name]
  255.             print '-' * 40
  256.             print 'Runner failed:', name
  257.             print 'You may wish to rerun this one individually, with:'
  258.             print ' '.join(failed_runner.call_args)
  259.             print 
  260.         
  261.  
  262.  
  263. def main():
  264.     if len(sys.argv) == 1:
  265.         run_iptestall()
  266.     elif sys.argv[1] == 'all':
  267.         run_iptestall()
  268.     else:
  269.         run_iptest()
  270.  
  271. if __name__ == '__main__':
  272.     main()
  273.  
  274.