selftest.run: Factor out expand_command_list.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 5 Mar 2012 02:27:40 +0000 (03:27 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 5 Mar 2012 02:27:40 +0000 (03:27 +0100)
selftest/run.py
selftest/selftest.py
selftest/tests/test_run.py

index 4ef10de14243373b7f1627fa52a4626db96882aa..c40dd7e389f2ba9fdc8c3deaf69a455a41fbf289 100644 (file)
@@ -15,7 +15,8 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import os
+import subprocess
+import warnings
 
 # expand strings from %ENV
 def expand_environment_strings(s, vars):
@@ -26,4 +27,7 @@ def expand_environment_strings(s, vars):
     return s
 
 
-
+def expand_command_list(cmd):
+    if not "$LISTOPT" in cmd:
+        return None
+    return cmd.replace("$LISTOPT", "--list")
index cbc24f13ce337b571a4cfd162a714a18e7148f2a..5c9bd7d13ce0d4c845229beda42f862dfec84417 100755 (executable)
@@ -39,7 +39,10 @@ from selftest import (
     subunithelper,
     testlist,
     )
-from selftest.run import expand_environment_strings
+from selftest.run import (
+    expand_environment_strings,
+    expand_command_list,
+    )
 from selftest.target import (
     EnvironmentManager,
     NoneTarget,
@@ -577,12 +580,11 @@ $envvarstr
     env_manager.teardown_env(testenv_name)
 elif opts.list:
     for (name, envname, cmd, supports_loadfile, supports_idlist, subtests) in todo:
-        if not "$LISTOPT" in cmd:
+        cmd = expand_command_list(cmd)
+        if cmd is None:
             warnings.warn("Unable to list tests in %s" % name)
             continue
 
-        cmd = cmd.replace("$LISTOPT", "--list")
-
         exitcode = subprocess.call(cmd, shell=True)
 
         if exitcode != 0:
index 040c1438959da497583d5511be24c2eb8c5cc2d1..f7a1dda436807771ad3a7096aa5b2231b86ed3d4 100644 (file)
 
 """Tests for selftest.run."""
 
-from selftest.run import expand_environment_strings
+from selftest.run import (
+    expand_command_list,
+    expand_environment_strings,
+    )
 
 from selftest.tests import TestCase
 
@@ -36,3 +39,12 @@ class ExpandEnvironmentStringsTests(TestCase):
     def test_unknown(self):
         self.assertEquals("foo $BLA",
             expand_environment_strings("foo $BLA", {}))
+
+
+class ExpandCommandListTests(TestCase):
+
+    def test_no_list(self):
+        self.assertIs(None, expand_command_list("test bla"))
+
+    def test_list(self):
+        self.assertEquals("test --list", expand_command_list("test $LISTOPT"))