Changeset 81

Show
Ignore:
Timestamp:
Fri Jul 28 16:37:02 2006
Author:
jpellerin
Message:

Fixed #72: :Class now selects all testlike methods of the class. Also
simplified wantClass, etc: no need to check against test addresses that
don't include a callable part, since presumably those that would
disqualify the callable (because they don't match its container) would
already have removed the container module from consideration.

Files:

Legend:

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

    r62 r81  
    113 113         assert not s.wantClass(TestMe)  
    114 114  
    115           s.tests = [ 'something:Bar' ]  
      115         s.tests = [ ':Bar.baz' ]  
      116         assert s.wantClass(Bar)  
      117         assert not s.wantClass(Foo)  
      118         assert not s.wantClass(TestMe)  
      119  
      120         s.tests = [ ':Blah' ]  
    116 121         assert not s.wantClass(Bar)  
    117 122         assert not s.wantClass(Foo)  
    118 123         assert not s.wantClass(TestMe)  
    119 124  
    120           s.tests = [ '%s:Bar' % __name__ ]  
    121           assert s.wantClass(Bar)  
      125         s.tests = [ ':Blah.baz' ]  
      126         assert not s.wantClass(Bar)  
    122 127         assert not s.wantClass(Foo)  
    123 128         assert not s.wantClass(TestMe)  
    124 129  
    125 130         s.tests = [ __name__ ]  
    126           assert s.wantClass(Bar)  
    127           assert not s.wantClass(Foo)  
    128           assert s.wantClass(TestMe)  
      131         assert s.wantClass(Bar) == [None]  
      132         assert s.wantClass(Foo) is None  
      133         assert s.wantClass(TestMe) == [None]  
    129 134  
    130 135         s.tests = [ __file__ ]  
    131           assert s.wantClass(Bar)  
    132           assert not s.wantClass(Foo)  
    133           assert s.wantClass(TestMe)  
      136         assert s.wantClass(Bar) == [None]  
      137         assert s.wantClass(Foo) is None  
      138         assert s.wantClass(TestMe)  == [None]  
    134 139          
    135 140     def test_want_directory(self):  
     
    207 212         assert not s.wantFunction(foo)  
    208 213  
      214         s.tests = [ __file__ ]  
      215         assert s.wantFunction(test_bar)  
      216         assert s.wantFunction(test_foo)  
      217         assert not s.wantFunction(foo)  
      218  
    209 219     def test_want_method(self):  
    210 220         class Baz:  
     
    226 236         assert not s.wantMethod(Baz.test_me)                 
    227 237         assert not s.wantMethod(Baz.other)  
      238  
      239         s.tests = [ ':Baz' ]  
      240         assert s.wantMethod(Baz.test_too)  
      241         assert s.wantMethod(Baz.test_me)  
      242         assert not s.wantMethod(Baz.other)  
      243  
      244         s.tests = [ ':Spaz' ]  
      245         assert not s.wantMethod(Baz.test_too)  
      246         assert not s.wantMethod(Baz.test_me)  
      247         assert not s.wantMethod(Baz.other)  
    228 248          
    229 249     def test_want_module(self):  
  • trunk/nose/selector.py

    r80 r81  
    101 101  
    102 102     def classInTests(self, cls):  
    103           def matches(clb, funcname):  
      103         def match(filename, modname, funcname, cls=cls):  
      104             if funcname is None:  
      105                 return None  
    104 106             try:  
    105 107                 clsn, dummy = funcname.split('.')  
    106               except ValueError:  
      108             except (ValueError, AttributeError):  
    106 108                 clsn, dummy = funcname, None  
    107               return clb.__name__ == clsn  
    108           return self.callableInTests(cls, matches)  
      109             return cls.__name__ == clsn  
      110         return self.anytest(match)  
    109 111  
    110 112     def configure(self, conf):  
     
    147 149  
    148 150     def funcInTests(self, func):  
    149           def matches(func, funcname):  
      151         def match(filename, modname, funcname, func=func):  
      152             if funcname is None:  
      153                 return None  
    150 154             return func.__name__ == funcname  
    151           return self.callableInTests(func, matches)  
      155         return self.anytest(match)  
    151 155          
    152 156     def matches(self, name):  
     
    163 167      
    164 168     def methodInTests(self, method):  
    165           def matches(clb, funcname):  
    166               mname = "%s.%s" % (clb.im_class.__name__, clb.__name__)  
    167               return mname == funcname  
    168           return self.callableInTests(method, matches)  
      169         """Determine if a method is listed in the requested tests. To  
      170         be consideed a match, the method's class must be in the class  
      171         part of the test address, and the function part of the test  
      172         address must match the method name or be None.  
      173         """  
      174         def match(filename, modname, funcname, method=method):  
      175             if funcname is None:  
      176                 return None  
      177             mcls = method.im_class.__name__  
      178             mname = method.__name__  
      179             try:  
      180                 cls, func = funcname.split('.')  
      181             except (ValueError, AttributeError):  
      182                 cls, func = funcname, None  
      183             return mcls == cls and (mname == func or func is None)  
      184         return self.anytest(match)  
    169 185  
    170 186     def moduleInTests(self, module, either=False):