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."""
28
class _NotRunningAsRoot(tests.Feature):
33
except AttributeError:
34
# If there is no uid, chances are there is no root either
38
def feature_name(self):
39
return 'Not running as root'
42
not_running_as_root = _NotRunningAsRoot()
44
apport = tests.ModuleAvailableFeature('apport')
45
meliae = tests.ModuleAvailableFeature('meliae')
46
paramiko = tests.ModuleAvailableFeature('paramiko')
47
pycurl = tests.ModuleAvailableFeature('pycurl')
48
pywintypes = tests.ModuleAvailableFeature('pywintypes')
49
sphinx = tests.ModuleAvailableFeature('sphinx')
50
subunit = tests.ModuleAvailableFeature('subunit')
53
class _BackslashDirSeparatorFeature(tests.Feature):
57
os.lstat(os.getcwd() + '\\')
63
def feature_name(self):
64
return "Filesystem treats '\\' as a directory separator."
66
backslashdir_feature = _BackslashDirSeparatorFeature()
69
class _PosixPermissionsFeature(tests.Feature):
73
# create temporary file and check if specified perms are maintained.
76
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
77
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
80
os.chmod(name, write_perms)
82
read_perms = os.stat(name).st_mode & 0777
84
return (write_perms == read_perms)
86
return (os.name == 'posix') and has_perms()
88
def feature_name(self):
89
return 'POSIX permissions support'
92
posix_permissions_feature = _PosixPermissionsFeature()
95
class _ChownFeature(tests.Feature):
96
"""os.chown is supported"""
99
return os.name == 'posix' and hasattr(os, 'chown')
101
chown_feature = _ChownFeature()
104
class ExecutableFeature(tests.Feature):
105
"""Feature testing whether an executable of a given name is on the PATH."""
107
def __init__(self, name):
108
super(ExecutableFeature, self).__init__()
114
# This is a property, so accessing path ensures _probe was called
119
self._path = osutils.find_executable_on_path(self.name)
120
return self._path is not None
122
def feature_name(self):
123
return '%s executable' % self.name
126
bash_feature = ExecutableFeature('bash')
127
sed_feature = ExecutableFeature('sed')
128
diff_feature = ExecutableFeature('diff')