Changeset 117

Show
Ignore:
Timestamp:
Tue Nov 14 15:46:09 2006
Author:
jpellerin
Message:

Continued work on new loader scratch pad

Files:

Legend:

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

    r103 r117  
    12 12         assert not nose.file_like('a.file')  
    13 13         assert not nose.file_like('some.package')  
      14         assert nose.file_like('a-file')  
    14 15          
    15 16     def test_split_test_name(self):  
  • branches/new_loader/nose/util.py

    r103 r117  
    19 19 log = logging.getLogger('nose')  
    20 20  
      21 ident_re = re.compile(r'^[A-Za-z_][A-Za-z0-9_.]*$')  
      22  
    21 23 def absdir(path):  
    22 24     """Return absolute, normalized path to directory, if it exists; None  
     
    72 74  
    73 75 def file_like(name):  
    74       return os.path.dirname(name) or name.endswith('.py')  
      76     """A name is file-like if it is a path that exists, or it has a  
      77     directory part, or it ends in .py, or it isn't a legal python  
      78     identifier.  
      79     """  
      80     return (os.path.exists(name)  
      81             or os.path.dirname(name)  
      82             or name.endswith('.py')  
      83             or not ident_re.match(os.path.splitext(name)[0]))  
    75 84  
    76 85  
  • branches/new_loader/work.py

    r116 r117  
    12 12 selector = Selector(conf)  
    13 13  
      14 def ispackage(dirname):  
      15     return os.path.exists(os.path.join(dirname, '__init__.py'))  
      16  
      17  
    14 18 class TestAddress:  
    15 19     def __init__(self, name, working_dir):  
      20         self.name = name  
    16 21         self.working_dir = working_dir  
    17 22         self.filename, self.module, self.call = split_test_name(name)  
     
    19 24             self.filename = os.path.abspath(os.path.join(working_dir,  
    20 25                                                          self.filename))  
      26  
      27     def __str__(self):  
      28         return self.name  
      29  
      30     def __repr__(self):  
      31         return "%s: (%s, %s, %s)" % (self.name, self.filename,  
      32                                      self.module, self.call)  
    21 33          
    22 34     def matches_file(self, filename):  
    23 35         fn = self.filename  
    24 36         if fn is None:  
    25               return None  
      37             return self.matches_file_as_module(filename)  
    25 37         if fn.endswith('__init__.py'):  
    26 38             dn = os.path.dn(fn)  
     
    48 60                              and fn[len(dirname)] == os.path.sep))))  
    49 61  
      62     def matches_file_as_module(self, filename):  
      63         """Match filename vs our module. Convert our module into  
      64         a path fragment, and return True if the filename contains that  
      65         path fragment.  
      66         """         
      67         mn = self.module  
      68         if mn is None:  
      69             return False  
      70         mpath = os.path.sep.join(mn.split('.'))  
      71         return mpath in os.path.splitext(filename)[0]  
      72              
      73  
    50 74  
    51 75 class TestLoader:  
     
    56 80  
    57 81         tests = None  
    58           if names is not None:  
      82         if names:  
    58 82             tests = map(lambda n: TestAddress(n, working_dir), names)  
    59 83  
     
    72 96              
    73 97         for dirpath, dirnames, filenames in os.walk(working_dir):  
    74               for filename in filenames:  
    75                   lname = os.path.join(dirpath, filename)  
    76                   if conf.testMatch.search(filename) and intests(lname):  
    77                       print "**", lname  
      98  
      99             # FIXME first sort dirnames into test-last order  
      100              
    78 101             to_remove = set()  
    79 102             for dirname in dirnames:  
      103  
      104                 # FIXME if it looks like a lib dir, continue in  
      105                 # FIXME and add it to sys.path  
      106                  
    80 107                 remove = True  
    81 108                 ldir = os.path.join(dirpath, dirname)  
    82                   if conf.testMatch.search(dirname) and intests(ldir):  
    83                       if os.path.exists(os.path.join(ldir, '__init__.py')):  
      109                 package = ispackage(ldir)  
      110                 if ((package or conf.testMatch.search(dirname))  
      111                     and intests(ldir)):  
      112                     if package:  
    84 113                         remove = True  
    85 114                         print "**",ldir  
      115                         # FIXME track this, we'll yield a ModuleSuite later  
    86 116                     else:  
    87 117                         remove = False  
     
    92 122                 dirnames.remove(dirname)  
    93 123  
      124             # FIXME store dirs that we're going to yield as ModuleSuites  
      125             # FIXME we want to yield the files in this dir first  
      126  
      127             # Process files after dirs so that any lib dirs will  
      128             # already be in sys.path before we start importing files  
      129                  
      130             for filename in filenames:  
      131                 lname = os.path.join(dirpath, filename)  
      132                 if (filename.endswith('.py')  
      133                     and conf.testMatch.search(filename)  
      134                     and intests(lname)):  
      135                     print "**", lname  
      136                     # FIXME yield a ModuleSuite if it's a python module  
      137                     # FIXME yield a FileSuite if it's not  
      138             # FIXME yield ModuleSuites for all module dirs  
      139  
    94 140 if __name__ == '__main__':  
      141     import sys  
    95 142     l = TestLoader()  
    96       l.collectTests('unit_tests/support',  
    97                      ['test.py'])  
      143     l.collectTests('unit_tests/support', sys.argv[1:])  
    98 144  
    99 145 # note these testable possibilities  
     
    102 148 #'foo' => 'support/foo'  
    103 149 #'test-dir/test.py' => 'support/test-dir/test.py'  
      150 #'test-dir' => 'support/test-dir/test.py'  
    104 151 #'test-dir/' => 'support/test-dir/test.py'  
    105 152