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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import inspect
  5. import sys
  6. from decorator_msim import decorator, update_wrapper
  7. from decorators_numpy import *
  8.  
  9. def apply_wrapper(wrapper, func):
  10.     import nose.tools as nose
  11.     return decorator(wrapper, nose.tools.make_decorator(func)(wrapper))
  12.  
  13.  
  14. def make_label_dec(label, ds = None):
  15.     if isinstance(label, basestring):
  16.         labels = [
  17.             label]
  18.     else:
  19.         labels = label
  20.     
  21.     tmp = lambda : pass
  22.     for label in labels:
  23.         setattr(tmp, label, True)
  24.     
  25.     
  26.     def decor(f):
  27.         for label in labels:
  28.             setattr(f, label, True)
  29.         
  30.         return f
  31.  
  32.     if ds is None:
  33.         ds = 'Labels a test as %r.' % label
  34.     
  35.     decor.__doc__ = ds
  36.     return decor
  37.  
  38.  
  39. def skipif(skip_condition, msg = None):
  40.     
  41.     def skip_decorator(f):
  42.         import nose
  43.         
  44.         def get_msg(func, msg = None):
  45.             if msg is None:
  46.                 out = 'Test skipped due to test condition.'
  47.             else:
  48.                 out = msg
  49.             return 'Skipping test: %s. %s' % (func.__name__, out)
  50.  
  51.         
  52.         def skipper_func(*args, **kwargs):
  53.             if skip_val():
  54.                 raise nose.SkipTest(get_msg(f, msg))
  55.             skip_val()
  56.             return f(*args, **kwargs)
  57.  
  58.         
  59.         def skipper_gen(*args, **kwargs):
  60.             if skip_val():
  61.                 raise nose.SkipTest(get_msg(f, msg))
  62.             skip_val()
  63.             for x in f(*args, **kwargs):
  64.                 yield x
  65.             
  66.  
  67.         if nose.util.isgenerator(f):
  68.             skipper = skipper_gen
  69.         else:
  70.             skipper = skipper_func
  71.         return nose.tools.make_decorator(f)(skipper)
  72.  
  73.     return skip_decorator
  74.  
  75.  
  76. def skip(msg = None):
  77.     return skipif(True, msg)
  78.  
  79.  
  80. def numpy_not_available():
  81.     
  82.     try:
  83.         import numpy
  84.         np_not_avail = False
  85.     except ImportError:
  86.         np_not_avail = True
  87.  
  88.     return np_not_avail
  89.  
  90. skip_doctest = make_label_dec('skip_doctest', 'Decorator - mark a function or method for skipping its doctest.\n\n    This decorator allows you to mark a function whose docstring you wish to\n    omit from testing, while preserving the docstring for introspection, help,\n    etc.')
  91. skip_win32 = skipif(sys.platform == 'win32', 'This test does not run under Windows')
  92. skip_linux = skipif(sys.platform == 'linux2', 'This test does not run under Linux')
  93. skip_osx = skipif(sys.platform == 'darwin', 'This test does not run under OS X')
  94. skip_if_not_win32 = skipif(sys.platform != 'win32', 'This test only runs under Windows')
  95. skip_if_not_linux = skipif(sys.platform != 'linux2', 'This test only runs under Linux')
  96. skip_if_not_osx = skipif(sys.platform != 'darwin', 'This test only runs under OSX')
  97. skipif_not_numpy = skipif(numpy_not_available, 'This test requires numpy')
  98. skipknownfailure = skip('This test is known to fail')
  99.