/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')
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
100
        def test_caller(message, category=None, stacklevel=1):
101
            # Find ourselves back from the right frame
102
            caller = sys._getframe(stacklevel)
103
            reported_file = caller.f_globals['__file__']
104
            reported_lineno = caller.f_lineno
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
105
            self.assertEqual(__file__, reported_file)
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
106
            # The call we're tracking occurred the line after we grabbed the
107
            # lineno.
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
108
            self.assertEqual(self.lineno + 1, reported_lineno)
6325.3.1 by Vincent Ladeuil
Give meaningful deprecation warnings for deprecated test features
109
        self.overrideAttr(symbol_versioning, 'warn', test_caller)
110
        # Grab the current lineno
111
        self.lineno = sys._getframe().f_lineno
112
        self.requireFeature(a_feature)
113
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
114
115
class TestModuleAvailableFeature(tests.TestCase):
116
117
    def test_available_module(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
118
        feature = features.ModuleAvailableFeature('breezy.tests')
119
        self.assertEqual('breezy.tests', feature.module_name)
120
        self.assertEqual('breezy.tests', str(feature))
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
121
        self.assertTrue(feature.available())
122
        self.assertIs(tests, feature.module)
123
124
    def test_unavailable_module(self):
125
        feature = features.ModuleAvailableFeature(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
126
            'breezy.no_such_module_exists')
127
        self.assertEqual('breezy.no_such_module_exists', str(feature))
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
128
        self.assertFalse(feature.available())
129
        self.assertIs(None, feature.module)
130
131
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
132
class TestPluginLoadedFeature(tests.TestCase):
133
134
    def test_available_plugin(self):
6759.4.3 by Jelmer Vernooij
Avoid accessing global state.
135
        plugins = _mod_plugin.plugins()
136
        if not plugins:
6704.1.1 by Jelmer Vernooij
Only run PluginLoadedFeature if there are actually plugins loaded.
137
            self.skipTest('no plugins available to test with')
6759.4.3 by Jelmer Vernooij
Avoid accessing global state.
138
        a_plugin_name = next(iter(plugins))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
139
        feature = features.PluginLoadedFeature(a_plugin_name)
140
        self.assertEqual(a_plugin_name, feature.plugin_name)
6703.1.2 by Jelmer Vernooij
Change feature name to '... plugin'.
141
        self.assertEqual(a_plugin_name + ' plugin', str(feature))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
142
        self.assertTrue(feature.available())
143
144
    def test_unavailable_plugin(self):
145
        feature = features.PluginLoadedFeature('idontexist')
6703.1.2 by Jelmer Vernooij
Change feature name to '... plugin'.
146
        self.assertEqual('idontexist plugin', str(feature))
6703.1.1 by Jelmer Vernooij
Add a ``PluginLoadedFeature``.
147
        self.assertFalse(feature.available())
148
        self.assertIs(None, feature.plugin)
149
150
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
151
class TestUnicodeFilenameFeature(tests.TestCase):
152
153
    def test_probe_passes(self):
154
        """UnicodeFilenameFeature._probe passes."""
155
        # We can't test much more than that because the behaviour depends
156
        # on the platform.
157
        features.UnicodeFilenameFeature._probe()
6478.3.1 by Jelmer Vernooij
Add backslashfilenamefeature.
158
159
160
class TestBackslashFilenameFeature(tests.TestCase):
161
162
    def test_probe_passes(self):
163
        """BackslashFilenameFeature._probe passes."""
164
        # We can't test much more than that because the behaviour depends
165
        # on the platform.
166
        features.BackslashFilenameFeature._probe()