~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_features.py

  • Committer: Martin Pool
  • Date: 2011-06-14 01:26:41 UTC
  • mto: (6034.2.1 integration)
  • mto: This revision was merged to the branch mainline in revision 6043.
  • Revision ID: mbp@canonical.com-20110614012641-dnb69zb57ae5je4w
Move all test features into bzrlib.tests.features

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 Canonical Ltd
 
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
 
 
17
"""Tests for test feature dependencies.
 
18
"""
 
19
 
 
20
from bzrlib import (
 
21
    symbol_versioning,
 
22
    tests,
 
23
    )
 
24
from bzrlib.tests import (
 
25
    features,
 
26
    )
 
27
 
 
28
 
 
29
class TestFeature(tests.TestCase):
 
30
 
 
31
    def test_caching(self):
 
32
        """Feature._probe is called by the feature at most once."""
 
33
        class InstrumentedFeature(features.Feature):
 
34
            def __init__(self):
 
35
                super(InstrumentedFeature, self).__init__()
 
36
                self.calls = []
 
37
 
 
38
            def _probe(self):
 
39
                self.calls.append('_probe')
 
40
                return False
 
41
        feature = InstrumentedFeature()
 
42
        feature.available()
 
43
        self.assertEqual(['_probe'], feature.calls)
 
44
        feature.available()
 
45
        self.assertEqual(['_probe'], feature.calls)
 
46
 
 
47
    def test_named_str(self):
 
48
        """Feature.__str__ should thunk to feature_name()."""
 
49
        class NamedFeature(features.Feature):
 
50
            def feature_name(self):
 
51
                return 'symlinks'
 
52
        feature = NamedFeature()
 
53
        self.assertEqual('symlinks', str(feature))
 
54
 
 
55
    def test_default_str(self):
 
56
        """Feature.__str__ should default to __class__.__name__."""
 
57
        class NamedFeature(features.Feature):
 
58
            pass
 
59
        feature = NamedFeature()
 
60
        self.assertEqual('NamedFeature', str(feature))
 
61
 
 
62
 
 
63
class TestUnavailableFeature(tests.TestCase):
 
64
 
 
65
    def test_access_feature(self):
 
66
        feature = features.Feature()
 
67
        exception = tests.UnavailableFeature(feature)
 
68
        self.assertIs(feature, exception.args[0])
 
69
 
 
70
 
 
71
simple_thunk_feature = features._CompatabilityThunkFeature(
 
72
    symbol_versioning.deprecated_in((2, 1, 0)),
 
73
    'bzrlib.tests.test_features',
 
74
    'simple_thunk_feature',
 
75
    'UnicodeFilename',
 
76
    replacement_module='bzrlib.tests.features')
 
77
 
 
78
 
 
79
class Test_CompatibilityFeature(tests.TestCase):
 
80
 
 
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)
 
88
 
 
89
 
 
90
class TestModuleAvailableFeature(tests.TestCase):
 
91
 
 
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)
 
98
 
 
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)
 
105
 
 
106
 
 
107
class TestUnicodeFilenameFeature(tests.TestCase):
 
108
 
 
109
    def test_probe_passes(self):
 
110
        """UnicodeFilenameFeature._probe passes."""
 
111
        # We can't test much more than that because the behaviour depends
 
112
        # on the platform.
 
113
        features.UnicodeFilenameFeature._probe()