~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/features.py

Merge cleanup into first-try

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
 
81
81
chown_feature = _ChownFeature()
82
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')