mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
selftest.run: Factor out expand_command_run.
This commit is contained in:
parent
d6924f8039
commit
f3f6b8eafa
@ -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)
|
||||
|
@ -26,7 +26,6 @@ import signal
|
||||
import shutil
|
||||
import subprocess
|
||||
import subunit
|
||||
import tempfile
|
||||
import traceback
|
||||
import warnings
|
||||
|
||||
@ -42,6 +41,7 @@ from selftest import (
|
||||
from selftest.run import (
|
||||
expand_environment_strings,
|
||||
expand_command_list,
|
||||
expand_command_run,
|
||||
)
|
||||
from selftest.target import (
|
||||
EnvironmentManager,
|
||||
@ -606,24 +606,14 @@ else:
|
||||
"unable to set up environment %s: %s" % (envname, e))
|
||||
continue
|
||||
|
||||
# Generate a file with the individual tests to run, if the
|
||||
# test runner for this test suite supports it.
|
||||
if subtests is not None:
|
||||
if supports_loadfile:
|
||||
(fd, listid_file) = tempfile.mkstemp()
|
||||
# FIXME: Remove tempfile afterwards
|
||||
f = os.fdopen(fd)
|
||||
try:
|
||||
for test in subtests:
|
||||
f.write(test+"\n")
|
||||
finally:
|
||||
f.close()
|
||||
cmd = cmd.replace("$LOADLIST", "--load-list=%s" % listid_file)
|
||||
elif supports_idlist:
|
||||
cmd += " ".join(subtests)
|
||||
cmd, tmpf = expand_command_run(cmd, supports_loadfile, supports_idlist,
|
||||
subtests)
|
||||
|
||||
run_testsuite(envname, name, cmd)
|
||||
|
||||
if tmpf is not None:
|
||||
os.remove(tmpf)
|
||||
|
||||
if opts.resetup_environment:
|
||||
env_manager.teardown_env(envname)
|
||||
|
||||
|
@ -19,9 +19,12 @@
|
||||
|
||||
"""Tests for selftest.run."""
|
||||
|
||||
import os
|
||||
|
||||
from selftest.run import (
|
||||
expand_command_list,
|
||||
expand_environment_strings,
|
||||
expand_command_run,
|
||||
)
|
||||
|
||||
from selftest.tests import TestCase
|
||||
@ -48,3 +51,29 @@ class ExpandCommandListTests(TestCase):
|
||||
|
||||
def test_list(self):
|
||||
self.assertEquals("test --list", expand_command_list("test $LISTOPT"))
|
||||
|
||||
|
||||
class ExpandCommandRunTests(TestCase):
|
||||
|
||||
def test_idlist(self):
|
||||
self.assertEquals(("test foo bar", None),
|
||||
expand_command_run("test", False, True, subtests=["foo", "bar"]))
|
||||
|
||||
def test_idlist_all(self):
|
||||
self.assertEquals(("test", None),
|
||||
expand_command_run("test", False, True))
|
||||
|
||||
def test_loadlist(self):
|
||||
(cmd, tmpf) = expand_command_run("test $LOADLIST", True, False,
|
||||
subtests=["foo", "bar"])
|
||||
self.addCleanup(os.remove, tmpf)
|
||||
f = open(tmpf, 'r')
|
||||
try:
|
||||
self.assertEquals(f.read(), "foo\nbar\n")
|
||||
finally:
|
||||
f.close()
|
||||
self.assertEquals("test --load-list=%s" % tmpf, cmd)
|
||||
|
||||
def test_loadlist_all(self):
|
||||
self.assertEquals(("test ", None),
|
||||
expand_command_run("test $LOADLIST", True, False))
|
||||
|
Loading…
Reference in New Issue
Block a user