PageRenderTime 41ms CodeModel.GetById 12ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/unit_tests/test_config.py

https://bitbucket.org/jpellerin/nose/
Python | 141 lines | 107 code | 21 blank | 13 comment | 10 complexity | fa917af21eac9bf5fb3685f00e41f931 MD5 | raw file
  1import re
  2import os
  3import tempfile
  4import unittest
  5import warnings
  6import pickle
  7import sys
  8
  9import nose.config
 10from nose.plugins.manager import DefaultPluginManager
 11from nose.plugins.skip import SkipTest
 12from nose.plugins.prof import Profile
 13
 14
 15class TestNoseConfig(unittest.TestCase):
 16
 17    def test_defaults(self):
 18        c = nose.config.Config()
 19        assert c.addPaths == True
 20        # FIXME etc
 21
 22    def test_reset(self):
 23        c = nose.config.Config()
 24        c.include = 'include'
 25        assert c.include == 'include'
 26        c.reset()
 27        assert c.include is None
 28
 29    def test_update(self):
 30        c = nose.config.Config()
 31        c.update({'exclude':'x'})
 32        assert c.exclude == 'x'
 33
 34    def test_ignore_files_default(self):
 35        """
 36        The default configuration should have several ignore file settings.
 37        """
 38        c = nose.config.Config()
 39        c.configure(['program'])
 40        self.assertEqual(len(c.ignoreFiles), 3)
 41    
 42    def test_ignore_files_single(self):
 43        """A single ignore-files flag should override the default settings.""" 
 44        c = nose.config.Config()
 45        c.configure(['program', '--ignore-files=a'])
 46        self.assertEqual(len(c.ignoreFiles), 1)
 47        aMatcher = c.ignoreFiles[0]
 48        assert aMatcher.match('a')
 49        assert not aMatcher.match('b')
 50    
 51    def test_ignore_files_multiple(self):
 52        """
 53        Multiple ignore-files flags should be appended together, overriding
 54        the default settings.
 55        """
 56        c = nose.config.Config()
 57        c.configure(['program', '--ignore-files=a', '-Ib'])
 58        self.assertEqual(len(c.ignoreFiles), 2)
 59        aMatcher, bMatcher = c.ignoreFiles
 60        assert aMatcher.match('a')
 61        assert not aMatcher.match('b')
 62        assert bMatcher.match('b')
 63        assert not bMatcher.match('a')
 64    
 65    def test_multiple_include(self):
 66        c = nose.config.Config()
 67        c.configure(['program', '--include=a', '--include=b'])
 68        self.assertEqual(len(c.include), 2)
 69        a, b = c.include
 70        assert a.match('a')
 71        assert not a.match('b')
 72        assert b.match('b')
 73        assert not b.match('a')
 74
 75    def test_single_include(self):
 76        c = nose.config.Config()
 77        c.configure(['program', '--include=b'])
 78        self.assertEqual(len(c.include), 1)
 79        b = c.include[0]
 80        assert b.match('b')
 81        assert not b.match('a')
 82
 83    def test_plugins(self):
 84        c = nose.config.Config()
 85        assert c.plugins
 86        c.plugins.begin()
 87
 88    def test_testnames(self):
 89        c = nose.config.Config()
 90        c.configure(['program', 'foo', 'bar', 'baz.buz.biz'])
 91        self.assertEqual(c.testNames, ['foo', 'bar', 'baz.buz.biz'])
 92
 93        c = nose.config.Config(testNames=['foo'])
 94        c.configure([])
 95        self.assertEqual(c.testNames, ['foo'])
 96
 97    def test_where(self):
 98        # we don't need to see our own warnings
 99        warnings.filterwarnings(action='ignore',
100                                category=DeprecationWarning,
101                                module='nose.config')
102
103        here = os.path.dirname(__file__)
104        support = os.path.join(here, 'support')
105        foo = os.path.abspath(os.path.join(support, 'foo'))
106        c = nose.config.Config()
107        c.configure(['program', '-w', foo, '-w', 'bar'])
108        self.assertEqual(c.workingDir, foo)
109        self.assertEqual(c.testNames, ['bar'])
110
111    def test_progname_looks_like_option(self):
112        # issue #184
113        c = nose.config.Config()
114        # the -v here is the program name, not an option
115        # this matters eg. with python -c "import nose; nose.main()"
116        c.configure(['-v', 'mytests'])
117        self.assertEqual(c.verbosity, 1)
118
119    def test_pickle_empty(self):
120        c = nose.config.Config()
121        cp = pickle.dumps(c)
122        cc = pickle.loads(cp)
123
124    def test_pickle_configured(self):
125        if 'java' in sys.version.lower():
126            raise SkipTest("jython has no profiler plugin")
127        c = nose.config.Config(plugins=DefaultPluginManager())
128        config_args = ['--with-doctest', '--with-coverage', 
129                     '--with-id', '--attr=A', '--collect', '--all',
130                     '--with-isolation', '-d', '--with-xunit', '--processes=2',
131                     '--pdb']
132        if Profile.available():
133            config_args.append('--with-profile')
134        c.configure(config_args)
135        cp = pickle.dumps(c)
136        cc = pickle.loads(cp)
137        assert cc.plugins._plugins
138
139
140if __name__ == '__main__':
141    unittest.main()