Changeset 61

Show
Ignore:
Timestamp:
Wed Jun 21 21:08:20 2006
Author:
jpellerin
Message:

r2481@Jason-Pellerins-Computer: jhp | 2006-06-21 21:03:29 -0500
Work on fixes for bugs #66, #68 and #69

Files:

Legend:

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

    r40 r61  
    181 181  
    182 182         s.tests = [ 'a.module' ]  
    183           assert s.wantFile('test.py')  
    184           assert s.wantFile('foo/test_foo.py')  
    185           assert s.wantFile('test-dir/test.py', package='baz')  
    186           assert not s.wantFile('other/file.txt')         
      183         assert not s.wantFile('test.py')  
      184         assert not s.wantFile('foo/test_foo.py')  
      185         assert not s.wantFile('test-dir/test.py', package='baz')  
      186         assert not s.wantFile('other/file.txt')  
      187         assert s.wantFile('/path/to/a/module.py')  
      188         assert s.wantFile('/another/path/to/a/module/file.py')  
      189         assert not s.wantFile('/path/to/a/module/data/file.txt')  
    187 190          
    188 191     def test_want_function(self):  
     
    284 287         assert not s.wantModuleTests(m8)  
    285 288  
      289     def test_module_in_tests(self):  
      290         s = Selector(Config())  
      291         # s.tests = [ 'ever', 'what', 'what.ever' ]  
      292  
      293         w = Mod('what')  
      294         we = Mod('whatever')  
      295         w_e = Mod('what.ever')  
      296         w_n = Mod('what.not')  
      297         f_e = Mod('for.ever')  
      298  
      299         s.tests = [ 'what' ]  
      300         assert s.moduleInTests(w)  
      301         assert s.moduleInTests(w, True)         
      302         assert s.moduleInTests(w_e)  
      303         assert s.moduleInTests(w_e, True)  
      304         assert s.moduleInTests(w_n)  
      305         assert s.moduleInTests(w_n, True)  
      306         assert not s.moduleInTests(we)  
      307         assert not s.moduleInTests(we, True)  
      308         assert not s.moduleInTests(f_e)  
      309         assert not s.moduleInTests(f_e, True)  
      310  
      311         s.tests = [ 'what.ever' ]  
      312         assert not s.moduleInTests(w)  
      313         assert s.moduleInTests(w, True)         
      314         assert s.moduleInTests(w_e)  
      315         assert s.moduleInTests(w_e, True)  
      316         assert not s.moduleInTests(w_n)  
      317         assert not s.moduleInTests(w_n, True)  
      318         assert not s.moduleInTests(we)  
      319         assert not s.moduleInTests(we, True)  
      320         assert not s.moduleInTests(f_e)  
      321         assert not s.moduleInTests(f_e, True)  
      322  
      323         s.tests = [ 'what.ever', 'what.not' ]  
      324         assert not s.moduleInTests(w)  
      325         assert s.moduleInTests(w, True)         
      326         assert s.moduleInTests(w_e)  
      327         assert s.moduleInTests(w_e, True)  
      328         assert s.moduleInTests(w_n)  
      329         assert s.moduleInTests(w_n, True)  
      330         assert not s.moduleInTests(we)  
      331         assert not s.moduleInTests(we, True)  
      332         assert not s.moduleInTests(f_e)  
      333         assert not s.moduleInTests(f_e, True)  
      334          
    286 335 if __name__ == '__main__':  
    287       # import logging  
    288       # logging.basicConfig()  
      336     import logging  
      337     logging.getLogger('nose.selector').setLevel(logging.DEBUG)  
      338     logging.basicConfig()  
    289 339     # log.setLevel(logging.DEBUG)  
    290 340     unittest.main()  
  • branches/0.9-stable/nose/core.py

    r60 r61  
    17 17 from nose.suite import LazySuite  
    18 18 from nose.util import absdir  
      19 from nose.importer import add_path  
    19 20  
    20 21 log = logging.getLogger('nose.core')  
     
    296 297                       help="Don't make any changes to sys.path when "  
    297 298                       "loading tests [NOSE_NOPATH]")  
    298       parser.add_option("--exe", action="store_false",  
    299                         dest="ignoreExe",  
    300                         default=not env.get('NOSE_INCLUDE_EXE'),  
      299     parser.add_option("--exe", action="store_true",  
      300                       dest="includeExe",  
      301                       default=env.get('NOSE_INCLUDE_EXE',  
      302                                       sys.platform=='win32'),  
    301 303                       help="Look for tests in python modules that are "  
    302 304                       "executable. Normal behavior is to exclude executable "  
     
    353 355     conf.stopOnError = options.stopOnError  
    354 356     conf.verbosity = options.verbosity  
    355       conf.ignoreExe = options.ignoreExe  
      357     conf.includeExe = options.includeExe  
    355 357      
    356 358     if options.where is not None:  
     
    361 363                             "not a directory" % options.where)  
    362 364         log.info("Looking for tests in %s", conf.where)  
    363    
      365         if conf.addPaths and \  
      366             os.path.exists(os.path.join(conf.where, '__init__.py')):  
      367             log.info("Working directory is a package; adding to sys.path")  
      368             add_path(conf.where)  
      369          
    364 370     if options.include:  
    365 371         conf.include = re.compile(options.include)  
  • branches/0.9-stable/nose/selector.py

    r40 r61  
    129 129         def match(filename, modname, funcname, file=file):  
    130 130             if filename is None:  
    131                   return None  
      131                 if modname is None:  
      132                     return None  
      133                 # be liberal... could this file possibly be this module?  
      134                 # return None if the module name, converted to a file  
      135                 # path, matches any part of the full filename  
      136                 mpath = os.path.sep.join(modname.split('.'))  
      137                 log.debug("Is module path %s in file %s?", mpath, file)  
      138                 if mpath in file:  
      139                     return None  
      140                 else:  
      141                     return False                     
    132 142             if not os.path.isabs(filename):  
    133 143                 filename = absfile(filename, self.conf.where)  
    134 144             return filename == file  
      145         log.debug('Check file in tests')  
    135 146         return self.anytest(match)  
    136 147  
     
    164 175                 return None  
    165 176             mname = module.__name__  
    166               result = (mname.startswith(modname)  
    167                         or (either and modname.startswith(mname)))  
      177             result = (subpackage_of(mname, modname) or  
      178                       (either and subpackage_of(modname, mname)))  
    168 179             log.debug("Module %s match %s (either: %s) result %s",  
    169 180                       module.__name__, modname, either, result)  
     
    238 249                       base)  
    239 250             return False  
    240    
    241           if not self.conf.ignoreExe and os.access(file, os.X_OK):  
      251         if not self.conf.includeExe and os.access(file, os.X_OK):  
    242 252             log.info('%s is executable; skipped', file)  
    243 253             return False  
    244            
    245 254         in_tests = self.fileInTests(file)  
    246 255         if not in_tests:  
     
    345 354          
    346 355 defaultSelector = Selector         
      356  
      357 # Helpers  
      358  
      359 def subpackage_of(modname, package):  
      360     """Is module modname a subpackage of package?"""  
      361     # quick negative case  
      362     log.debug('subpackage_of(%s,%s)', modname, package)  
      363     if not modname.startswith(package):  
      364         log.debug('not %s startswith %s' , modname, package)  
      365         return False  
      366     if len(package) > len(modname):  
      367         log.debug('package name longer than mod name')  
      368         return False  
      369     mod_parts = modname.split('.')  
      370     pkg_parts = package.split('.')  
      371     try:  
      372         for p in pkg_parts:             
      373             pp = mod_parts.pop(0)  
      374             log.debug('check part %s vs part %s', p, pp)  
      375             if p != pp:  
      376                 return False  
      377     except IndexError:  
      378         log.debug('package %s more parts than modname %s', package, modname)  
      379         return False  
      380     return True  
      381      
  • branches/0.9-stable/nose/importer.py

    r47 r61  
    37 37     if name == '__main__':  
    38 38         return sys.modules[name]  
      39  
      40     # make sure we're doing an absolute import  
      41     # name, path = make_absolute(name, path)  
    39 42      
    40 43     if conf.addPaths:  
     
    103 106         parent = mod  
    104 107     return mod  
      108  
      109 def make_absolute(name, path):  
      110     """Given a module name and the path at which it is found, back up to find  
      111     the parent of the module, popping directories off of the path so long as  
      112     they contain __init__.py files.  
      113     """  
      114     if not os.path.exists(os.path.join(path, '__init__.py')):  
      115         return (name, path)  
      116     path, parent = os.path.split(path)  
      117     name = "%s.%s" % (parent, path)  
      118     return make_absolute(name, path)  
  • branches/0.9-stable/nose/config.py

    r40 r61  
    1 1 import os  
    2 2 import re  
      3 import sys  
    3 4  
    4 5 class Config(object):  
     
    14 15         self.debugFailures = False  
    15 16         self.exclude = None  
    16           self.ignoreExe = True  
      17         self.includeExe = sys.platform=='win32'  
    16 17         self.ignoreFiles = [ re.compile(r'^\.'),  
    17 18                              re.compile(r'^_'),