Changeset 87

Show
Ignore:
Timestamp:
Wed Aug 23 14:37:07 2006
Author:
jpellerin
Message:

Implemented #75: multiple include and exclude arguments are now accepted.

Files:

Legend:

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

    r21 r87  
      1 import re  
    1 2 import unittest  
    2 3 import nose.config  
      4 from nose.core import configure  
    3 5  
    4 6 class TestNoseConfig(unittest.TestCase):  
     
    23 25         assert c.exclude == 'x'  
    24 26  
      27     def test_multiple_include(self):  
      28         conf = configure(['--include=a', '--include=b'])  
      29         self.assertEqual(conf.include, [re.compile('a'), re.compile('b')])  
      30  
      31     def test_single_include(self):  
      32         conf = configure(['--include=b'])  
      33         self.assertEqual(conf.include, [re.compile('b')])  
      34  
    25 35 if __name__ == '__main__':  
    26 36     unittest.main()  
  • trunk/unit_tests/test_selector.py

    r86 r87  
    73 73         s = Selector(Config())  
    74 74         c = Config()  
    75           c.exclude = re.compile(r'me')         
      75         c.exclude = [re.compile(r'me')]  
    75 75         s2 = Selector(c)  
    76 76          
     
    84 84         s = Selector(Config())  
    85 85         c = Config()  
    86           c.include = re.compile(r'me')  
      86         c.include = [re.compile(r'me')]  
    86 86         s2 = Selector(c)  
    87 87  
     
    91 91         assert not s.matches('meatball')  
    92 92         assert s2.matches('meatball')  
      93         assert not s.matches('toyota')  
      94         assert not s2.matches('toyota')  
      95          
      96         c.include.append(re.compile('toy'))  
      97         assert s.matches('test')  
      98         assert s2.matches('test')  
      99         assert not s.matches('meatball')  
      100         assert s2.matches('meatball')  
      101         assert not s.matches('toyota')  
      102         assert s2.matches('toyota')  
    93 103          
    94 104     def test_want_class(self):  
  • trunk/nose/core.py

    r86 r87  
    265 265     parser.add_option("-w", "--where", action="append", dest="where",  
    266 266                       help="Look for tests in this directory [NOSE_WHERE]")  
    267       parser.add_option("-e", "--exclude", action="store", dest="exclude",  
    268                         default=env.get('NOSE_EXCLUDE'),  
      267     parser.add_option("-e", "--exclude", action="append", dest="exclude",  
    269 268                       help="Don't run tests that match regular "  
    270 269                       "expression [NOSE_EXCLUDE]")  
    271       parser.add_option("-i", "--include", action="store", dest="include",  
    272                         default=env.get('NOSE_INCLUDE'),  
      270     parser.add_option("-i", "--include", action="append", dest="include",  
    273 271                       help="Also run tests that match regular "  
    274 272                       "expression [NOSE_INCLUDE]")  
     
    340 338     if not options.where:  
    341 339         options.where = env.get('NOSE_WHERE', os.getcwd())  
      340  
      341     # include and exclude also  
      342     if not options.include:  
      343         options.include = env.get('NOSE_INCLUDE', [])  
      344     if not options.exclude:  
      345         options.exclude = env.get('NOSE_EXCLUDE', [])  
    342 346          
    343 347     configure_logging(options)  
     
    382 386                          "adding to sys.path" % abs_path)  
    383 387                 add_path(abs_path)  
    384            
      388                  
    384 388     if options.include:  
    385           conf.include = re.compile(options.include)  
      389         conf.include = map(re.compile, tolist(options.include))  
    385 389         log.info("Including tests matching %s", options.include)  
      390          
    386 391     if options.exclude:  
    387           conf.exclude = re.compile(options.exclude)  
      392         conf.exclude = map(re.compile, tolist(options.exclude))  
    387 392         log.info("Excluding tests matching %s", options.exclude)  
    388 393          
    389 394     if conf.capture:  
    390 395         start_capture()  
    391    
      396          
    391 396     try:  
    392 397         # give plugins a chance to start  
  • trunk/nose/selector.py

    r86 r87  
    133 133         """  
    134 134         return ((self.match.search(name)  
    135                    or (self.include is not None and self.include.search(name)))  
    136                   and (self.exclude is None  
    137                        or not self.exclude.search(name)))  
      135                  or (self.include and  
      136                      filter(None,  
      137                             [inc.search(name) for inc in self.include])))  
      138                 and ((not self.exclude)  
      139                      or not filter(None,  
      140                                    [exc.search(name) for exc in self.exclude])  
      141                  ))  
    138 142      
    139 143     def methodInTests(self, method):