Changeset 103

Show
Ignore:
Timestamp:
Tue Oct 10 16:42:02 2006
Author:
jpellerin
Message:

r3565@Jason-Pellerins-Computer: jhp | 2006-10-10 17:41:53 -0400

  • Fixed bugs in try_run when the attempted callable attribute isn't a function.
  • Updated CHANGELOG
Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/unit_tests/test_utils.py

    r76 r103  
    96 96         self.assertEqual(tolist('.*foo/.*,.1'), ['.*foo/.*', '.1'])  
    97 97  
      98     def test_try_run(self):  
      99         from nose.util import try_run  
      100         import imp  
      101  
      102         def bar():  
      103             pass  
      104  
      105         def bar_m(mod):  
      106             pass  
      107  
      108         class Bar:  
      109             def __call__(self):  
      110                 pass  
      111  
      112         class Bar_m:  
      113             def __call__(self, mod):  
      114                 pass  
      115          
      116         foo = imp.new_module('foo')  
      117         foo.bar = bar  
      118         foo.bar_m = bar_m  
      119         foo.i_bar = Bar()  
      120         foo.i_bar_m = Bar_m()  
      121  
      122         try_run(foo, ('bar',))  
      123         try_run(foo, ('bar_m',))  
      124         try_run(foo, ('i_bar',))  
      125         try_run(foo, ('i_bar_m',))  
    98 126          
    99 127 if __name__ == '__main__':  
  • trunk/nose/util.py

    r99 r103  
    179 179             if type(obj) == types.ModuleType:  
    180 180                 # py.test compatibility  
    181                   args, varargs, varkw, defaults = inspect.getargspec(func)  
      181                 try:  
      182                     args, varargs, varkw, defaults = inspect.getargspec(func)  
      183                 except TypeError:  
      184                     # Not a function. If it's callable, call it anyway  
      185                     if hasattr(func, '__call__'):  
      186                         func = func.__call__  
      187                     try:  
      188                         args, varargs, varkw, defaults = \  
      189                             inspect.getargspec(func)  
      190                         args.pop(0) # pop the self off  
      191                     except TypeError:  
      192                         raise TypeError("Attribute %s of %r is not a python "  
      193                                         "function. Only functions or callables"  
      194                                         " may be used as fixtures." %  
      195                                         (name, obj))                     
    182 196                 if len(args):  
    183 197                     log.debug("call fixture %s.%s(%s)", obj, name, obj)     
  • trunk/CHANGELOG

    r97 r103  
    28 28 - Fix log message in selector that could raise IndexError. Thanks Kumar  
    29 29   McMillan for the bug report and patch.  
      30 - Fix bug in handling doctest extension arguments specified in environment and  
      31   on command line. Thanks to Ian Bicking for the bug report.  
      32 - Fix bug in running fixtures (setup/teardown) that are not functions, and  
      33   report a better error message when a fixture is not callable. Thanks to Ian  
      34   Bicking for the bug report.  
    30 35    
    31 36 0.9.0