/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-06-19 12:45:11 UTC
  • mto: This revision was merged to the branch mainline in revision 5987.
  • Revision ID: jelmer@samba.org-20110619124511-x679jcuj1d0naeb6
fix test.

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')
 
53
testtools = tests.ModuleAvailableFeature('testtools')
 
54
 
 
55
 
 
56
class _BackslashDirSeparatorFeature(tests.Feature):
 
57
 
 
58
    def _probe(self):
 
59
        try:
 
60
            os.lstat(os.getcwd() + '\\')
 
61
        except OSError:
 
62
            return False
 
63
        else:
 
64
            return True
 
65
 
 
66
    def feature_name(self):
 
67
        return "Filesystem treats '\\' as a directory separator."
 
68
 
 
69
backslashdir_feature = _BackslashDirSeparatorFeature()
28
70
 
29
71
 
30
72
class _PosixPermissionsFeature(tests.Feature):
61
103
 
62
104
chown_feature = _ChownFeature()
63
105
 
 
106
 
 
107
class ExecutableFeature(tests.Feature):
 
108
    """Feature testing whether an executable of a given name is on the PATH."""
 
109
 
 
110
    def __init__(self, name):
 
111
        super(ExecutableFeature, self).__init__()
 
112
        self.name = name
 
113
        self._path = None
 
114
 
 
115
    @property
 
116
    def path(self):
 
117
        # This is a property, so accessing path ensures _probe was called
 
118
        self.available()
 
119
        return self._path
 
120
 
 
121
    def _probe(self):
 
122
        self._path = osutils.find_executable_on_path(self.name)
 
123
        return self._path is not None
 
124
 
 
125
    def feature_name(self):
 
126
        return '%s executable' % self.name
 
127
 
 
128
 
 
129
bash_feature = ExecutableFeature('bash')
 
130
sed_feature = ExecutableFeature('sed')
 
131
diff_feature = ExecutableFeature('diff')
 
132
 
 
133
 
 
134
class Win32Feature(tests.Feature):
 
135
    """Feature testing whether we're running selftest on Windows
 
136
    or Windows-like platform.
 
137
    """
 
138
 
 
139
    def _probe(self):
 
140
        return sys.platform == 'win32'
 
141
 
 
142
    def feature_name(self):
 
143
        return "win32 platform"
 
144
 
 
145
win32_feature = Win32Feature()