/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: 2010-12-06 14:01:44 UTC
  • mto: (5321.1.101 mergetools)
  • mto: This revision was merged to the branch mainline in revision 5632.
  • Revision ID: v.ladeuil+lp@free.fr-20101206140144-yz3cp2paek953gp4
More cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
from bzrlib import tests
 
22
from bzrlib import (
 
23
    osutils,
 
24
    tests,
 
25
    )
21
26
from bzrlib.symbol_versioning import deprecated_in
22
27
 
23
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()
 
44
 
24
45
apport = tests.ModuleAvailableFeature('apport')
 
46
meliae = tests.ModuleAvailableFeature('meliae')
25
47
paramiko = tests.ModuleAvailableFeature('paramiko')
26
48
pycurl = tests.ModuleAvailableFeature('pycurl')
 
49
pywintypes = tests.ModuleAvailableFeature('pywintypes')
 
50
sphinx = tests.ModuleAvailableFeature('sphinx')
27
51
subunit = tests.ModuleAvailableFeature('subunit')
28
52
 
29
53
 
 
54
class _BackslashDirSeparatorFeature(tests.Feature):
 
55
 
 
56
    def _probe(self):
 
57
        try:
 
58
            os.lstat(os.getcwd() + '\\')
 
59
        except OSError:
 
60
            return False
 
61
        else:
 
62
            return True
 
63
 
 
64
    def feature_name(self):
 
65
        return "Filesystem treats '\\' as a directory separator."
 
66
 
 
67
backslashdir_feature = _BackslashDirSeparatorFeature()
 
68
 
 
69
 
30
70
class _PosixPermissionsFeature(tests.Feature):
31
71
 
32
72
    def _probe(self):
61
101
 
62
102
chown_feature = _ChownFeature()
63
103
 
 
104
 
 
105
class ExecutableFeature(tests.Feature):
 
106
    """Feature testing whether an executable of a given name is on the PATH."""
 
107
 
 
108
    def __init__(self, name):
 
109
        super(ExecutableFeature, self).__init__()
 
110
        self.name = name
 
111
        self._path = None
 
112
 
 
113
    @property
 
114
    def path(self):
 
115
        # This is a property, so accessing path ensures _probe was called
 
116
        self.available()
 
117
        return self._path
 
118
 
 
119
    def _probe(self):
 
120
        self._path = osutils.find_executable_on_path(self.name)
 
121
        return self._path is not None
 
122
 
 
123
    def feature_name(self):
 
124
        return '%s executable' % self.name
 
125
 
 
126
 
 
127
bash_feature = ExecutableFeature('bash')
 
128
sed_feature = ExecutableFeature('sed')
 
129
diff_feature = ExecutableFeature('diff')