Changeset 47

Show
Ignore:
Timestamp:
Mon May 22 22:35:36 2006
Author:
jpellerin
Message:

r1343@Jason-Pellerins-Computer: jhp | 2006-05-22 21:53:38 -0500
Fix attrib plugin handling of OR case (-a tags=a -a tags=b)
r1344@Jason-Pellerins-Computer: jhp | 2006-05-22 22:26:25 -0500
In importer, handle modules in sys.modules without file attribute

Files:

Legend:

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

    r40 r47  
    35 35         # buz has an intra-package import that sets boodle  
    36 36         assert mod.boodle  
      37  
      38     def test_module_no_file(self):  
      39         where = os.path.abspath(os.path.join(os.path.dirname(__file__),  
      40                                              'support'))  
      41         foo = os.path.join(where, 'foo')  
      42         foobar = os.path.join(foo, 'bar')  
      43  
      44         # something that's not a real module and has no __file__  
      45         sys.modules['buz'] = 'Whatever'  
      46          
      47         mod = nose.importer._import('buz', [foobar], nose.config.Config())  
      48         assert where in sys.path  
      49         # buz has an intra-package import that sets boodle  
      50         assert mod.boodle  
    37 51          
    38 52 if __name__ == '__main__':  
  • branches/0.9-stable/unit_tests/test_plugins.py

    r40 r47  
    4 4 import unittest  
    5 5 import nose.plugins  
      6 from optparse import OptionParser  
    6 7 from warnings import warn  
    7 8  
     
    222 223         plug.configure(opt, Config())  
    223 224         assert plug.enabled  
    224           self.assertEqual(plug.attribs, [('slow',False)])  
      225         self.assertEqual(plug.attribs, [[('slow', False)]])  
    224 225  
    225 226         opt.attr = ['fast,quick', 'weird=66']  
    226 227         plug.configure(opt, Config())  
    227           self.assertEqual(plug.attribs, [('fast', True),  
    228                                           ('quick', True),  
    229                                           ('weird', '66')])  
      228         self.assertEqual(plug.attribs, [[('fast', True),  
      229                                          ('quick', True)],  
      230                                         [('weird', '66')]])  
    230 231  
    231 232         if compat_24:  
     
    234 235             opt.eval_attr = [ 'weird >= 66' ]  
    235 236             plug.configure(opt, Config())  
    236               self.assertEqual(plug.attribs[0][0], 'weird >= 66')  
    237               assert callable(plug.attribs[0][1])  
      237             self.assertEqual(plug.attribs[0][0][0], 'weird >= 66')  
      238             assert callable(plug.attribs[0][0][1])  
    238 239                          
    239 240     def test_basic_attr(self):  
    240 241         def f():  
    241 242             pass  
      243         f.a = 1  
      244  
    242 245         def g():  
    243 246             pass  
    244 247      
    245 248         plug = AttributeSelector()  
    246           f.a = 1  
    247           plug.attribs = [('a',1)]  
      249         plug.attribs = [[('a', 1)]]  
    248 250         assert plug.wantFunction(f) is not False  
    249 251         assert not plug.wantFunction(g)  
     
    276 278         assert not plug.wantFunction(h)  
    277 279  
      280     def test_attr_a_b(self):  
      281         def f1():  
      282             pass  
      283         f1.tags = ['a', 'b']  
      284  
      285         def f2():  
      286             pass  
      287         f2.tags = ['a', 'c']  
      288  
      289         def f3():  
      290             pass  
      291         f3.tags = ['b', 'c']  
      292  
      293         def f4():  
      294             pass  
      295         f4.tags = ['c', 'd']  
      296          
      297         cnf = Config()  
      298         parser = OptionParser()  
      299         plug = AttributeSelector()  
      300  
      301         plug.add_options(parser)  
      302  
      303         # OR  
      304         opt, args = parser.parse_args(['test', '-a', 'tags=a',  
      305                                        '-a', 'tags=b'])  
      306         print opt  
      307         plug.configure(opt, cnf)  
      308  
      309         assert plug.wantFunction(f1) is None  
      310         assert plug.wantFunction(f2) is None  
      311         assert plug.wantFunction(f3) is None  
      312         assert not plug.wantFunction(f4)  
      313  
      314         # AND  
      315         opt, args = parser.parse_args(['test', '-a', 'tags=a,tags=b'])  
      316         print opt  
      317         plug.configure(opt, cnf)  
      318  
      319         assert plug.wantFunction(f1) is None  
      320         assert not plug.wantFunction(f2)  
      321         assert not plug.wantFunction(f3)  
      322         assert not plug.wantFunction(f4)  
    278 323          
    279 324 class TestMissedTestsPlugin(unittest.TestCase):  
  • branches/0.9-stable/nose/plugins/attrib.py

    r40 r47  
    8 8     => both attributes must match  
    9 9  
    10     * nosetests -a priority=2, -a slow  
      10   * nosetests -a priority=2 -a slow  
    10 10     => either attribute must match  
    11 11      
     
    74 74  
    75 75         attr and eval_attr may each be lists.  
      76  
      77         self.attribs will be a list of lists of tuples. In that list, each  
      78         list is a group of attributes, all of which must match for the rule to  
      79         match.  
    76 80         """  
    77 81         self.attribs = []  
     
    85 89                 def eval_in_context(expr, attribs):  
    86 90                     return eval(expr, None, ContextHelper(attribs))  
    87                   self.attribs.append((attr, eval_in_context))  
      91                 self.attribs.append([(attr, eval_in_context)])  
    87 91  
    88 92         # attribute requirements are a comma separated list of  
     
    92 96             std_attr = self.tolist(options.attr)  
    93 97             for attr in std_attr:  
      98                 # all attributes within an attribute group must match  
      99                 attr_group = []  
    94 100                 for attrib in attr.split(","):  
      101                     # don't die on trailing comma  
      102                     if not attrib:  
      103                         pass  
    95 104                     items = attrib.split("=", 1)  
    96 105                     if len(items) > 1:  
     
    108 117                             # "name"  
    109 118                             # -> 'bool(obj.name)' must be True  
    110                               value = True  
    111                       self.attribs.append((key, value))  
      119                             value = True  
      120                     attr_group.append((key, value))  
      121                 self.attribs.append(attr_group)  
    112 122         if self.attribs:  
    113 123             self.enabled = True  
     
    115 125     def validateAttrib(self, attribs):  
    116 126         # TODO: is there a need for case-sensitive value comparison?  
    117           for key, value in self.attribs:  
    118               obj_value = attribs.get(key)  
    119               if callable(value):  
    120                   if not value(key, attribs):  
    121                       return False  
    122               elif value is True:  
    123                   # value must exist and be True  
    124                   if not bool(obj_value):  
    125                       return False  
    126               elif value is False:  
    127                   # value must not exist or be False  
    128                   if bool(obj_value):  
    129                       return False  
    130               elif type(obj_value) in (list, tuple):  
    131                   # value must be found in the list attribute  
    132                   if not value in [str(x).lower() for x in obj_value]:  
    133                       return False  
    134               else:  
    135                   # value must match, convert to string and compare  
    136                   if (value != obj_value  
    137                       and str(value).lower() != str(obj_value).lower()):  
    138                       return False  
    139           return None  
      127  
      128         # within each group, all must match for the group to match  
      129         # if any group matches, then the attribute set as a whole  
      130         # has matched  
      131         any = False  
      132         for group in self.attribs:  
      133             match = True  
      134             for key, value in group:  
      135                 obj_value = attribs.get(key)  
      136                 if callable(value):  
      137                     if not value(key, attribs):  
      138                         match = False  
      139                         break  
      140                 elif value is True:  
      141                     # value must exist and be True  
      142                     if not bool(obj_value):  
      143                         match = False  
      144                         break  
      145                 elif value is False:  
      146                     # value must not exist or be False  
      147                     if bool(obj_value):  
      148                         match = False  
      149                         break  
      150                 elif type(obj_value) in (list, tuple):  
      151                     # value must be found in the list attribute  
      152                     if not value in [str(x).lower() for x in obj_value]:  
      153                         match = False  
      154                         break  
      155                 else:  
      156                     # value must match, convert to string and compare  
      157                     if (value != obj_value  
      158                         and str(value).lower() != str(obj_value).lower()):  
      159                         match = False  
      160                         break  
      161             any = any or match  
      162         if any:  
      163             # not True because we don't want to FORCE the selection of the  
      164             # item, only say that it is acceptable  
      165             return None  
      166         return False  
    140 167          
    141 168     def wantFunction(self, function):  
  • branches/0.9-stable/nose/importer.py

    r40 r47  
    74 74                         old_path = os.path.normpath(old.__path__[0])  
    75 75                         old_ext = None  
    76                       else:  
      76                     elif hasattr(old, '__file__'):  
    76 76                         old_norm = os.path.normpath(old.__file__)  
    77 77                         old_path, old_ext = os.path.splitext(old_norm)  
      78                     else:  
      79                         # builtin or other module-like object that  
      80                         # doesn't have __file__  
      81                         old_path, old_ext, old_norm = None, None, None  
    78 82                     new_norm = os.path.normpath(filename)  
    79 83                     new_path, new_ext = os.path.splitext(new_norm)