/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: Jelmer Vernooij
  • Date: 2011-01-19 19:54:46 UTC
  • mto: (5582.10.33 weave-fmt-plugin)
  • mto: This revision was merged to the branch mainline in revision 5625.
  • Revision ID: jelmer@samba.org-20110119195446-tdfskt08571vafma
RemoveĀ unusedĀ import.

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
21
 
20
22
from bzrlib import tests
21
 
from bzrlib.symbol_versioning import deprecated_in
22
 
 
 
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()
23
40
 
24
41
apport = tests.ModuleAvailableFeature('apport')
 
42
meliae = tests.ModuleAvailableFeature('meliae')
25
43
paramiko = tests.ModuleAvailableFeature('paramiko')
26
44
pycurl = tests.ModuleAvailableFeature('pycurl')
 
45
pywintypes = tests.ModuleAvailableFeature('pywintypes')
 
46
sphinx = tests.ModuleAvailableFeature('sphinx')
27
47
subunit = tests.ModuleAvailableFeature('subunit')
28
48
 
29
49
 
 
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
 
30
66
class _PosixPermissionsFeature(tests.Feature):
31
67
 
32
68
    def _probe(self):
61
97
 
62
98
chown_feature = _ChownFeature()
63
99
 
 
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')