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
simple_thunk_feature = features._CompatabilityThunkFeature(
72
symbol_versioning.deprecated_in((2, 1, 0)),
73
'bzrlib.tests.test_features',
74
'simple_thunk_feature',
76
replacement_module='bzrlib.tests.features')
79
class Test_CompatibilityFeature(tests.TestCase):
81
def test_does_thunk(self):
82
res = self.callDeprecated(
83
['bzrlib.tests.test_features.simple_thunk_feature '
84
'was deprecated in version 2.1.0. '
85
'Use bzrlib.tests.features.UnicodeFilename instead.'],
86
simple_thunk_feature.available)
87
self.assertEqual(features.UnicodeFilename.available(), res)
90
class TestModuleAvailableFeature(tests.TestCase):
92
def test_available_module(self):
93
feature = features.ModuleAvailableFeature('bzrlib.tests')
94
self.assertEqual('bzrlib.tests', feature.module_name)
95
self.assertEqual('bzrlib.tests', str(feature))
96
self.assertTrue(feature.available())
97
self.assertIs(tests, feature.module)
99
def test_unavailable_module(self):
100
feature = features.ModuleAvailableFeature(
101
'bzrlib.no_such_module_exists')
102
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
103
self.assertFalse(feature.available())
104
self.assertIs(None, feature.module)
107
class TestUnicodeFilenameFeature(tests.TestCase):
109
def test_probe_passes(self):
110
"""UnicodeFilenameFeature._probe passes."""
111
# We can't test much more than that because the behaviour depends
113
features.UnicodeFilenameFeature._probe()