Changeset 35

Show
Ignore:
Timestamp:
Sat May 6 13:11:25 2006
Author:
jpellerin
Message:

r932@Jason-Pellerins-Computer: jhp | 2006-05-06 13:09:20 -0500
Better function/module tests in loader (#56)

Files:

Legend:

Unmodified
Added
Removed
Modified
  • branches/0.9-stable/unit_tests/test_loader.py

    r24 r35  
    190 190             count += 1  
    191 191         assert count == 5  
      192  
      193     def test_get_module_funcs(self):  
      194         from StringIO import StringIO  
      195          
      196         m = Mod('testo', __path__=None)  
      197  
      198         def test_func():  
      199             pass  
      200  
      201         class NotTestFunc(object):  
      202             def __call__(self):  
      203                 pass  
      204  
      205         class Selector:  
      206             classes = []  
      207             funcs = []  
      208              
      209             def wantClass(self, test):  
      210                 self.classes.append(test)  
      211                 return False  
      212              
      213             def wantFunction(self, test):  
      214                 self.funcs.append(test)  
      215                 return True             
      216         sel = Selector()  
      217          
      218         m.test_func = test_func  
      219         m.test_func_not_really = NotTestFunc()  
      220         m.StringIO = StringIO  
      221         m.buffer = StringIO()  
      222          
      223         l = loader.TestLoader(selector=sel)  
      224         tests = l.testsInModule(m)  
      225          
      226         print tests  
      227         print sel.funcs  
      228         assert test_func in sel.funcs  
      229         assert not m.test_func_not_really in sel.funcs  
      230         assert len(sel.funcs) == 1  
    192 231          
    193 232 if __name__ == '__main__':  
  • branches/0.9-stable/nose/loader.py

    r28 r35  
    7 7 import unittest  
    8 8  
      9 from inspect import isfunction, ismethod  
    9 10 from nose.case import *  
    10 11 from nose.config import Config  
     
    270 271                     tests.append(TestClass(self.loadTestsFromTestCase,  
    271 272                                            self.conf, test))  
    272               elif callable(test):  
    273                   log.debug("candidate %s is a callable", test)  
      273             elif isfunction(test):  
      274                 log.debug("candidate %s is a function", test)  
    274 275                 if not self.selector.wantFunction(test):  
    275 276                     continue  
     
    296 297             attr = getattr(cls, item)  
    297 298             log.debug("Check if selector wants %s (%s)", attr, cls)  
    298               if callable(attr) and self.selector.wantMethod(attr):  
      299             if ismethod(attr) and self.selector.wantMethod(attr):  
    298 299                 collected.append(item)                 
    299 300         # base class methods; include those not overridden