Changeset 62

Show
Ignore:
Timestamp:
Wed Jun 21 21:11:00 2006
Author:
jpellerin
Message:

r2483@Jason-Pellerins-Computer: jhp | 2006-06-21 21:10:54 -0500
Merge 0.9-stable into trunk to [61]

Files:

Legend:

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

    r21 r62  
    30 30  
    31 31     def test_raises(self):  
    32    
      32         from nose.case import FunctionTestCase  
      33          
    33 34         def raise_typeerror():  
    34 35             raise TypeError("foo")  
     
    40 41         raise_other = raises(ValueError)(raise_typeerror)  
    41 42         no_raise = raises(TypeError)(noraise)  
      43  
      44         tc = FunctionTestCase(raise_good)  
      45         self.assertEqual(str(tc), "%s.%s" % (__name__, 'raise_typeerror'))  
    42 46          
    43 47         raise_good()  
  • trunk/unit_tests/test_importer.py

    r21 r62  
    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__':  
  • trunk/unit_tests/test_loader.py

    r24 r62  
    190 190             count += 1  
    191 191         assert count == 5  
      192  
      193     def test_get_module_funcs(self):  
      194         from StringIO import StringIO  
      195          
      196         m = Mod('testo', __path__=None)  
      197  
      198         def test_func():  
      199             pass  
      200  
      201         class NotTestFunc(object):  
      202             def __call__(self):  
      203                 pass  
      204  
      205         class Selector:  
      206             classes = []  
      207             funcs = []  
      208              
      209             def wantClass(self, test):  
      210                 self.classes.append(test)  
      211                 return False  
      212              
      213             def wantFunction(self, test):  
      214                 self.funcs.append(test)  
      215                 return True             
      216         sel = Selector()  
      217          
      218         m.test_func = test_func  
      219         m.test_func_not_really = NotTestFunc()  
      220         m.StringIO = StringIO  
      221         m.buffer = StringIO()  
      222          
      223         l = loader.TestLoader(selector=sel)  
      224         tests = l.testsInModule(m)  
      225          
      226         print tests  
      227         print sel.funcs  
      228         assert test_func in sel.funcs  
      229         assert not m.test_func_not_really in sel.funcs  
      230         assert len(sel.funcs) == 1  
    192 231          
    193 232 if __name__ == '__main__':  
  • trunk/unit_tests/test_result.py

    r24 r62  
    4 4 from nose.config import Config  
    5 5 from nose.exc import DeprecatedTest, SkipTest  
      6 from nose.result import start_capture, end_capture  
    6 7  
    7 8 class TestResult(unittest.TestCase):  
     
    20 21         self.tr = nose.result.TextTestResult(stream, None, 2, Config())  
    21 22  
    22       def tearDown(self):  
    23           nose.result.end_capture()  
      23 #    def tearDown(self):  
      24 #        nose.result.end_capture()  
    24 25          
    25 26     def test_capture(self):  
    26           nose.result.start_capture()  
    27           print "Hello"  
    28           self.assertEqual(nose.result.buffer.getvalue(), "Hello\n")  
    29           nose.result.end_capture()  
      27         start_capture()  
      28         try:  
      29             print "Hello"  
      30             self.assertEqual(sys.stdout.getvalue(), "Hello\n")  
      31         finally:  
      32             end_capture()  
    30 33          
    31 34     def test_init(self):  
     
    51 54          
    52 55         # test with capture  
    53           tr.capture = True  
    54           nose.result.buffer.write("some output")  
    55           tr.addError(test, err)  
    56           self.assertEqual(tr.errors[1],  
    57                            (test, tr._exc_info_to_string(err, test),  
    58                             'some output'))  
    59           self.assertEqual(buf, [ 'ERROR', 'ERROR' ])  
      56         start_capture()  
      57         try:  
      58             tr.capture = True  
      59             print "some output"  
      60             tr.addError(test, err)  
      61             self.assertEqual(tr.errors[1],  
      62                              (test, tr._exc_info_to_string(err, test),  
      63                               'some output\n'))  
      64             self.assertEqual(buf, [ 'ERROR', 'ERROR' ])  
      65         finally:  
      66             end_capture()  
    60 67  
    61 68         # test deprecated  
     
    92 99  
    93 100         # test with capture  
    94           tr.capture = True  
    95           nose.result.buffer.write("some output")  
    96           tr.addFailure(test, err)  
    97           self.assertEqual(tr.failures[1],  
    98                            (test, tr._exc_info_to_string(err, test),  
    99                             'some output'))  
    100           self.assertEqual(buf, [ 'FAIL', 'FAIL' ])  
      101         start_capture()  
      102         try:  
      103             tr.capture = True  
      104             print "some output"  
      105             tr.addFailure(test, err)  
      106             self.assertEqual(tr.failures[1],  
      107                              (test, tr._exc_info_to_string(err, test),  
      108                               'some output\n'))  
      109             self.assertEqual(buf, [ 'FAIL', 'FAIL' ])  
      110         finally:  
      111             end_capture()  
    101 112  
    102 113     def test_start_stop(self):  
  • trunk/unit_tests/test_selector.py

    r21 r62  
    159 159         assert not s.wantFile('setup.py')  
    160 160         assert not s.wantFile('/some/path/to/setup.py')  
      161         assert not s.wantFile('ez_setup.py')  
      162         assert not s.wantFile('.test.py')  
      163         assert not s.wantFile('_test.py')  
      164         assert not s.wantFile('setup_something.py')  
    161 165          
    162 166         assert s.wantFile('test.py')  
     
    177 181  
    178 182         s.tests = [ 'a.module' ]  
    179           assert s.wantFile('test.py')  
    180           assert s.wantFile('foo/test_foo.py')  
    181           assert s.wantFile('test-dir/test.py', package='baz')  
    182           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')  
    183 190          
    184 191     def test_want_function(self):  
     
    280 287         assert not s.wantModuleTests(m8)  
    281 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          
    282 335 if __name__ == '__main__':  
    283       # import logging  
    284       # logging.basicConfig()  
      336     import logging  
      337     logging.getLogger('nose.selector').setLevel(logging.DEBUG)  
      338     logging.basicConfig()  
    285 339     # log.setLevel(logging.DEBUG)  
    286 340     unittest.main()  
  • trunk/unit_tests/test_proxy.py

    r26 r62  
    24 24     class TC(unittest.TestCase):  
    25 25         def runTest(self):  
      26             print "RUNTEST %s" % self  
    26 27             pass  
    27 28  
     
    81 82         self.assertEqual(len(res.failures), 1)         
    82 83  
      84         # shouldStop is proxied  
      85         self.assertEqual(pr.shouldStop, res.shouldStop)  
      86         pr.shouldStop = True  
      87         assert res.shouldStop  
      88              
    83 89     def test_output_capture(self):  
    84 90  
     
    113 119         Result.conf = c  
    114 120          
    115           errcase = TestProxy(self.ErrTC('test_err'))  
    116           failcase = TestProxy(self.ErrTC('test_fail'))  
    117           passcase = TestProxy(self.TC())         
      121         errcase = self.ErrTC('test_err')  
      122         failcase = self.ErrTC('test_fail')  
      123         passcase = self.TC()  
    118 124  
    119 125         suite = ResultProxySuite([errcase, failcase, passcase])  
      126         print list(suite)  
      127          
      128         for test in suite:  
      129             print test  
      130             assert isinstance(test, TestProxy)  
    120 131          
    121 132         d = dummy()     
    122 133         res = unittest._TextTestResult(d, 1, 1)  
    123 134         suite.run(res)  
    124    
    125 135         res.printErrors()  
      136         print d.buf  
    126 137  
    127 138         # split internal \n in strings into own lines  
     
    138 149         c.detailedErrors = True  
    139 150         Result.conf = c  
    140            
    141           errcase = TestProxy(self.ErrTC('test_err'))  
    142           failcase = TestProxy(self.ErrTC('test_fail'))  
    143           passcase = TestProxy(self.TC())  
    144 151  
      152         base_errcase = self.ErrTC('test_err')  
      153         base_failcase = self.ErrTC('test_fail')  
      154         base_passcase = self.TC()  
      155         errcase = TestProxy(base_errcase)  
      156         failcase = TestProxy(base_failcase)  
      157         passcase = TestProxy(base_passcase)  
      158  
      159         self.assertEqual(errcase.id(), base_errcase.id())  
      160         self.assertEqual(failcase.id(), base_failcase.id())  
      161         self.assertEqual(passcase.id(), base_passcase.id())  
      162  
      163         self.assertEqual(errcase.shortDescription(),  
      164                          base_errcase.shortDescription())  
      165         self.assertEqual(failcase.shortDescription(),  
      166                          base_failcase.shortDescription())  
      167         self.assertEqual(passcase.shortDescription(),  
      168                          base_passcase.shortDescription())  
      169          
    145 170         d = dummy()  
    146 171          
  • trunk/unit_tests/test_plugins.py

    r26 r62  
      1 import logging  
    1 2 import os  
    2 3 import sys  
    3 4 import unittest  
    4 5 import nose.plugins  
      6 from optparse import OptionParser  
    5 7 from warnings import warn  
    6 8  
     
    11 13 from nose.plugins.doctests import Doctest  
    12 14 from nose.plugins.missed import MissedTests  
    13   from nose.plugins.profile import Profile  
      15 from nose.plugins.prof import Profile  
    13 15  
    14 16 from mock import *  
     
    19 21     pass  
    20 22  
      23 class ErrPlugin(object):  
      24     def load(self):  
      25         raise Exception("Failed to load the plugin")  
      26      
      27 class ErrPkgResources(object):  
      28     def iter_entry_points(self, ep):  
      29         yield ErrPlugin()  
      30  
      31          
    21 32 # some plugins have 2.4-only features  
    22 33 pyvers = sys.version_info  
     
    44 55         for p in plugs:  
    45 56             assert not p.enabled  
      57  
      58     def test_failing_load(self):  
      59         tmp = nose.plugins.pkg_resources  
      60         nose.plugins.pkg_resources = ErrPkgResources()  
      61         try:  
      62             # turn off logging  
      63             lvl = logging.getLogger('nose.plugins').level  
      64             logging.getLogger('nose.plugins').setLevel(100)             
      65             plugs = list(nose.plugins.load_plugins(builtin=True, others=True))  
      66             self.assertEqual(plugs, [])  
      67         finally:  
      68             nose.plugins.pkg_resources = tmp  
      69             logging.getLogger('nose.plugins').setLevel(lvl)  
    46 70              
    47 71     def test_add_options(self):  
     
    106 130         plug.configure(opt, conf)  
    107 131          
    108           assert plug.wantFile('foo.py') is None  
      132         assert plug.wantFile('foo.py')  
    108 132         assert not plug.wantFile('bar.txt')  
    109 133         assert not plug.wantFile('buz.rst')  
     
    112 136          
    113 137         plug.extension = ['.txt', '.rst']  
    114           assert plug.wantFile('/path/to/foo.py') is None  
      138         assert plug.wantFile('/path/to/foo.py')  
    114 138         assert plug.wantFile('/path/to/bar.txt')  
    115 139         assert plug.wantFile('/path/to/buz.rst')  
     
    162 186         for test in suite:  
    163 187             assert str(test).endswith('doctests.txt')  
      188          
      189     def test_collect_no_collect(self):  
      190         # bug http://nose.python-hosting.com/ticket/55  
      191         # we got "iteration over non-sequence" when no files match  
      192         here = os.path.abspath(os.path.dirname(__file__))  
      193         support = os.path.join(here, 'support')  
      194         plug = Doctest()  
      195         suite = plug.loadTestsFromPath(os.path.join(support, 'foo'))  
      196         for test in suite:  
      197             pass  
      198          
    164 199  
    165 200 class TestAttribPlugin(unittest.TestCase):  
     
    189 224         plug.configure(opt, Config())  
    190 225         assert plug.enabled  
    191           self.assertEqual(plug.attribs, [('slow',False)])  
      226         self.assertEqual(plug.attribs, [[('slow', False)]])  
    191 226  
    192 227         opt.attr = ['fast,quick', 'weird=66']  
    193 228         plug.configure(opt, Config())  
    194           self.assertEqual(plug.attribs, [('fast', True),  
    195                                           ('quick', True),  
    196                                           ('weird', '66')])  
      229         self.assertEqual(plug.attribs, [[('fast', True),  
      230                                          ('quick', True)],  
      231                                         [('weird', '66')]])  
    197 232  
      233         # don't die on trailing ,  
      234         opt.attr = [ 'something,' ]  
      235         plug.configure(opt, Config())  
      236         self.assertEqual(plug.attribs, [[('something', True)]] )  
      237          
    198 238         if compat_24:  
    199 239             opt.attr = None  
    200 240             opt.eval_attr = [ 'weird >= 66' ]  
    201 241             plug.configure(opt, Config())  
    202               self.assertEqual(plug.attribs[0][0], 'weird >= 66')  
    203               assert callable(plug.attribs[0][1])  
      242             self.assertEqual(plug.attribs[0][0][0], 'weird >= 66')  
      243             assert callable(plug.attribs[0][0][1])  
    204 244                          
    205 245     def test_basic_attr(self):  
    206 246         def f():  
    207 247             pass  
      248         f.a = 1  
      249  
    208 250         def g():  
    209 251             pass  
    210 252      
    211 253         plug = AttributeSelector()  
    212           f.a = 1  
    213           plug.attribs = [('a',1)]  
      254         plug.attribs = [[('a', 1)]]  
    214 255         assert plug.wantFunction(f) is not False  
    215 256         assert not plug.wantFunction(g)  
     
    243 284         assert not plug.wantFunction(h)  
    244 285  
      286     def test_attr_a_b(self):  
      287         def f1():  
      288             pass  
      289         f1.tags = ['a', 'b']  
      290  
      291         def f2():  
      292             pass  
      293         f2.tags = ['a', 'c']  
      294  
      295         def f3():  
      296             pass  
      297         f3.tags = ['b', 'c']  
      298  
      299         def f4():  
      300             pass  
      301         f4.tags = ['c', 'd']  
      302          
      303         cnf = Config()  
      304         parser = OptionParser()  
      305         plug = AttributeSelector()  
      306  
      307         plug.add_options(parser)  
      308  
      309         # OR  
      310         opt, args = parser.parse_args(['test', '-a', 'tags=a',  
      311                                        '-a', 'tags=b'])  
      312         print opt  
      313         plug.configure(opt, cnf)  
      314  
      315         assert plug.wantFunction(f1) is None  
      316         assert plug.wantFunction(f2) is None  
      317         assert plug.wantFunction(f3) is None  
      318         assert not plug.wantFunction(f4)  
      319  
      320         # AND  
      321         opt, args = parser.parse_args(['test', '-a', 'tags=a,tags=b'])  
      322         print opt  
      323         plug.configure(opt, cnf)  
      324  
      325         assert plug.wantFunction(f1) is None  
      326         assert not plug.wantFunction(f2)  
      327         assert not plug.wantFunction(f3)  
      328         assert not plug.wantFunction(f4)  
    245 329          
    246 330 class TestMissedTestsPlugin(unittest.TestCase):  
  • trunk/unit_tests/test_core.py

    r23 r62  
    26 26         assert '__main__' in t.conf.tests  
    27 27  
      28  
      29 class TestAPI_run(unittest.TestCase):  
      30  
      31     def test_restore_stdout(self):  
      32         import sys  
      33         s = StringIO()  
      34         stdout = sys.stdout  
      35         res = nose.core.run(defaultTest=nullcollector, argv=[], env={},  
      36                             stream=s)  
      37         stdout_after = sys.stdout  
      38         self.assertEqual(stdout, stdout_after)  
      39          
    28 40 if __name__ == '__main__':  
    29 41     unittest.main()  
  • trunk/nose/core.py

    r31 r62  
    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')  
     
    287 288                       default=env.get('NOSE_PDB_FAILURES'),  
    288 289                       help="Drop into debugger on failures")  
    289       parser.add_option("--stop", action="store_true", dest="stopOnError",  
      290     parser.add_option("-x", "--stop", action="store_true", dest="stopOnError",  
    289 290                       default=env.get('NOSE_STOP'),  
    290 291                       help="Stop running tests after the first error or "  
     
    296 297                       help="Don't make any changes to sys.path when "  
    297 298                       "loading tests [NOSE_NOPATH]")  
      299     parser.add_option("--exe", action="store_true",  
      300                       dest="includeExe",  
      301                       default=env.get('NOSE_INCLUDE_EXE',  
      302                                       sys.platform=='win32'),  
      303                       help="Look for tests in python modules that are "  
      304                       "executable. Normal behavior is to exclude executable "  
      305                       "modules, since they may not be import-safe "  
      306                       "[NOSE_INCLUDE_EXE]")  
    298 307      
    299 308     # add opts from plugins  
     
    346 355     conf.stopOnError = options.stopOnError  
    347 356     conf.verbosity = options.verbosity  
      357     conf.includeExe = options.includeExe  
    348 358      
    349 359     if options.where is not None:  
     
    353 363                             "not a directory" % options.where)  
    354 364         log.info("Looking for tests in %s", conf.where)  
    355    
      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          
    356 370     if options.include:  
    357 371         conf.include = re.compile(options.include)  
     
    374 388  
    375 389 def configure_logging(options):  
      390     """Configure logging for nose, or optionally other packages. Any logger  
      391     name may be set with the debug option, and that logger will be set to  
      392     debug level and be assigned the same handler as the nose loggers, unless  
      393     it already has a handler.  
      394     """  
      395     format = logging.Formatter('%(name)s: %(levelname)s: %(message)s')  
      396     if options.debug_log:  
      397         handler = logging.FileHandler(options.debug_log)  
      398     else:  
      399         handler = logging.StreamHandler(sys.stderr) # FIXME         
      400     handler.setFormatter(format)  
      401  
    376 402     logger = logging.getLogger('nose')  
    377 403     logger.propagate = 0  
     
    380 406     # this avoids annoying duplicate log messages.  
    381 407     if not logger.handlers:  
    382           format = logging.Formatter('%(name)s: %(levelname)s: %(message)s')  
    383           if options.debug_log:  
    384               handler = logging.FileHandler(options.debug_log)  
    385           else:  
    386               handler = logging.StreamHandler(sys.stderr) # FIXME         
    387           handler.setFormatter(format)  
    388 408         logger.addHandler(handler)  
    389 409          
     
    400 420     # individual overrides  
    401 421     if options.debug:  
    402           debug_loggers = options.debug.split(',')  
      422         # no blanks  
      423         debug_loggers = [ name for name in options.debug.split(',') if name ]  
    403 424         for logger_name in debug_loggers:  
    404 425             l = logging.getLogger(logger_name)  
    405 426             l.setLevel(logging.DEBUG)  
      427             if not l.handlers and not logger_name.startswith('nose'):  
      428                 l.addHandler(handler)  
      429                  
    406 430              
    407 431 def main(*arg, **kw):  
     
    416 440     """Collect and run test, returning success or failure  
    417 441     """  
    418       return TestProgram(*arg, **kw).success  
      442     result = TestProgram(*arg, **kw).success  
      443     end_capture()  
      444     return result  
    419 445              
    420 446 if __name__ == '__main__':  
  • trunk/nose/plugins/doctests.py

    r26 r62  
    34 34                           dest='doctest_tests',  
    35 35                           default=env.get('NOSE_DOCTEST_TESTS'),  
    36                             help="Also look for doctests in test modules")  
      36                           help="Also look for doctests in test modules [NOSE_DOCTEST_TESTS]")  
    36 36         try:  
    37 37             # 2.4 or better supports loading tests from non-modules