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
17
"""A collection of commonly used 'Features' which bzrlib uses to skip tests."""
22
from bzrlib import tests
23
from bzrlib.symbol_versioning import deprecated_in
26
class _NotRunningAsRoot(tests.Feature):
31
except AttributeError:
32
# If there is no uid, chances are there is no root either
36
def feature_name(self):
37
return 'Not running as root'
40
not_running_as_root = _NotRunningAsRoot()
41
apport = tests.ModuleAvailableFeature('apport')
42
paramiko = tests.ModuleAvailableFeature('paramiko')
43
pycurl = tests.ModuleAvailableFeature('pycurl')
44
pywintypes = tests.ModuleAvailableFeature('pywintypes')
45
subunit = tests.ModuleAvailableFeature('subunit')
46
sphinx = tests.ModuleAvailableFeature('sphinx')
49
class _BackslashDirSeparatorFeature(tests.Feature):
53
os.lstat(os.getcwd() + '\\')
18
from bzrlib.tests import Feature
21
class _ApportFeature(Feature):
26
except ImportError, e:
59
31
def feature_name(self):
60
return "Filesystem treats '\\' as a directory separator."
62
backslashdir_feature = _BackslashDirSeparatorFeature()
65
class _PosixPermissionsFeature(tests.Feature):
69
# create temporary file and check if specified perms are maintained.
72
write_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
73
f = tempfile.mkstemp(prefix='bzr_perms_chk_')
76
os.chmod(name, write_perms)
78
read_perms = os.stat(name).st_mode & 0777
80
return (write_perms == read_perms)
82
return (os.name == 'posix') and has_perms()
84
def feature_name(self):
85
return 'POSIX permissions support'
88
posix_permissions_feature = _PosixPermissionsFeature()
91
class _ChownFeature(tests.Feature):
92
"""os.chown is supported"""
95
return os.name == 'posix' and hasattr(os, 'chown')
97
chown_feature = _ChownFeature()
100
class ExecutableFeature(tests.Feature):
101
"""Feature testing whether an executable of a given name is on the PATH."""
103
def __init__(self, name):
104
super(ExecutableFeature, self).__init__()
110
# This is a property, so accessing path ensures _probe was called
115
path = os.environ.get('PATH')
118
for d in path.split(os.pathsep):
120
f = os.path.join(d, self.name)
121
if os.access(f, os.X_OK):
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')
35
ApportFeature = _ApportFeature()