summaryrefslogtreecommitdiff
path: root/unit_tests/test_config.py
blob: b58b054150c6ed7fd780b7588a13cb9ffe5ee935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import re
import os
import tempfile
import unittest
import warnings
import pickle
import sys

import nose.config
from nose.plugins.manager import DefaultPluginManager
from nose.plugins.skip import SkipTest
from nose.plugins.prof import Profile


class TestNoseConfig(unittest.TestCase):

    def test_defaults(self):
        c = nose.config.Config()
        assert c.addPaths == True
        # FIXME etc

    def test_reset(self):
        c = nose.config.Config()
        c.include = 'include'
        assert c.include == 'include'
        c.reset()
        assert c.include is None

    def test_update(self):
        c = nose.config.Config()
        c.update({'exclude':'x'})
        assert c.exclude == 'x'

    def test_ignore_files_default(self):
        """
        The default configuration should have several ignore file settings.
        """
        c = nose.config.Config()
        c.configure(['program'])
        self.assertEqual(len(c.ignoreFiles), 3)
    
    def test_ignore_files_single(self):
        """A single ignore-files flag should override the default settings.""" 
        c = nose.config.Config()
        c.configure(['program', '--ignore-files=a'])
        self.assertEqual(len(c.ignoreFiles), 1)
        aMatcher = c.ignoreFiles[0]
        assert aMatcher.match('a')
        assert not aMatcher.match('b')
    
    def test_ignore_files_multiple(self):
        """
        Multiple ignore-files flags should be appended together, overriding
        the default settings.
        """
        c = nose.config.Config()
        c.configure(['program', '--ignore-files=a', '-Ib'])
        self.assertEqual(len(c.ignoreFiles), 2)
        aMatcher, bMatcher = c.ignoreFiles
        assert aMatcher.match('a')
        assert not aMatcher.match('b')
        assert bMatcher.match('b')
        assert not bMatcher.match('a')
    
    def test_multiple_include(self):
        c = nose.config.Config()
        c.configure(['program', '--include=a', '--include=b'])
        self.assertEqual(len(c.include), 2)
        a, b = c.include
        assert a.match('a')
        assert not a.match('b')
        assert b.match('b')
        assert not b.match('a')

    def test_single_include(self):
        c = nose.config.Config()
        c.configure(['program', '--include=b'])
        self.assertEqual(len(c.include), 1)
        b = c.include[0]
        assert b.match('b')
        assert not b.match('a')

    def test_plugins(self):
        c = nose.config.Config()
        assert c.plugins
        c.plugins.begin()

    def test_testnames(self):
        c = nose.config.Config()
        c.configure(['program', 'foo', 'bar', 'baz.buz.biz'])
        self.assertEqual(c.testNames, ['foo', 'bar', 'baz.buz.biz'])

        c = nose.config.Config(testNames=['foo'])
        c.configure([])
        self.assertEqual(c.testNames, ['foo'])

    def test_where(self):
        # we don't need to see our own warnings
        warnings.filterwarnings(action='ignore',
                                category=DeprecationWarning,
                                module='nose.config')

        here = os.path.dirname(__file__)
        support = os.path.join(here, 'support')
        foo = os.path.abspath(os.path.join(support, 'foo'))
        c = nose.config.Config()
        c.configure(['program', '-w', foo, '-w', 'bar'])
        self.assertEqual(c.workingDir, foo)
        self.assertEqual(c.testNames, ['bar'])

    def test_progname_looks_like_option(self):
        # issue #184
        c = nose.config.Config()
        # the -v here is the program name, not an option
        # this matters eg. with python -c "import nose; nose.main()"
        c.configure(['-v', 'mytests'])
        self.assertEqual(c.verbosity, 1)

    def test_pickle_empty(self):
        c = nose.config.Config()
        cp = pickle.dumps(c)
        cc = pickle.loads(cp)

    def test_pickle_configured(self):
        if 'java' in sys.version.lower():
            raise SkipTest("jython has no profiler plugin")
        c = nose.config.Config(plugins=DefaultPluginManager())
        config_args = ['--with-doctest', '--with-coverage', 
                     '--with-id', '--attr=A', '--collect', '--all',
                     '--with-isolation', '-d', '--with-xunit', '--processes=2',
                     '--pdb']
        if Profile.available():
            config_args.append('--with-profile')
        c.configure(config_args)
        cp = pickle.dumps(c)
        cc = pickle.loads(cp)
        assert cc.plugins._plugins


if __name__ == '__main__':
    unittest.main()