PageRenderTime 38ms CodeModel.GetById 31ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/functional_tests/test_issue_082.py

https://bitbucket.org/jpellerin/nose/
Python | 74 lines | 50 code | 16 blank | 8 comment | 17 complexity | a13fcf31b235fd59ce6604de59eb30fa MD5 | raw file
 1import os
 2import re
 3try:
 4    from cStringIO import StringIO
 5except ImportError:
 6    from StringIO import StringIO
 7import sys
 8import unittest
 9
10from nose.plugins import Plugin, PluginTester
11from nose.plugins.builtin import FailureDetail, Capture, Doctest
12
13support = os.path.join(os.path.dirname(__file__), 'support')
14
15
16class IncludeUnderscoreFilesPlugin(Plugin):
17
18    # Note that this is purely for purposes of testing nose itself, and is
19    # not intended to be a useful plugin.  In particular, the rules it
20    # applies for _*.py files differ from the nose defaults (e.g. the
21    # --testmatch option is ignored).
22
23    name = "underscorefiles"
24
25    def wantFile(self, file):
26        base = os.path.basename(file)
27        dummy, ext = os.path.splitext(base)
28        pysrc = ext == '.py'
29        if pysrc and os.path.basename(file).startswith("_"):
30            return True
31
32    def wantDirectory(self, dirname):
33        if os.path.basename(dirname).startswith("_"):
34            return True
35
36
37class TestIncludeUnderscoreFiles(PluginTester, unittest.TestCase):
38    activate = '--with-underscorefiles'
39    plugins = [IncludeUnderscoreFilesPlugin(), Doctest()]
40    args = ['-v', '--with-doctest']
41    suitepath = os.path.join(support, 'issue082')
42    ignoreFiles = (re.compile(r'^\.'),
43                   # we want _*.py, but don't want e.g. __init__.py, since that
44                   # appears to cause infinite recursion at the moment
45                   re.compile(r'^__'),
46                   re.compile(r'^setup\.py$')
47                   )
48
49    def test_assert_info_in_output(self):
50        print self.output
51        # In future, all four test cases will be run.  Backwards-compatibility
52        # means that can't be done in nose 0.10.
53        assert '_mypackage._eggs' not in str(self.output)
54        assert '_mypackage.bacon' not in str(self.output)
55        assert 'Doctest: mypublicpackage._foo ... FAIL' in str(self.output)
56        assert 'Doctest: mypublicpackage.bar ... FAIL' in str(self.output)
57
58
59class TestExcludeUnderscoreFilesByDefault(PluginTester, unittest.TestCase):
60    activate = '-v'
61    plugins = [Doctest()]
62    args = ['--with-doctest']
63    suitepath = os.path.join(support, 'issue082')
64
65    def test_assert_info_in_output(self):
66        print self.output
67        assert '_mypackage._eggs' not in str(self.output)
68        assert '_mypackage.bacon' not in str(self.output)
69        assert 'mypublicpackage._foo' not in str(self.output)
70        assert 'Doctest: mypublicpackage.bar ... FAIL' in str(self.output)
71
72
73if __name__ == '__main__':
74    unittest.main()