~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

  • Committer: Andrew Bennetts
  • Date: 2010-06-27 05:25:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5322.
  • Revision ID: andrew.bennetts@canonical.com-20100627052503-rat7ch559a215swk
Implement __sizeof__ in StaticTuple.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
21
 
24
26
apport = tests.ModuleAvailableFeature('apport')
25
27
paramiko = tests.ModuleAvailableFeature('paramiko')
26
28
pycurl = tests.ModuleAvailableFeature('pycurl')
 
29
pywintypes = tests.ModuleAvailableFeature('pywintypes')
27
30
subunit = tests.ModuleAvailableFeature('subunit')
28
31
 
29
32
 
 
33
class _BackslashDirSeparatorFeature(tests.Feature):
 
34
 
 
35
    def _probe(self):
 
36
        try:
 
37
            os.lstat(os.getcwd() + '\\')
 
38
        except OSError:
 
39
            return False
 
40
        else:
 
41
            return True
 
42
 
 
43
    def feature_name(self):
 
44
        return "Filesystem treats '\\' as a directory separator."
 
45
 
 
46
backslashdir_feature = _BackslashDirSeparatorFeature()
 
47
 
 
48
 
30
49
class _PosixPermissionsFeature(tests.Feature):
31
50
 
32
51
    def _probe(self):
61
80
 
62
81
chown_feature = _ChownFeature()
63
82
 
 
83
 
 
84
class ExecutableFeature(tests.Feature):
 
85
    """Feature testing whether an executable of a given name is on the PATH."""
 
86
 
 
87
    def __init__(self, name):
 
88
        super(ExecutableFeature, self).__init__()
 
89
        self.name = name
 
90
        self._path = None
 
91
 
 
92
    @property
 
93
    def path(self):
 
94
        # This is a property, so accessing path ensures _probe was called
 
95
        self.available()
 
96
        return self._path
 
97
 
 
98
    def _probe(self):
 
99
        path = os.environ.get('PATH')
 
100
        if path is None:
 
101
            return False
 
102
        for d in path.split(os.pathsep):
 
103
            if d:
 
104
                f = os.path.join(d, self.name)
 
105
                if os.access(f, os.X_OK):
 
106
                    self._path = f
 
107
                    return True
 
108
        return False
 
109
 
 
110
    def feature_name(self):
 
111
        return '%s executable' % self.name
 
112
 
 
113
 
 
114
bash_feature = ExecutableFeature('bash')
 
115
sed_feature = ExecutableFeature('sed')