74
73
# it's really just a test fixture for test-feature deprecation.
75
74
simple_thunk_feature = features._CompatabilityThunkFeature(
76
75
symbol_versioning.deprecated_in((2, 1, 0)),
77
'breezy.tests.test_features',
76
'bzrlib.tests.test_features',
78
77
'simple_thunk_feature',
79
78
'UnicodeFilenameFeature',
80
replacement_module='breezy.tests.features')
79
replacement_module='bzrlib.tests.features')
83
82
class Test_CompatibilityFeature(tests.TestCase):
85
84
def test_does_thunk(self):
86
85
res = self.callDeprecated(
87
['breezy.tests.test_features.simple_thunk_feature '
86
['bzrlib.tests.test_features.simple_thunk_feature '
88
87
'was deprecated in version 2.1.0. '
89
'Use breezy.tests.features.UnicodeFilenameFeature instead.'],
88
'Use bzrlib.tests.features.UnicodeFilenameFeature instead.'],
90
89
simple_thunk_feature.available)
91
90
self.assertEqual(features.UnicodeFilenameFeature.available(), res)
93
92
def test_reports_correct_location(self):
94
93
a_feature = features._CompatabilityThunkFeature(
95
94
symbol_versioning.deprecated_in((2, 1, 0)),
96
'breezy.tests.test_features',
95
'bzrlib.tests.test_features',
98
97
'UnicodeFilenameFeature',
99
replacement_module='breezy.tests.features')
98
replacement_module='bzrlib.tests.features')
100
99
def test_caller(message, category=None, stacklevel=1):
101
100
# Find ourselves back from the right frame
102
101
caller = sys._getframe(stacklevel)
103
102
reported_file = caller.f_globals['__file__']
104
103
reported_lineno = caller.f_lineno
105
self.assertEqual(__file__, reported_file)
104
self.assertEquals(__file__, reported_file)
106
105
# The call we're tracking occurred the line after we grabbed the
108
self.assertEqual(self.lineno + 1, reported_lineno)
107
self.assertEquals(self.lineno + 1, reported_lineno)
109
108
self.overrideAttr(symbol_versioning, 'warn', test_caller)
110
109
# Grab the current lineno
111
110
self.lineno = sys._getframe().f_lineno
115
114
class TestModuleAvailableFeature(tests.TestCase):
117
116
def test_available_module(self):
118
feature = features.ModuleAvailableFeature('breezy.tests')
119
self.assertEqual('breezy.tests', feature.module_name)
120
self.assertEqual('breezy.tests', str(feature))
117
feature = features.ModuleAvailableFeature('bzrlib.tests')
118
self.assertEqual('bzrlib.tests', feature.module_name)
119
self.assertEqual('bzrlib.tests', str(feature))
121
120
self.assertTrue(feature.available())
122
121
self.assertIs(tests, feature.module)
124
123
def test_unavailable_module(self):
125
124
feature = features.ModuleAvailableFeature(
126
'breezy.no_such_module_exists')
127
self.assertEqual('breezy.no_such_module_exists', str(feature))
125
'bzrlib.no_such_module_exists')
126
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
128
127
self.assertFalse(feature.available())
129
128
self.assertIs(None, feature.module)
132
class TestPluginLoadedFeature(tests.TestCase):
134
def test_available_plugin(self):
135
plugins = _mod_plugin.plugins()
137
self.skipTest('no plugins available to test with')
138
a_plugin_name = next(iter(plugins))
139
feature = features.PluginLoadedFeature(a_plugin_name)
140
self.assertEqual(a_plugin_name, feature.plugin_name)
141
self.assertEqual(a_plugin_name + ' plugin', str(feature))
142
self.assertTrue(feature.available())
144
def test_unavailable_plugin(self):
145
feature = features.PluginLoadedFeature('idontexist')
146
self.assertEqual('idontexist plugin', str(feature))
147
self.assertFalse(feature.available())
148
self.assertIs(None, feature.plugin)
151
131
class TestUnicodeFilenameFeature(tests.TestCase):
153
133
def test_probe_passes(self):
155
135
# We can't test much more than that because the behaviour depends
156
136
# on the platform.
157
137
features.UnicodeFilenameFeature._probe()
160
class TestBackslashFilenameFeature(tests.TestCase):
162
def test_probe_passes(self):
163
"""BackslashFilenameFeature._probe passes."""
164
# We can't test much more than that because the behaviour depends
166
features.BackslashFilenameFeature._probe()