~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_features.py

  • Committer: Vincent Ladeuil
  • Date: 2010-10-07 06:08:01 UTC
  • mto: This revision was merged to the branch mainline in revision 5491.
  • Revision ID: v.ladeuil+lp@free.fr-20101007060801-wfdhizfhfmctl8qa
Fix some typos and propose a release planning.

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
 
# 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')
79
 
 
80
 
 
81
 
class Test_CompatibilityFeature(tests.TestCase):
82
 
 
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)
90
 
 
91
 
 
92
 
class TestModuleAvailableFeature(tests.TestCase):
93
 
 
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)
100
 
 
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)
107
 
 
108
 
 
109
 
class TestUnicodeFilenameFeature(tests.TestCase):
110
 
 
111
 
    def test_probe_passes(self):
112
 
        """UnicodeFilenameFeature._probe passes."""
113
 
        # We can't test much more than that because the behaviour depends
114
 
        # on the platform.
115
 
        features.UnicodeFilenameFeature._probe()