Changeset 123

Show
Ignore:
Timestamp:
Fri Nov 17 17:42:50 2006
Author:
jpellerin
Message:

Work on new loader/selector: selector unit tests pass

Files:

Legend:

Unmodified
Added
Removed
Modified
  • branches/new_loader/unit_tests/test_selector.py

    r87 r123  
      1 import logging  
    1 2 import os  
    2 3 import re  
     
    4 5 import nose.selector  
    5 6 from nose.config import Config  
    6   from nose.selector import log, Selector  
      7 from nose.selector import log, Selector, test_addr  
    6 7 from nose.util import absdir  
    7 8 from mock import Mod  
     
    10 11 class TestSelector(unittest.TestCase):  
    11 12  
    12       def test_anytest(self):  
    13    
    14           def exact_file_a(filename, modname, funcname):  
    15               if filename is None:  
    16                   return None  
    17               return filename == '/a/file.py'  
    18            
    19           def exact_file_b(filename, modname, funcname):  
    20               if filename is None:  
    21                   return None  
    22               return filename == '/a/nother/file.py'  
    23    
    24           def exact_module_a(filename, modname, funcname):  
    25               if modname is None:  
    26                   return None  
    27               return modname == 'some.module'  
    28    
    29           def exact_module_b(filename, modname, funcname):  
    30               if modname is None:  
    31                   return None  
    32               return modname == 'some.other.module'  
    33    
    34           c = Config()  
    35           s = Selector(c)  
    36           s.tests = [ '/a/file.py', 'some.module' ]  
    37    
    38           # in these cases, there is a test that doesn't care  
    39           # so they all pass  
    40           assert s.anytest(exact_file_a)  
    41           assert s.anytest(exact_file_b)         
    42           assert s.anytest(exact_module_a)  
    43           assert s.anytest(exact_module_b)  
    44    
    45           # no test matches file b  
    46           s.tests = [ '/a/file.py' ]  
    47           assert s.anytest(exact_file_a)  
    48           assert not s.anytest(exact_file_b)         
    49           assert s.anytest(exact_module_a)  
    50           assert s.anytest(exact_module_b)  
    51    
    52           s.tests = [ '/a/file.py', '/that/file.py' ]  
    53           assert s.anytest(exact_file_a)  
    54           assert not s.anytest(exact_file_b)         
    55           assert s.anytest(exact_module_a)  
    56           assert s.anytest(exact_module_b)  
    57            
    58           # no test matches module b  
    59           s.tests = [ 'some.module' ]  
    60           assert s.anytest(exact_file_a)  
    61           assert s.anytest(exact_file_b)         
    62           assert s.anytest(exact_module_a)  
    63           assert not s.anytest(exact_module_b)  
    64    
    65           # no test matches module b  
    66           s.tests = [ 'some.module', 'blah.blah' ]  
    67           assert s.anytest(exact_file_a)  
    68           assert s.anytest(exact_file_b)         
    69           assert s.anytest(exact_module_a)  
    70           assert not s.anytest(exact_module_b)  
    71            
      13     def tearDown(self):  
      14         logging.getLogger('nose.selector').setLevel(logging.WARN)  
      15      
    72 16     def test_exclude(self):  
    73 17         s = Selector(Config())  
     
    115 59         assert s.wantClass(TestMe)  
    116 60  
    117           s.tests = [ ':Bar' ]  
    118           assert s.wantClass(Bar)  
    119           assert not s.wantClass(Foo)  
    120           assert not s.wantClass(TestMe)  
    121    
    122           s.tests = [ ':Bar.baz' ]  
    123           assert s.wantClass(Bar)  
    124           assert not s.wantClass(Foo)  
    125           assert not s.wantClass(TestMe)  
    126    
    127           s.tests = [ ':Blah' ]  
    128           assert not s.wantClass(Bar)  
    129           assert not s.wantClass(Foo)  
    130           assert not s.wantClass(TestMe)  
    131    
    132           s.tests = [ ':Blah.baz' ]  
    133           assert not s.wantClass(Bar)  
    134           assert not s.wantClass(Foo)  
    135           assert not s.wantClass(TestMe)  
    136    
    137           s.tests = [ __name__ ]  
    138           assert s.wantClass(Bar) == [None]  
    139           assert s.wantClass(Foo) is None  
    140           assert s.wantClass(TestMe) == [None]  
    141    
    142           s.tests = [ __file__ ]  
    143           assert s.wantClass(Bar) == [None]  
    144           assert s.wantClass(Foo) is None  
    145           assert s.wantClass(TestMe)  == [None]  
      61         tests = test_addr([ ':Bar' ])  
      62         assert s.wantClass(Bar, tests)  
      63         assert not s.wantClass(Foo, tests)  
      64         assert not s.wantClass(TestMe, tests)  
      65  
      66         tests = test_addr([ ':Bar.baz' ])  
      67         assert s.wantClass(Bar, tests)  
      68         assert not s.wantClass(Foo, tests)  
      69         assert not s.wantClass(TestMe, tests)  
      70  
      71         tests = test_addr([ ':Blah' ])  
      72         assert not s.wantClass(Bar, tests)  
      73         assert not s.wantClass(Foo, tests)  
      74         assert not s.wantClass(TestMe, tests)  
      75  
      76         tests = test_addr([ ':Blah.baz' ])  
      77         assert not s.wantClass(Bar, tests)  
      78         assert not s.wantClass(Foo, tests)  
      79         assert not s.wantClass(TestMe, tests)  
      80  
      81         tests = test_addr([ __name__ ])  
      82         assert s.wantClass(Bar, tests)  
      83         assert not s.wantClass(Foo, tests)  
      84         assert s.wantClass(TestMe, tests)  
      85  
      86         tests = test_addr([ __file__ ])  
      87         assert s.wantClass(Bar, tests)  
      88         assert not s.wantClass(Foo, tests)  
      89         assert s.wantClass(TestMe, tests)  
    146 90          
    147 91     def test_want_directory(self):  
     
    165 109          
    166 110     def test_want_file(self):  
      111  
      112         #logging.getLogger('nose.selector').setLevel(logging.DEBUG)  
      113         #logging.basicConfig()  
      114          
    167 115         c = Config()  
    168 116         c.where = [absdir(os.path.join(os.path.dirname(__file__), 'support'))]  
      117         base = c.where[0]  
    169 118         s = Selector(c)  
    170 119  
     
    184 133         assert not s.wantFile('bar/baz/__init__.py', package='baz')  
    185 134  
    186           s.tests = [ 'test.py', 'other/file.txt' ]  
    187           assert s.wantFile('test.py')  
    188           assert not s.wantFile('foo/test_foo.py')  
    189           assert not s.wantFile('bar/baz/test.py', package='baz')  
      135         tests = test_addr([ 'test.py', 'other/file.txt' ], base)  
      136         assert s.wantFile(os.path.join(base, 'test.py'), tests=tests)  
      137         assert not s.wantFile(os.path.join(base,'foo/test_foo.py'),  
      138                               tests=tests)  
      139         assert not s.wantFile(os.path.join(base,'bar/baz/test.py'),  
      140                               package='baz', tests=tests)  
    190 141         # still not a python module... some plugin might want it,  
    191 142         # but the default selector doesn't  
    192           assert not s.wantFile('other/file.txt')  
      143         assert not s.wantFile(os.path.join(base,'other/file.txt'),  
      144                               tests=tests)  
    193 145  
    194           s.tests = [ 'a.module' ]  
    195           assert not s.wantFile('test.py')  
    196           assert not s.wantFile('foo/test_foo.py')  
    197           assert not s.wantFile('test-dir/test.py', package='baz')  
    198           assert not s.wantFile('other/file.txt')  
    199           assert s.wantFile('/path/to/a/module.py')  
    200           assert s.wantFile('/another/path/to/a/module/file.py')  
    201           assert not s.wantFile('/path/to/a/module/data/file.txt')  
      146         tests = test_addr([ 'a.module' ], base)  
      147         assert not s.wantFile(os.path.join(base, 'test.py'),  
      148                               tests=tests)  
      149         assert not s.wantFile(os.path.join(base, 'foo/test_foo.py'),  
      150                               tests=tests)  
      151         assert not s.wantFile(os.path.join(base, 'test-dir/test.py'),  
      152                               package='baz', tests=tests)  
      153         assert not s.wantFile(os.path.join(base, 'other/file.txt'),  
      154                               tests=tests)  
      155         assert s.wantFile('/path/to/a/module.py', tests=tests)  
      156         assert s.wantFile('/another/path/to/a/module/file.py', tests=tests)  
      157         assert not s.wantFile('/path/to/a/module/data/file.txt', tests=tests)  
    202 158          
    203 159     def test_want_function(self):  
     
    214 170         assert not s.wantFunction(foo)  
    215 171  
    216           s.tests = [ ':test_bar' ]  
    217           assert s.wantFunction(test_bar)  
    218           assert not s.wantFunction(test_foo)  
    219           assert not s.wantFunction(foo)  
    220    
    221           s.tests = [ __file__ ]  
    222           assert s.wantFunction(test_bar)  
    223           assert s.wantFunction(test_foo)  
    224           assert not s.wantFunction(foo)  
      172         tests = test_addr([ ':test_bar' ])  
      173         assert s.wantFunction(test_bar, tests)  
      174         assert not s.wantFunction(test_foo, tests)  
      175         assert not s.wantFunction(foo, tests)  
      176  
      177         tests = test_addr([ __file__ ])  
      178         assert s.wantFunction(test_bar, tests)  
      179         assert s.wantFunction(test_foo, tests)  
      180         assert not s.wantFunction(foo, tests)  
    225 181  
    226 182     def test_want_method(self):  
     
    239 195         assert not s.wantMethod(Baz.other)  
    240 196  
    241           s.tests = [ ':Baz.test_too' ]  
    242           assert s.wantMethod(Baz.test_too)  
    243           assert not s.wantMethod(Baz.test_me)                 
    244           assert not s.wantMethod(Baz.other)  
    245    
    246           s.tests = [ ':Baz' ]  
    247           assert s.wantMethod(Baz.test_too)  
    248           assert s.wantMethod(Baz.test_me)  
    249           assert not s.wantMethod(Baz.other)  
    250    
    251           s.tests = [ ':Spaz' ]  
    252           assert not s.wantMethod(Baz.test_too)  
    253           assert not s.wantMethod(Baz.test_me)  
    254           assert not s.wantMethod(Baz.other)  
      197         tests = test_addr([ ':Baz.test_too' ])  
      198         assert s.wantMethod(Baz.test_too, tests)  
      199         assert not s.wantMethod(Baz.test_me, tests)                 
      200         assert not s.wantMethod(Baz.other, tests)  
      201  
      202         tests = test_addr([ ':Baz' ])  
      203         assert s.wantMethod(Baz.test_too, tests)  
      204         assert s.wantMethod(Baz.test_me, tests)  
      205         assert not s.wantMethod(Baz.other, tests)  
      206  
      207         tests = test_addr([ ':Spaz' ])  
      208         assert not s.wantMethod(Baz.test_too, tests)  
      209         assert not s.wantMethod(Baz.test_me, tests)  
      210         assert not s.wantMethod(Baz.other, tests)  
    255 211          
    256 212     def test_want_module(self):  
     
    274 230         assert not s.wantModule(m8)  
    275 231          
    276           s.tests = [ 'this.that.another' ]  
    277           assert not s.wantModule(m)  
    278           assert s.wantModule(m2)  
    279           assert s.wantModule(m3)  
    280           assert s.wantModule(m4)         
    281           assert not s.wantModule(m5)  
    282           assert not s.wantModule(m6)  
    283           assert not s.wantModule(m7)  
    284           assert not s.wantModule(m8)  
      232         tests = test_addr([ 'this.that.another' ])  
      233         assert not s.wantModule(m, tests)  
      234         assert s.wantModule(m2, tests)  
      235         assert s.wantModule(m3, tests)  
      236         assert s.wantModule(m4, tests)         
      237         assert not s.wantModule(m5, tests)  
      238         assert not s.wantModule(m6, tests)  
      239         assert not s.wantModule(m7, tests)  
      240         assert not s.wantModule(m8, tests)  
    285 241          
    286 242     def test_want_module_tests(self):  
     
    304 260         assert s.wantModuleTests(m8)  
    305 261          
    306           s.tests = [ 'this.that.another' ]  
    307           assert not s.wantModuleTests(m)  
    308           assert not s.wantModuleTests(m2)  
    309           assert s.wantModuleTests(m3)  
    310           assert s.wantModuleTests(m4)         
    311           assert not s.wantModuleTests(m5)  
    312           assert not s.wantModuleTests(m6)  
    313           assert not s.wantModuleTests(m7)  
    314           assert not s.wantModuleTests(m8)  
      262         tests = test_addr([ 'this.that.another' ])  
      263         assert not s.wantModuleTests(m, tests)  
      264         assert not s.wantModuleTests(m2, tests)  
      265         assert s.wantModuleTests(m3, tests)  
      266         assert s.wantModuleTests(m4, tests)         
      267         assert not s.wantModuleTests(m5, tests)  
      268         assert not s.wantModuleTests(m6, tests)  
      269         assert not s.wantModuleTests(m7, tests)  
      270         assert not s.wantModuleTests(m8, tests)  
    315 271  
    316 272     def test_module_in_tests(self):  
     
    324 280         f_e = Mod('for.ever')  
    325 281  
    326           s.tests = [ 'what' ]  
    327           assert s.moduleInTests(w)  
    328           assert s.moduleInTests(w, True)         
    329           assert s.moduleInTests(w_e)  
    330           assert s.moduleInTests(w_e, True)  
    331           assert s.moduleInTests(w_n)  
    332           assert s.moduleInTests(w_n, True)  
    333           assert not s.moduleInTests(we)  
    334           assert not s.moduleInTests(we, True)  
    335           assert not s.moduleInTests(f_e)  
    336           assert not s.moduleInTests(f_e, True)  
    337    
    338           s.tests = [ 'what.ever' ]  
    339           assert not s.moduleInTests(w)  
    340           assert s.moduleInTests(w, True)         
    341           assert s.moduleInTests(w_e)  
    342           assert s.moduleInTests(w_e, True)  
    343           assert not s.moduleInTests(w_n)  
    344           assert not s.moduleInTests(w_n, True)  
    345           assert not s.moduleInTests(we)  
    346           assert not s.moduleInTests(we, True)  
    347           assert not s.moduleInTests(f_e)  
    348           assert not s.moduleInTests(f_e, True)  
    349    
    350           s.tests = [ 'what.ever', 'what.not' ]  
    351           assert not s.moduleInTests(w)  
    352           assert s.moduleInTests(w, True)         
    353           assert s.moduleInTests(w_e)  
    354           assert s.moduleInTests(w_e, True)  
    355           assert s.moduleInTests(w_n)  
    356           assert s.moduleInTests(w_n, True)  
    357           assert not s.moduleInTests(we)  
    358           assert not s.moduleInTests(we, True)  
    359           assert not s.moduleInTests(f_e)  
    360           assert not s.moduleInTests(f_e, True)  
      282         tests = test_addr([ 'what' ])  
      283         assert s.moduleInTests(tests)(w)  
      284         assert s.moduleInTests(tests, True)(w)  
      285         assert s.moduleInTests(tests)(w_e)  
      286         assert s.moduleInTests(tests, True)(w_e)  
      287         assert s.moduleInTests(tests)(w_n)  
      288         assert s.moduleInTests(tests, True)(w_n)  
      289         assert not s.moduleInTests(tests)(we)  
      290         assert not s.moduleInTests(tests, True)(we)  
      291         assert not s.moduleInTests(tests)(f_e)  
      292         assert not s.moduleInTests(tests, True)(f_e)  
      293  
      294         tests = test_addr([ 'what.ever' ])  
      295         assert not s.moduleInTests(tests)(w)  
      296         assert s.moduleInTests(tests, True)(w)  
      297         assert s.moduleInTests(tests)(w_e)  
      298         assert s.moduleInTests(tests, True)(w_e)  
      299         assert not s.moduleInTests(tests)(w_n)  
      300         assert not s.moduleInTests(tests, True)(w_n)  
      301         assert not s.moduleInTests(tests)(we)  
      302         assert not s.moduleInTests(tests, True)(we)  
      303         assert not s.moduleInTests(tests)(f_e)  
      304         assert not s.moduleInTests(tests, True)(f_e)  
      305  
      306         tests = test_addr([ 'what.ever', 'what.not' ])  
      307         assert not s.moduleInTests(tests)(w)  
      308         assert s.moduleInTests(tests, True)(w)  
      309         assert s.moduleInTests(tests)(w_e)  
      310         assert s.moduleInTests(tests, True)(w_e)  
      311         assert s.moduleInTests(tests)(w_n)  
      312         assert s.moduleInTests(tests, True)(w_n)  
      313         assert not s.moduleInTests(tests)(we)  
      314         assert not s.moduleInTests(tests, True)(we)  
      315         assert not s.moduleInTests(tests)(f_e)  
      316         assert not s.moduleInTests(tests, True)(f_e)  
    361 317  
    362 318     def test_module_in_tests_file(self):  
     
    371 327         d_t_t = Mod('test', path=base+'/test-dir')  
    372 328          
    373           s.tests = [ 'test.py' ]  
    374           assert not s.moduleInTests(f)  
    375           assert s.moduleInTests(t)  
    376           assert not s.moduleInTests(f_t_f)  
    377           assert not s.moduleInTests(d_t_t)  
    378            
    379           s.tests = [ 'foo/' ]  
    380           assert s.moduleInTests(f)  
    381           assert s.moduleInTests(f_t_f)  
    382           assert not s.moduleInTests(t)  
    383           assert not s.moduleInTests(d_t_t)  
    384    
    385           s.tests = [ 'foo/test_foo.py' ]  
    386           assert not s.moduleInTests(f)  
    387           assert s.moduleInTests(f_t_f)  
    388           assert not s.moduleInTests(t)  
    389           assert not s.moduleInTests(d_t_t)  
    390            
    391           s.tests = [ 'test-dir/test.py' ]  
    392           assert not s.moduleInTests(f)  
    393           assert not s.moduleInTests(t)  
    394           assert not s.moduleInTests(f_t_f)  
    395           assert s.moduleInTests(d_t_t)  
      329         tests = test_addr([ 'test.py' ], base)  
      330         assert not s.moduleInTests(tests)(f)  
      331         assert s.moduleInTests(tests)(t)  
      332         assert not s.moduleInTests(tests)(f_t_f)  
      333         assert not s.moduleInTests(tests)(d_t_t)  
      334          
      335         tests = test_addr([ 'foo/' ], base)  
      336         assert s.moduleInTests(tests)(f)  
      337         assert s.moduleInTests(tests)(f_t_f)  
      338         assert not s.moduleInTests(tests)(t)  
      339         assert not s.moduleInTests(tests)(d_t_t)  
      340  
      341         tests = test_addr([ 'foo/test_foo.py' ], base)  
      342         assert not s.moduleInTests(tests)(f)  
      343         assert s.moduleInTests(tests)(f_t_f)  
      344         assert not s.moduleInTests(tests)(t)  
      345         assert not s.moduleInTests(tests)(d_t_t)  
      346          
      347         tests = test_addr([ 'test-dir/test.py' ], base)  
      348         assert not s.moduleInTests(tests)(f)  
      349         assert not s.moduleInTests(tests)(t)  
      350         assert not s.moduleInTests(tests)(f_t_f)  
      351         assert s.moduleInTests(tests)(d_t_t)  
    396 352  
    397 353  
    398 354          
    399 355 if __name__ == '__main__':  
    400       import logging  
    401       logging.getLogger('nose.selector').setLevel(logging.DEBUG)  
    402       logging.basicConfig()  
    403 356     # log.setLevel(logging.DEBUG)  
    404 357     unittest.main()  
  • branches/new_loader/nose/selector.py

    r122 r123  
    18 18         self.conf = conf  
    19 19         self.configure(conf)  
    20        
    21       def _anytest(self, func):  
    22           """Check func against all tests. Funcs should return None if they  
    23           don't apply, False if they apply but don't match, True if they apply  
    24           and match.  
    25    
    26           Example: a func that wants tests based on what file they are in should  
    27           return None for a test address that doesn't contain a file part. It  
    28           should return true if a test address contains a file part that matches  
    29           the comparison file, and False if a test address contains a file part  
    30           that does not match the comparison file.  
    31           """  
    32           if not self.tests:  
    33               return True  
    34            
    35           log.debug('tests to check: %s', self.tests)  
    36           #matches = [ func(*test_tuple) for test_tuple in  
    37           #            map(split_test_name, self.tests) ]  
    38           matches = [ func(*test_tuple) for test_tuple in self.tests ]  
    39           log.debug('anytest matches: %s', matches)  
    40           res = filter(lambda x: x is not False, matches)  
    41           log.debug('anytest result: %s', res)  
    42           return res  
    43 20  
    44       def classInTests(self, cls, tests):  
      21     def classInTests(self, tests):  
    44 21         if tests is None:  
    45 22             in_tests = match_all  
     
    51 28         return in_tests  
    52 29  
    53       def _classInTests(self, cls):  
    54           def match(filename, modname, funcname, cls=cls):  
    55               if funcname is None:  
    56                   return None  
    57               try:  
    58                   clsn, dummy = funcname.split('.')  
    59               except (ValueError, AttributeError):  
    60                   clsn, dummy = funcname, None  
    61               return cls.__name__ == clsn  
    62           return self.anytest(match)  
    63    
    64 30     def configure(self, conf):  
    65 31         self.exclude = conf.exclude  
     
    77 43                               [ t.matches_file(file) for t in tests ])  
    78 44         return in_tests  
    79                          
    80       def _fileInTests(self, file):  
    81           orig = file  
    82           if not os.path.isabs(file):  
    83               file = absfile(file, self.conf.working_dir)  
    84               log.debug("abs file %s is %s", orig, file)  
    85           if file is None:  
    86               log.debug("File %s does not exist" % orig)  
    87               if self.tests:  
    88                   return False  
    89               return True  
    90           log.debug('Check file in tests')  
    91           def match(filename, modname, funcname, file=file):  
    92               return self.filematch(filename, modname, funcname, file)  
    93           return self.anytest(match)  
    94    
    95       def _filematch(self, filename, modname, funcname, file):  
    96           log.debug("Filematch (%s, %s, %s, %s)",  
    97                     filename, modname, funcname, file)  
    98           if filename is None:  
    99               if modname is None:  
    100                   return None  
    101               # be liberal... could this file possibly be this module?  
    102               # return None if the module name, converted to a file  
    103               # path, matches any part of the full filename  
    104               mpath = os.path.sep.join(modname.split('.'))  
    105               log.debug("Is module path %s in file %s?", mpath, file)  
    106               if mpath in file:  
    107                   return None  
    108               else:  
    109                   return False                     
    110           if not os.path.isabs(filename):  
    111               filename = absfile(filename, self.conf.working_dir)  
    112               log.debug("Abs match file: %s", filename)  
    113                
    114           # A file is a match if it is an exact match, or if  
    115           # the filename to match against is a directory (or package init file)  
    116           # and the file appears to be under that directory. Files that  
    117           # don't exist can't match.  
    118           if filename is None:  
    119               return False  
    120            
    121           if filename.endswith('__init__.py'):  
    122               dirname = os.path.dirname(filename)  
    123           elif os.path.isdir(filename):  
    124               dirname = filename  
      45      
      46     def funcInTests(self, tests):  
      47         if tests is None:  
      48             in_tests = match_all  
    125 49         else:  
    126               dirname = None  
    127    
    128           log.debug("Files are same: %s", filename == file)  
    129           log.debug("Dirname: %s", dirname)  
    130           if dirname is not None:  
    131               log.debug("File startswith dirname: %s", file.startswith(dirname))  
    132               try:  
    133                   log.debug("File has sep at end of dirname: %s == %s",  
    134                             file[len(dirname)], os.path.sep)  
    135               except IndexError:  
    136                   log.debug("File is not within dir")  
    137            
    138           return filename == file \  
    139                  or (dirname is not None  
    140                      and file.startswith(dirname)  
    141                      and file[len(dirname)] == os.path.sep)  
    142    
    143       def funcInTests(self, func):  
    144           def match(filename, modname, funcname, func=func):  
    145               if funcname is None:  
    146                   return None  
    147               return func.__name__ == funcname  
    148           return self.anytest(match)  
      50             def in_tests(func):  
      51                 return filter(None,  
      52                               [ t.matches_function(func) for t in tests ])  
      53         return in_tests  
    149 54          
    150 55     def matches(self, name):  
     
    176 81                               [ t.matches_method(method) for t in tests ])  
    177 82         return in_tests  
    178        
    179       def _methodInTests(self, method):  
    180           """Determine if a method is listed in the requested tests. To  
    181           be consideed a match, the method's class must be in the class  
    182           part of the test address, and the function part of the test  
    183           address must match the method name or be None.  
    184           """  
    185           def match(filename, modname, funcname, method=method):  
    186               if funcname is None:  
    187                   return None  
    188               mcls = method.im_class.__name__  
    189               mname = method.__name__  
    190               try:  
    191                   cls, func = funcname.split('.')  
    192               except (ValueError, AttributeError):  
    193                   cls, func = funcname, None  
    194               return mcls == cls and (mname == func or func is None)  
    195           return self.anytest(match)  
    196 83  
    197 84     def moduleInTests(self, tests, either=False):  
     
    293 180         if plug_wants is not None:  
    294 181             wanted = plug_wants  
    295           result = wanted or (pysrc and in_tests)  
      182         result = wanted or (pysrc and tests and in_tests)  
    295 182         log.debug("wantFile %s wanted %s pysrc %s in_tests %s", file,  
    296 183                   wanted, pysrc, in_tests)  
     
    348 235         The tail of the module name must match test requirements.  
    349 236  
    350           If a module is wanted, it means that the module should be loaded,  
    351           and its setup/teardown fixtures run -- if any. It does not mean that  
    352           tests will be collected from the module; tests are only collected from  
      237         If a module is wanted, it means that the module should be  
      238         imported and examined. It does not mean that tests will be  
      239         collected from the module; tests are only collected from  
    353 240         modules where wantModuleTests() is true.  
    354 241         """  
     
    360 247         if plug_wants is not None:  
    361 248             wanted = plug_wants  
    362           return wanted or (self.tests and in_tests)  
      249         return wanted or (tests and in_tests)  
    362 249  
    363 250     def wantModuleTests(self, module, tests=None):  
     
    384 271         if plug_wants is not None:  
    385 272             wanted = plug_wants         
    386           return wanted or (self.tests and in_tests)  
      273         return wanted or (tests and in_tests)  
    386 273          
    387 274 defaultSelector = Selector         
     
    408 295     class.method specification.  
    409 296     """  
    410       def __init__(self, name, working_dir):  
      297     def __init__(self, name, working_dir=None):  
      298         if working_dir is None:  
      299             working_dir = os.getcwd()  
    411 300         self.name = name  
    412 301         self.working_dir = working_dir  
     
    430 319         if self.call is None:  
    431 320             return True  
      321         try:  
      322             clsn, dummy = self.call.split('.')  
      323         except (ValueError, AttributeError):  
      324             # self.call is not dotted, like: foo or Foo  
      325             clsn, dummy = self.call, None  
      326         return cls.__name__ == clsn  
    432 327          
    433 328     def matches_file(self, filename):  
      329         """Does the filename match my file part?  
      330         """  
    434 331         log.debug("matches_file? %s == %s", filename, self.filename)  
    435 332         fn = self.filename  
     
    497 394             log.debug('%s is a subpackage of %s', mn, filename)  
    498 395             return True  
    499           return False  
    500            
      396         return False         
    501 397  
    502 398     def matches_function(self, function):  
     
    505 401         if self.call is None:  
    506 402             return True  
      403         funcname = getattr(function, 'compat_func_name', function.__name__)  
      404         log.debug("Match function name: %s == %s", funcname, self.call)  
      405         return funcname == self.call  
    507 406      
    508 407     def matches_method(self, method):  
     
    511 410         if self.call is None:  
    512 411             return True  
      412         mcls = method.im_class.__name__  
      413         mname = getattr(method, 'compat_func_name', method.__name__)  
      414         log.debug("Match method %s.%s == %s", mcls, mname, self.call)  
      415         try:  
      416             cls, func = self.call.split('.')  
      417         except (ValueError, AttributeError):  
      418             cls, func = self.call, None  
      419         return mcls == cls and (mname == func or func is None)