Changeset 29

Show
Ignore:
Timestamp:
Wed Apr 26 21:39:57 2006
Author:
jpellerin
Message:

r901@Jason-Pellerins-Computer: jhp | 2006-04-26 21:38:44 -0500
Add capt to addSuccess plugin calls; provisional fix for windows bugs in split_test_name

Files:

Legend:

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

    r21 r29  
    2 2 import nose  
    3 3 import nose.case  
      4 from nose.util import absfile  
    4 5  
    5 6 class TestUtils(unittest.TestCase):  
     
    23 24         assert nose.split_test_name(':Baz') == \  
    24 25             (None, None, 'Baz')  
      26  
      27     def test_split_test_name_windows(self):  
      28         # convenience  
      29         stn = nose.split_test_name  
      30         self.assertEqual(stn(r'c:\some\path.py:a_test'),  
      31                          (r'c:\some\path.py', None, 'a_test'))  
      32         self.assertEqual(stn(r'c:\some\path.py'),  
      33                          (r'c:\some\path.py', None, None))  
      34         self.assertEqual(stn(r'c:/some/other/path.py'),  
      35                          (r'c:/some/other/path.py', None, None))  
      36         self.assertEqual(stn(r'c:/some/other/path.py:Class.test'),  
      37                          (r'c:/some/other/path.py', None, 'Class.test'))  
      38         try:  
      39             stn('c:something')  
      40         except ValueError:  
      41             pass  
      42         else:  
      43             self.fail("Ambiguous test name should throw ValueError")  
    25 44          
    26 45     def test_test_address(self):  
     
    48 67  
    49 68         foo_mtc = nose.case.MethodTestCase(Foo, 'bar')  
    50            
    51           assert nose.test_address(baz) == (__file__, __name__, 'baz')  
    52           assert nose.test_address(Foo) == (__file__, __name__, 'Foo')  
    53           assert nose.test_address(Foo.bar) == (__file__, __name__,  
      69  
      70         me = absfile(__file__)  
      71         self.assertEqual(nose.test_address(baz),  
      72                          (me, __name__, 'baz'))  
      73         assert nose.test_address(Foo) == (me, __name__, 'Foo')  
      74         assert nose.test_address(Foo.bar) == (me, __name__,  
    54 75                                               'Foo.bar')  
    55           assert nose.test_address(f) == (__file__, __name__, 'Foo')  
    56           assert nose.test_address(f.bar) == (__file__, __name__, 'Foo.bar')  
    57           assert nose.test_address(nose) == (nose.__file__, 'nose')  
      76         assert nose.test_address(f) == (me, __name__, 'Foo')  
      77         assert nose.test_address(f.bar) == (me, __name__, 'Foo.bar')  
      78         assert nose.test_address(nose) == (absfile(nose.__file__), 'nose')  
    58 79  
    59 80         # test passing the actual test callable, as the  
    60 81         # missed test plugin must do  
    61 82         self.assertEqual(nose.test_address(FooTC('test_one')),  
    62                            (__file__, __name__, 'FooTC.test_one'))  
      83                          (me, __name__, 'FooTC.test_one'))  
    62 83         self.assertEqual(nose.test_address(foo_funct),  
    63                            (__file__, __name__, 'baz'))  
      84                          (me, __name__, 'baz'))  
    63 84         self.assertEqual(nose.test_address(foo_functu),  
    64                            (__file__, __name__, 'baz'))  
      85                          (me, __name__, 'baz'))  
    64 85         self.assertEqual(nose.test_address(foo_mtc),  
    65                            (__file__, __name__, 'Foo.bar'))  
      86                          (me, __name__, 'Foo.bar'))  
    65 86 if __name__ == '__main__':  
    66 87     unittest.main()  
  • trunk/nose/core.py

    r27 r29  
    114 114     defaults to the current working directory). Any python source file,  
    115 115     directory or package that matches the testMatch regulat expression  
    116       (by default: (?:^|[\b_\.-])[Tt]est) will be collected as a test (or  
      116     (by default: (?:^|[\\b_\\.-])[Tt]est) will be collected as a test (or  
    116 116     source for collection of tests). In addition, all other packages  
    117 117     found in the working directory are examined for python source files  
     
    138 138     ---------------  
    139 139  
    140       To specify which tests to run, pass test names on the command line::  
      140     To specify which tests to run, pass test names on the command line:  
    140 140  
    141 141       %prog only_test_this.py  
     
    145 145     indicate the test case to run by separating the module or file name  
    146 146     from the test case name with a colon. Filenames may be relative or  
    147       absolute. Examples::  
      147     absolute. Examples:  
    147 147  
    148 148       %prog test.module  
     
    156 156     against tests discovered, and only the requested tests are  
    157 157     run. Setup and teardown methods are run at all stages. That means  
    158       that if you run::  
      158     that if you run:  
    158 158  
    159 159       %prog some.tests.test_module:test_function  
     
    165 165  
    166 166     You may also change the working directory where nose looks for tests,  
    167       use the -w switch::  
      167     use the -w switch:  
    167 167  
    168 168       %prog -w /path/to/tests  
  • trunk/nose/plugins/base.py

    r28 r29  
    204 204         pass         
    205 205  
    206       def addSuccess(self, test):  
      206     def addSuccess(self, test, capt):  
    206 206         """Called when a test passes. DO NOT return a value unless you  
    207 207         want to stop other plugins from seeing the passing test.  
     
    211 211          * test:  
    212 212            the test case  
      213          * capt:  
      214            Captured output, if any  
    213 215         """  
    214 216         pass         
  • trunk/nose/plugins/profile.py

    r26 r29  
    12 12 import os  
    13 13 import sys  
      14 import tempfile  
    14 15 from nose.plugins.base import Plugin  
    15 16  
     
    28 29                           dest='profile_stats_file',  
    29 30                           default=env.get('NOSE_PROFILE_STATS_FILE'),  
    30                             help='Profiler stats file; default is a new'  
      31                           help='Profiler stats file; default is a new '  
    30 31                           'temp file on each run')  
    31 32         parser.add_option('--profile-restrict',action='append',  
     
    47 48             self.pfile = options.profile_stats_file  
    48 49         else:  
    49               # FIXME use a temp file  
    50               self.pfile = 'nose.profile'  
      50             fileno, filename = tempfile.mkstemp()  
      51             # close the open handle immediately, hotshot needs to open  
      52             # the file itself  
      53             os.close(fileno)  
      54             self.pfile = filename  
    51 55         self.sort = options.profile_sort  
    52 56         self.restrict = self.tolist(options.profile_restrict)  
  • trunk/nose/util.py

    r28 r29  
    4 4 import logging  
    5 5 import os  
      6 import re  
    6 7 import sys  
    7 8 import types  
    8 9 import unittest  
    9    
    10   log = logging.getLogger('nose')  
    11    
    12 10 from compiler.consts import CO_GENERATOR  
    13 11  
     
    19 17 from nose.config import Config  
    20 18  
      19 log = logging.getLogger('nose')  
      20 split_test_re = re.compile  
      21  
    21 22 def absdir(path):  
    22 23     """Return absolute, normalized path to directory, if it exists; None  
     
    72 73  
    73 74 def split_test_name(test):  
    74       try:  
    75           file_or_mod, fn = test.split(':')  
    76       except ValueError:  
    77           file_or_mod, fn = test, None  
      75     """Split a test name into a 3-tuple containing file, module, and callable  
      76     names, any of which (but not all) may be blank.  
      77  
      78     Test names are in the form:  
      79  
      80     file_or_module:callable  
      81  
      82     Either side of the : may be dotted. To change the splitting behavior, you  
      83     can alter nose.util.split_test_re.  
      84     """  
      85     parts = test.split(':')  
      86     num = len(parts)  
      87     if num == 1:  
      88         # only a file or mod part  
      89         if file_like(test):  
      90             return (test, None, None)  
      91         else:  
      92             return (None, test, None)  
      93     elif num >= 3:  
      94         # definitely popped off a windows driveletter  
      95         file_or_mod = ':'.join(parts[0:-1])  
      96         fn = parts[-1]  
      97     else:  
      98         # only a file or mod part, or a test part, or  
      99         # we mistakenly split off a windows driveletter  
      100         file_or_mod, fn = parts  
      101         if len(file_or_mod) == 1:  
      102             # windows drive letter: must be a file  
      103             if not file_like(fn):  
      104                 raise ValueError("Test name '%s' is ambiguous; can't tell "  
      105                                  "if ':%s' refers to a module or callable"  
      106                                  % (test, fn))  
      107             return (test, None, None)         
    78 108     if file_or_mod:  
    79 109         if file_like(file_or_mod):  
  • trunk/nose/result.py

    r28 r29  
    80 80  
    81 81     def addSuccess(self, test):  
      82         self.capt = buffer.getvalue()  
    82 83         self.resetBuffer()  
    83           call_plugins(self.conf.plugins, 'addSuccess', test)  
      84         call_plugins(self.conf.plugins, 'addSuccess', test, self.capt)  
    83 84  
    84 85     def isDeprecated(self, err):  
    85 86         if err[0] is DeprecatedTest:  
    86 87             return True  
    87           # FIXME also if is subclass or instance of DeprecatedTest  
    88    
      88         # FIXME also if is subclass or instance of DeprecatedTest?  
    89 89         return False  
    90 90      
     
    93 93         if err[0] is SkipTest:  
    94 94             return True  
    95           # FIXME also if is subclass or instance of DeprecatedTest  
    96    
      95         # FIXME also if is subclass or instance of SkipTest?  
    97 96         return False  
    98 97          
  • trunk/scripts/mkwiki.py

    r27 r29  
    31 31                  }  
    32 32  
    33       for k in modlinks:  
    34           doc = re.sub(k, '`' + modlinks[k] + '`:trac', doc)  
      33     # not working at all..  
      34     #for k in modlinks:  
      35     #    doc = re.sub(k, '`' + modlinks[k] + '`:trac', doc)  
    35 36  
    36 37     doc = '`This page is autogenerated. Please add comments only ' \  
     
    62 63     # FIXME dump whole example plugin code from setup.py and plug.py  
    63 64     # into python source sections  
    64       pass  
      65     root = os.path.abspath(os.path.join(os.path.dirname(__file__),  
      66                                         '..'))  
      67     exp = os.path.join(root, 'examples', 'plugin')  
      68     setup = file(os.path.join(exp, 'setup.py'), 'r').read()  
      69     plug = file(os.path.join(exp, 'plug.py'), 'r').read()  
      70  
      71     wik = "'''%s:'''\n{{{\n#!python\n%s\n}}}\n"  
      72     return wik % ('setup.py', setup) + wik % ('plug.py', plug)  
    65 73  
    66 74 def mkwiki(url, realm, user, passwd):  
     
    74 82         'WritingPlugins': wikirst(nose.plugins.__doc__),  
    75 83         'PluginInterface': plugin_interface(),  
    76           # FIXME finish example plugin doc  
    77   #        'ExamplePlugin': example_plugin(),  
      84         # FIXME finish example plugin doc... add some explanation  
      85         'ExamplePlugin': example_plugin(),  
    78 86          
    79           # FIXME: need to remove example plugin section and html-output section  
    80 87         'NosetestsUsage': '\n{{{\n' +  
    81 88         nose.configure(help=True).replace('mkwiki.py', 'nosetests') +  
    82                  '\n}}}\n',  
    83                 }  
      89         '\n}}}\n'  
      90         }  
    84 91      
    85 92     w = TracWiki(url, realm, user, passwd)  
  • trunk/examples/html_plugin/htmlplug.py

    r17 r29  
    21 21                       '</head><body>' ]  
    22 22      
    23       def addSuccess(self, test):  
      23     def addSuccess(self, test, capt):  
    23 23         self.html.append('<span>ok</span>')  
    24 24          
     
    36 36         if capt:  
    37 37             self.html.append('<pre>%s</pre>' % capt)  
      38              
    38 39     def addFailure(self, test, err, capt, tb_info):  
    39 40         err = self.formatErr(err)  
  • trunk/examples/plugin/setup.py

    r9 r29  
    3 3  
    4 4 """  
    5   import sys  
    6 5 try:  
    7 6     import ez_setup