1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""A collection of commonly used 'Features' which bzrlib uses to skip tests."""
29
class _NotRunningAsRoot(tests.Feature):
34
except AttributeError:
35
# If there is no uid, chances are there is no root either
39
def feature_name(self):
40
return 'Not running as root'
43
not_running_as_root = _NotRunningAsRoot()
45
apport = tests.ModuleAvailableFeature('apport')
46
gpgme = tests.ModuleAvailableFeature('gpgme')
47
lzma = tests.ModuleAvailableFeature('lzma')
48
meliae = tests.ModuleAvailableFeature('meliae')
49
paramiko = tests.ModuleAvailableFeature('paramiko')
50
pycurl = tests.ModuleAvailableFeature('pycurl')
51
pywintypes = tests.ModuleAvailableFeature('pywintypes')
52
sphinx = tests.ModuleAvailableFeature('sphinx')
53
subunit = tests.ModuleAvailableFeature('subunit')
54
testtools = tests.ModuleAvailableFeature('testtools')
57
class _BackslashDirSeparatorFeature(tests.Feature):
61
os.lstat(os.getcwd() + '\\')
67
def feature_name(self):
68
return "Filesystem treats '\\' as a directory separator."
70
backslashdir_feature = _BackslashDirSeparatorFeature()
73
class _PosixPermissionsFeature(tests.Feature):
77
# create temporary file and check if specified perms are maintained.
80
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
81
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
84
os.chmod(name, write_perms)
86
read_perms = os.stat(name).st_mode & 0777
88
return (write_perms == read_perms)
90
return (os.name == 'posix') and has_perms()
92
def feature_name(self):
93
return 'POSIX permissions support'
96
posix_permissions_feature = _PosixPermissionsFeature()
99
class _ChownFeature(tests.Feature):
100
"""os.chown is supported"""
103
return os.name == 'posix' and hasattr(os, 'chown')
105
chown_feature = _ChownFeature()
108
class ExecutableFeature(tests.Feature):
109
"""Feature testing whether an executable of a given name is on the PATH."""
111
def __init__(self, name):
112
super(ExecutableFeature, self).__init__()
118
# This is a property, so accessing path ensures _probe was called
123
self._path = osutils.find_executable_on_path(self.name)
124
return self._path is not None
126
def feature_name(self):
127
return '%s executable' % self.name
130
bash_feature = ExecutableFeature('bash')
131
sed_feature = ExecutableFeature('sed')
132
diff_feature = ExecutableFeature('diff')
135
class Win32Feature(tests.Feature):
136
"""Feature testing whether we're running selftest on Windows
137
or Windows-like platform.
141
return sys.platform == 'win32'
143
def feature_name(self):
144
return "win32 platform"
146
win32_feature = Win32Feature()