Rev 5255: (lifeless) Generalise probing for executables used in selftest. (Martin von in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue May 25 22:30:58 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5255 [merge]
revision-id: pqm at pqm.ubuntu.com-20100525213052-9rdn7ws6mo6corql
parent: pqm at pqm.ubuntu.com-20100524055053-98svu921jteiweaw
parent: martin.vgagern at gmx.net-20100525112016-p25dj7mdiw00hfqb
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-05-25 22:30:52 +0100
message:
  (lifeless) Generalise probing for executables used in selftest. (Martin von
   Gagern)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/plugins/bash_completion/tests/test_bashcomp.py test_bashcomp.py-20100429205005-o3im24mr5pdqog19-3
  bzrlib/tests/features.py       features.py-20090820042958-jglgza3wrn03ha9e-1
=== modified file 'NEWS'
--- a/NEWS	2010-05-21 07:17:13 +0000
+++ b/NEWS	2010-05-25 21:30:52 +0000
@@ -244,6 +244,10 @@
   failures on Lucid, FreeBSD and gentoo.  
   (Vincent Ladeuil, #528436)
 
+* New class ``ExecutableFeature`` for checking the availability of
+  executables on the ``PATH``. Migrated from bash_completion plugin.
+  (Martin von Gagern)
+
 bzr 2.2b2
 #########
 

=== modified file 'bzrlib/plugins/bash_completion/tests/test_bashcomp.py'
--- a/bzrlib/plugins/bash_completion/tests/test_bashcomp.py	2010-05-04 19:30:44 +0000
+++ b/bzrlib/plugins/bash_completion/tests/test_bashcomp.py	2010-05-25 11:20:16 +0000
@@ -22,35 +22,10 @@
 import subprocess
 
 
-class _BashFeature(tests.Feature):
-    """Feature testing whether a bash executable is available."""
-
-    bash_paths = ['/bin/bash', '/usr/bin/bash']
-
-    def __init__(self):
-        super(_BashFeature, self).__init__()
-        self.bash_path = None
-
-    def available(self):
-        if self.bash_path is not None:
-            return self.bash_path is not False
-        for path in self.bash_paths:
-            if os.access(path, os.X_OK):
-                self.bash_path = path
-                return True
-        self.bash_path = False
-        return False
-
-    def feature_name(self):
-        return 'bash'
-
-BashFeature = _BashFeature()
-
-
 class BashCompletionMixin(object):
     """Component for testing execution of a bash completion script."""
 
-    _test_needs_features = [BashFeature]
+    _test_needs_features = [tests.features.bash_feature]
 
     def complete(self, words, cword=-1):
         """Perform a bash completion.
@@ -60,7 +35,8 @@
         """
         if self.script is None:
             self.script = self.get_script()
-        proc = subprocess.Popen([BashFeature.bash_path, '--noprofile'],
+        proc = subprocess.Popen([tests.features.bash_feature.path,
+                                 '--noprofile'],
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
@@ -187,6 +163,7 @@
         return s.replace("$(bzr ", "$('%s' " % self.get_bzr_path())
 
     def test_revspec_tag_all(self):
+        self.requireFeature(tests.features.sed_feature)
         wt = self.make_branch_and_tree('.', format='dirstate-tags')
         wt.branch.tags.set_tag('tag1', 'null:')
         wt.branch.tags.set_tag('tag2', 'null:')
@@ -195,6 +172,7 @@
         self.assertCompletionEquals('tag1', 'tag2', '3tag')
 
     def test_revspec_tag_prefix(self):
+        self.requireFeature(tests.features.sed_feature)
         wt = self.make_branch_and_tree('.', format='dirstate-tags')
         wt.branch.tags.set_tag('tag1', 'null:')
         wt.branch.tags.set_tag('tag2', 'null:')

=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py	2010-05-21 06:14:50 +0000
+++ b/bzrlib/tests/features.py	2010-05-25 21:30:52 +0000
@@ -80,3 +80,36 @@
 
 chown_feature = _ChownFeature()
 
+
+class ExecutableFeature(tests.Feature):
+    """Feature testing whether an executable of a given name is on the PATH."""
+
+    def __init__(self, name):
+        super(ExecutableFeature, self).__init__()
+        self.name = name
+        self._path = None
+
+    @property
+    def path(self):
+        # This is a property, so accessing path ensures _probe was called
+        self.available()
+        return self._path
+
+    def _probe(self):
+        path = os.environ.get('PATH')
+        if path is None:
+            return False
+        for d in path.split(os.pathsep):
+            if d:
+                f = os.path.join(d, self.name)
+                if os.access(f, os.X_OK):
+                    self._path = f
+                    return True
+        return False
+
+    def feature_name(self):
+        return '%s executable' % self.name
+
+
+bash_feature = ExecutableFeature('bash')
+sed_feature = ExecutableFeature('sed')




More information about the bazaar-commits mailing list