summaryrefslogtreecommitdiff
path: root/selftest/run.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-03-05 03:39:57 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-03-05 03:39:57 +0100
commitf3f6b8eafa07b8d9e815e023adb8825ce89ef8da (patch)
tree10650e539e9a5840cda105f51069a68b70b415ac /selftest/run.py
parentd6924f803904d25a7f9cac2ec69f421d7a5bdeab (diff)
downloadsamba-f3f6b8eafa07b8d9e815e023adb8825ce89ef8da.tar.gz
samba-f3f6b8eafa07b8d9e815e023adb8825ce89ef8da.tar.bz2
samba-f3f6b8eafa07b8d9e815e023adb8825ce89ef8da.zip
selftest.run: Factor out expand_command_run.
Diffstat (limited to 'selftest/run.py')
-rw-r--r--selftest/run.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/selftest/run.py b/selftest/run.py
index c40dd7e389..25f3e5d7c9 100644
--- a/selftest/run.py
+++ b/selftest/run.py
@@ -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 subprocess
+import os
+import tempfile
import warnings
# expand strings from %ENV
@@ -31,3 +32,39 @@ def expand_command_list(cmd):
if not "$LISTOPT" in cmd:
return None
return cmd.replace("$LISTOPT", "--list")
+
+
+def expand_command_run(cmd, supports_loadfile, supports_idlist, subtests=None):
+ """Expand a test command.
+
+ :param cmd: Command to expand
+ :param supports_loadfile: Whether command supports loadfile
+ :param supports_idlist: Whether the command supports running specific
+ subtests
+ :param subtests: List of subtests to run - None for all subtests
+ :return: Tuple with command to run and temporary file to remove after
+ running (or None)
+ """
+ # Generate a file with the individual tests to run, if the
+ # test runner for this test suite supports it.
+ if subtests is None:
+ return (cmd.replace("$LOADLIST", ""), None)
+ if supports_loadfile:
+ (fd, listid_file) = tempfile.mkstemp()
+ f = os.fdopen(fd, 'w')
+ try:
+ for test in subtests:
+ f.write(test+"\n")
+ finally:
+ f.close()
+ return (
+ cmd.replace("$LOADLIST", "--load-list=%s" % listid_file),
+ listid_file)
+ elif supports_idlist:
+ cmd += " " + " ".join(subtests)
+ return (cmd, None)
+ else:
+ warnings.warn(
+ "Running subtests requested, but command does not support "
+ "this.")
+ return (cmd, None)