1
# Copyright (C) 2005-2011 Canonical Ltd
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.
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.
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
17
"""Tests for test feature dependencies."""
25
from bzrlib.tests import (
30
class TestFeature(tests.TestCase):
32
def test_caching(self):
33
"""Feature._probe is called by the feature at most once."""
34
class InstrumentedFeature(features.Feature):
36
super(InstrumentedFeature, self).__init__()
40
self.calls.append('_probe')
42
feature = InstrumentedFeature()
44
self.assertEqual(['_probe'], feature.calls)
46
self.assertEqual(['_probe'], feature.calls)
48
def test_named_str(self):
49
"""Feature.__str__ should thunk to feature_name()."""
50
class NamedFeature(features.Feature):
51
def feature_name(self):
53
feature = NamedFeature()
54
self.assertEqual('symlinks', str(feature))
56
def test_default_str(self):
57
"""Feature.__str__ should default to __class__.__name__."""
58
class NamedFeature(features.Feature):
60
feature = NamedFeature()
61
self.assertEqual('NamedFeature', str(feature))
64
class TestUnavailableFeature(tests.TestCase):
66
def test_access_feature(self):
67
feature = features.Feature()
68
exception = tests.UnavailableFeature(feature)
69
self.assertIs(feature, exception.args[0])
72
# Although this was deprecated a long time ago, please keep it here because
73
# it's really just a test fixture for test-feature deprecation.
74
simple_thunk_feature = features._CompatabilityThunkFeature(
75
symbol_versioning.deprecated_in((2, 1, 0)),
76
'bzrlib.tests.test_features',
77
'simple_thunk_feature',
78
'UnicodeFilenameFeature',
79
replacement_module='bzrlib.tests.features')
82
class Test_CompatibilityFeature(tests.TestCase):
84
def test_does_thunk(self):
85
res = self.callDeprecated(
86
['bzrlib.tests.test_features.simple_thunk_feature '
87
'was deprecated in version 2.1.0. '
88
'Use bzrlib.tests.features.UnicodeFilenameFeature instead.'],
89
simple_thunk_feature.available)
90
self.assertEqual(features.UnicodeFilenameFeature.available(), res)
92
def test_reports_correct_location(self):
93
a_feature = features._CompatabilityThunkFeature(
94
symbol_versioning.deprecated_in((2, 1, 0)),
95
'bzrlib.tests.test_features',
97
'UnicodeFilenameFeature',
98
replacement_module='bzrlib.tests.features')
99
def test_caller(message, category=None, stacklevel=1):
100
# Find ourselves back from the right frame
101
caller = sys._getframe(stacklevel)
102
reported_file = caller.f_globals['__file__']
103
reported_lineno = caller.f_lineno
104
self.assertEquals(__file__, reported_file)
105
# The call we're tracking occurred the line after we grabbed the
107
self.assertEquals(self.lineno + 1, reported_lineno)
108
self.overrideAttr(symbol_versioning, 'warn', test_caller)
109
# Grab the current lineno
110
self.lineno = sys._getframe().f_lineno
111
self.requireFeature(a_feature)
114
class TestModuleAvailableFeature(tests.TestCase):
116
def test_available_module(self):
117
feature = features.ModuleAvailableFeature('bzrlib.tests')
118
self.assertEqual('bzrlib.tests', feature.module_name)
119
self.assertEqual('bzrlib.tests', str(feature))
120
self.assertTrue(feature.available())
121
self.assertIs(tests, feature.module)
123
def test_unavailable_module(self):
124
feature = features.ModuleAvailableFeature(
125
'bzrlib.no_such_module_exists')
126
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
127
self.assertFalse(feature.available())
128
self.assertIs(None, feature.module)
131
class TestUnicodeFilenameFeature(tests.TestCase):
133
def test_probe_passes(self):
134
"""UnicodeFilenameFeature._probe passes."""
135
# We can't test much more than that because the behaviour depends
137
features.UnicodeFilenameFeature._probe()