/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-16 18:34:26 UTC
  • mfrom: (5609.46.3 2.3.4-dev)
  • mto: This revision was merged to the branch mainline in revision 5980.
  • Revision ID: v.ladeuil+lp@free.fr-20110616183426-oj818x56zm7yzvb8
Merge 2.3 into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
"""A collection of commonly used 'Features' which bzrlib uses to skip tests."""
 
18
 
17
19
import os
18
20
import stat
19
 
 
20
 
from bzrlib import tests
21
 
from bzrlib.symbol_versioning import deprecated_in
22
 
 
 
21
import sys
 
22
 
 
23
from bzrlib import (
 
24
    osutils,
 
25
    tests,
 
26
    )
 
27
 
 
28
 
 
29
class _NotRunningAsRoot(tests.Feature):
 
30
 
 
31
    def _probe(self):
 
32
        try:
 
33
            uid = os.getuid()
 
34
        except AttributeError:
 
35
            # If there is no uid, chances are there is no root either
 
36
            return True
 
37
        return uid != 0
 
38
 
 
39
    def feature_name(self):
 
40
        return 'Not running as root'
 
41
 
 
42
 
 
43
not_running_as_root = _NotRunningAsRoot()
23
44
 
24
45
apport = tests.ModuleAvailableFeature('apport')
 
46
lzma = tests.ModuleAvailableFeature('lzma')
 
47
meliae = tests.ModuleAvailableFeature('meliae')
25
48
paramiko = tests.ModuleAvailableFeature('paramiko')
26
49
pycurl = tests.ModuleAvailableFeature('pycurl')
 
50
pywintypes = tests.ModuleAvailableFeature('pywintypes')
 
51
sphinx = tests.ModuleAvailableFeature('sphinx')
27
52
subunit = tests.ModuleAvailableFeature('subunit')
28
53
 
29
54
 
 
55
class _BackslashDirSeparatorFeature(tests.Feature):
 
56
 
 
57
    def _probe(self):
 
58
        try:
 
59
            os.lstat(os.getcwd() + '\\')
 
60
        except OSError:
 
61
            return False
 
62
        else:
 
63
            return True
 
64
 
 
65
    def feature_name(self):
 
66
        return "Filesystem treats '\\' as a directory separator."
 
67
 
 
68
backslashdir_feature = _BackslashDirSeparatorFeature()
 
69
 
 
70
 
30
71
class _PosixPermissionsFeature(tests.Feature):
31
72
 
32
73
    def _probe(self):
61
102
 
62
103
chown_feature = _ChownFeature()
63
104
 
 
105
 
 
106
class ExecutableFeature(tests.Feature):
 
107
    """Feature testing whether an executable of a given name is on the PATH."""
 
108
 
 
109
    def __init__(self, name):
 
110
        super(ExecutableFeature, self).__init__()
 
111
        self.name = name
 
112
        self._path = None
 
113
 
 
114
    @property
 
115
    def path(self):
 
116
        # This is a property, so accessing path ensures _probe was called
 
117
        self.available()
 
118
        return self._path
 
119
 
 
120
    def _probe(self):
 
121
        self._path = osutils.find_executable_on_path(self.name)
 
122
        return self._path is not None
 
123
 
 
124
    def feature_name(self):
 
125
        return '%s executable' % self.name
 
126
 
 
127
 
 
128
bash_feature = ExecutableFeature('bash')
 
129
sed_feature = ExecutableFeature('sed')
 
130
diff_feature = ExecutableFeature('diff')
 
131
 
 
132
 
 
133
class Win32Feature(tests.Feature):
 
134
    """Feature testing whether we're running selftest on Windows
 
135
    or Windows-like platform.
 
136
    """
 
137
 
 
138
    def _probe(self):
 
139
        return sys.platform == 'win32'
 
140
 
 
141
    def feature_name(self):
 
142
        return "win32 platform"
 
143
 
 
144
win32_feature = Win32Feature()