~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

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