/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 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
 
 
19
17
import os
20
18
import stat
21
19
 
22
20
from bzrlib import tests
23
 
 
24
 
 
25
 
class _NotRunningAsRoot(tests.Feature):
26
 
 
27
 
    def _probe(self):
28
 
        try:
29
 
            uid = os.getuid()
30
 
        except AttributeError:
31
 
            # If there is no uid, chances are there is no root either
32
 
            return True
33
 
        return uid != 0
34
 
 
35
 
    def feature_name(self):
36
 
        return 'Not running as root'
37
 
 
38
 
 
39
 
not_running_as_root = _NotRunningAsRoot()
 
21
from bzrlib.symbol_versioning import deprecated_in
 
22
 
40
23
 
41
24
apport = tests.ModuleAvailableFeature('apport')
42
 
meliae = tests.ModuleAvailableFeature('meliae')
43
25
paramiko = tests.ModuleAvailableFeature('paramiko')
44
26
pycurl = tests.ModuleAvailableFeature('pycurl')
45
 
pywintypes = tests.ModuleAvailableFeature('pywintypes')
46
 
sphinx = tests.ModuleAvailableFeature('sphinx')
47
27
subunit = tests.ModuleAvailableFeature('subunit')
48
28
 
49
29
 
50
 
class _BackslashDirSeparatorFeature(tests.Feature):
51
 
 
52
 
    def _probe(self):
53
 
        try:
54
 
            os.lstat(os.getcwd() + '\\')
55
 
        except OSError:
56
 
            return False
57
 
        else:
58
 
            return True
59
 
 
60
 
    def feature_name(self):
61
 
        return "Filesystem treats '\\' as a directory separator."
62
 
 
63
 
backslashdir_feature = _BackslashDirSeparatorFeature()
64
 
 
65
 
 
66
30
class _PosixPermissionsFeature(tests.Feature):
67
31
 
68
32
    def _probe(self):
97
61
 
98
62
chown_feature = _ChownFeature()
99
63
 
100
 
 
101
 
class ExecutableFeature(tests.Feature):
102
 
    """Feature testing whether an executable of a given name is on the PATH."""
103
 
 
104
 
    def __init__(self, name):
105
 
        super(ExecutableFeature, self).__init__()
106
 
        self.name = name
107
 
        self._path = None
108
 
 
109
 
    @property
110
 
    def path(self):
111
 
        # This is a property, so accessing path ensures _probe was called
112
 
        self.available()
113
 
        return self._path
114
 
 
115
 
    def _probe(self):
116
 
        path = os.environ.get('PATH')
117
 
        if path is None:
118
 
            return False
119
 
        for d in path.split(os.pathsep):
120
 
            if d:
121
 
                f = os.path.join(d, self.name)
122
 
                if os.access(f, os.X_OK):
123
 
                    self._path = f
124
 
                    return True
125
 
        return False
126
 
 
127
 
    def feature_name(self):
128
 
        return '%s executable' % self.name
129
 
 
130
 
 
131
 
bash_feature = ExecutableFeature('bash')
132
 
sed_feature = ExecutableFeature('sed')
133
 
diff_feature = ExecutableFeature('diff')