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.
24
from bzrlib.tests import (
29
class TestFeature(tests.TestCase):
31
def test_caching(self):
32
"""Feature._probe is called by the feature at most once."""
33
class InstrumentedFeature(features.Feature):
35
super(InstrumentedFeature, self).__init__()
39
self.calls.append('_probe')
41
feature = InstrumentedFeature()
43
self.assertEqual(['_probe'], feature.calls)
45
self.assertEqual(['_probe'], feature.calls)
47
def test_named_str(self):
48
"""Feature.__str__ should thunk to feature_name()."""
49
class NamedFeature(features.Feature):
50
def feature_name(self):
52
feature = NamedFeature()
53
self.assertEqual('symlinks', str(feature))
55
def test_default_str(self):
56
"""Feature.__str__ should default to __class__.__name__."""
57
class NamedFeature(features.Feature):
59
feature = NamedFeature()
60
self.assertEqual('NamedFeature', str(feature))
63
class TestUnavailableFeature(tests.TestCase):
65
def test_access_feature(self):
66
feature = features.Feature()
67
exception = tests.UnavailableFeature(feature)
68
self.assertIs(feature, exception.args[0])
71
# Although this was deprecated a long time ago, please keep it here because
72
# it's really just a test fixture for test-feature deprecation.
73
simple_thunk_feature = features._CompatabilityThunkFeature(
74
symbol_versioning.deprecated_in((2, 1, 0)),
75
'bzrlib.tests.test_features',
76
'simple_thunk_feature',
77
'UnicodeFilenameFeature',
78
replacement_module='bzrlib.tests.features')
81
class Test_CompatibilityFeature(tests.TestCase):
83
def test_does_thunk(self):
84
res = self.callDeprecated(
85
['bzrlib.tests.test_features.simple_thunk_feature '
86
'was deprecated in version 2.1.0. '
87
'Use bzrlib.tests.features.UnicodeFilenameFeature instead.'],
88
simple_thunk_feature.available)
89
self.assertEqual(features.UnicodeFilenameFeature.available(), res)
92
class TestModuleAvailableFeature(tests.TestCase):
94
def test_available_module(self):
95
feature = features.ModuleAvailableFeature('bzrlib.tests')
96
self.assertEqual('bzrlib.tests', feature.module_name)
97
self.assertEqual('bzrlib.tests', str(feature))
98
self.assertTrue(feature.available())
99
self.assertIs(tests, feature.module)
101
def test_unavailable_module(self):
102
feature = features.ModuleAvailableFeature(
103
'bzrlib.no_such_module_exists')
104
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
105
self.assertFalse(feature.available())
106
self.assertIs(None, feature.module)
109
class TestUnicodeFilenameFeature(tests.TestCase):
111
def test_probe_passes(self):
112
"""UnicodeFilenameFeature._probe passes."""
113
# We can't test much more than that because the behaviour depends
115
features.UnicodeFilenameFeature._probe()