/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2011, 2016 Canonical Ltd
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
17
"""Tests for test feature dependencies."""
18
19
import sys
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from .. import (
6759.4.3 by Jelmer Vernooij
Avoid accessing global state.
22
    plugin as _mod_plugin,
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
23
    symbol_versioning,
24
    tests,
25
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
26
from . import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
27
    features,
28
    )
29
30
31
class TestFeature(tests.TestCase):
32
33
    def test_caching(self):
34
        """Feature._probe is called by the feature at most once."""
35
        class InstrumentedFeature(features.Feature):
36
            def __init__(self):
37
                super(InstrumentedFeature, self).__init__()
38
                self.calls = []
39
40
            def _probe(self):
41
                self.calls.append('_probe')
42
                return False
43
        feature = InstrumentedFeature()
44
        feature.available()
45
        self.assertEqual(['_probe'], feature.calls)
46
        feature.available()
47
        self.assertEqual(['_probe'], feature.calls)
48
49
    def test_named_str(self):
50
        """Feature.__str__ should thunk to feature_name()."""
51
        class NamedFeature(features.Feature):
52
            def feature_name(self):
53
                return 'symlinks'
54
        feature = NamedFeature()
55
        self.assertEqual('symlinks', str(feature))
56
57
    def test_default_str(self):
58
        """Feature.__str__ should default to __class__.__name__."""
59
        class NamedFeature(features.Feature):
60
            pass
61
        feature = NamedFeature()
62
        self.assertEqual('NamedFeature', str(feature))
63
64
65
class TestUnavailableFeature(tests.TestCase):
66
67
    def test_access_feature(self):
68
        feature = features.Feature()
69
        exception = tests.UnavailableFeature(feature)
70
        self.assertIs(feature, exception.args[0])
71
72
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
73
# Although this was deprecated a long time ago, please keep it here because
74
# it's really just a test fixture for test-feature deprecation.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
75
simple_thunk_feature = features._CompatabilityThunkFeature(
76
    symbol_versioning.deprecated_in((2, 1, 0)),
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
77
    'breezy.tests.test_features',
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
78
    'simple_thunk_feature',
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
79
    'UnicodeFilenameFeature',
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
80
    replacement_module='breezy.tests.features')
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
81
82
83
class Test_CompatibilityFeature(tests.TestCase):
84
85
    def test_does_thunk(self):
86
        res = self.callDeprecated(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
87
            ['breezy.tests.test_features.simple_thunk_feature '
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
88
             'was deprecated in version 2.1.0. '
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
89
             'Use breezy.tests.features.UnicodeFilenameFeature instead.'],
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
90
            simple_thunk_feature.available)
5967.12.3 by Martin Pool
Unify duplicated UnicodeFilename and _PosixPermissionsFeature
91
        self.assertEqual(features.UnicodeFilenameFeature.available(), res)
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
92
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
93
    def test_reports_correct_location(self):
94
        a_feature = features._CompatabilityThunkFeature(
95
            symbol_versioning.deprecated_in((2, 1, 0)),
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
96
            'breezy.tests.test_features',
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
97
            'a_feature',
98
            'UnicodeFilenameFeature',
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
99
            replacement_module='breezy.tests.features')
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
101
        def test_caller(message, category=None, stacklevel=1):
102
            # Find ourselves back from the right frame
103
            caller = sys._getframe(stacklevel)
104
            reported_file = caller.f_globals['__file__']
105
            reported_lineno = caller.f_lineno
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
106
            self.assertEqual(__file__, reported_file)
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
107
            # The call we're tracking occurred the line after we grabbed the
108
            # lineno.
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
109
            self.assertEqual(self.lineno + 1, reported_lineno)
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
110
        self.overrideAttr(symbol_versioning, 'warn', test_caller)
111
        # Grab the current lineno
112
        self.lineno = sys._getframe().f_lineno
113
        self.requireFeature(a_feature)
114
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
115
116
class TestModuleAvailableFeature(tests.TestCase):
117
118
    def test_available_module(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
119
        feature = features.ModuleAvailableFeature('breezy.tests')
120
        self.assertEqual('breezy.tests', feature.module_name)
121
        self.assertEqual('breezy.tests', str(feature))
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
122
        self.assertTrue(feature.available())
123
        self.assertIs(tests, feature.module)
124
125
    def test_unavailable_module(self):
126
        feature = features.ModuleAvailableFeature(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
127
            'breezy.no_such_module_exists')
128
        self.assertEqual('breezy.no_such_module_exists', str(feature))
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
129
        self.assertFalse(feature.available())
130
        self.assertIs(None, feature.module)
131
132
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
133
class TestPluginLoadedFeature(tests.TestCase):
134
135
    def test_available_plugin(self):
6759.4.3 by Jelmer Vernooij
Avoid accessing global state.
136
        plugins = _mod_plugin.plugins()
137
        if not plugins:
6704.1.1 by Jelmer Vernooij
Only run PluginLoadedFeature if there are actually plugins loaded.
138
            self.skipTest('no plugins available to test with')
6759.4.3 by Jelmer Vernooij
Avoid accessing global state.
139
        a_plugin_name = next(iter(plugins))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
140
        feature = features.PluginLoadedFeature(a_plugin_name)
141
        self.assertEqual(a_plugin_name, feature.plugin_name)
6703.1.2 by Jelmer Vernooij
Change feature name to '... plugin'.
142
        self.assertEqual(a_plugin_name + ' plugin', str(feature))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
143
        self.assertTrue(feature.available())
144
145
    def test_unavailable_plugin(self):
146
        feature = features.PluginLoadedFeature('idontexist')
6703.1.2 by Jelmer Vernooij
Change feature name to '... plugin'.
147
        self.assertEqual('idontexist plugin', str(feature))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
148
        self.assertFalse(feature.available())
149
        self.assertIs(None, feature.plugin)
150
151
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
152
class TestUnicodeFilenameFeature(tests.TestCase):
153
154
    def test_probe_passes(self):
155
        """UnicodeFilenameFeature._probe passes."""
156
        # We can't test much more than that because the behaviour depends
157
        # on the platform.
158
        features.UnicodeFilenameFeature._probe()
6478.3.1 by Jelmer Vernooij
Add backslashfilenamefeature.
159
160
161
class TestBackslashFilenameFeature(tests.TestCase):
162
163
    def test_probe_passes(self):
164
        """BackslashFilenameFeature._probe passes."""
165
        # We can't test much more than that because the behaviour depends
166
        # on the platform.
167
        features.BackslashFilenameFeature._probe()