1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

selftest: convert print func to be py2/py3 compatible

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
Noel Power 2018-03-09 14:03:29 +00:00 committed by Andrew Bartlett
parent bebdefeba9
commit 40e7d57999
2 changed files with 21 additions and 19 deletions

View File

@ -17,6 +17,7 @@
# by the name of the test, the environment it needs and the command to run, all # by the name of the test, the environment it needs and the command to run, all
# three separated by newlines. All other lines in the output are considered # three separated by newlines. All other lines in the output are considered
# comments. # comments.
from __future__ import print_function
import os import os
import subprocess import subprocess
@ -66,18 +67,18 @@ def plantestsuite(name, env, cmdline):
:param env: Environment to run the testsuite in :param env: Environment to run the testsuite in
:param cmdline: Command line to run :param cmdline: Command line to run
""" """
print "-- TEST --" print("-- TEST --")
if env == "none": if env == "none":
fullname = name fullname = name
else: else:
fullname = "%s(%s)" % (name, env) fullname = "%s(%s)" % (name, env)
print fullname print(fullname)
print env print(env)
if isinstance(cmdline, list): if isinstance(cmdline, list):
cmdline = " ".join(cmdline) cmdline = " ".join(cmdline)
if "$LISTOPT" in cmdline: if "$LISTOPT" in cmdline:
raise AssertionError("test %s supports --list, but not --load-list" % name) raise AssertionError("test %s supports --list, but not --load-list" % name)
print cmdline + " 2>&1 " + " | " + add_prefix(name, env) print(cmdline + " 2>&1 " + " | " + add_prefix(name, env))
def add_prefix(prefix, env, support_list=False): def add_prefix(prefix, env, support_list=False):
@ -89,13 +90,13 @@ def add_prefix(prefix, env, support_list=False):
def plantestsuite_loadlist(name, env, cmdline): def plantestsuite_loadlist(name, env, cmdline):
print "-- TEST-LOADLIST --" print("-- TEST-LOADLIST --")
if env == "none": if env == "none":
fullname = name fullname = name
else: else:
fullname = "%s(%s)" % (name, env) fullname = "%s(%s)" % (name, env)
print fullname print(fullname)
print env print(env)
if isinstance(cmdline, list): if isinstance(cmdline, list):
cmdline = " ".join(cmdline) cmdline = " ".join(cmdline)
support_list = ("$LISTOPT" in cmdline) support_list = ("$LISTOPT" in cmdline)
@ -103,8 +104,8 @@ def plantestsuite_loadlist(name, env, cmdline):
raise AssertionError("loadlist test %s does not support not --list" % name) raise AssertionError("loadlist test %s does not support not --list" % name)
if not "$LOADLIST" in cmdline: if not "$LOADLIST" in cmdline:
raise AssertionError("loadlist test %s does not support --load-list" % name) raise AssertionError("loadlist test %s does not support --load-list" % name)
print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list") print(("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list"))
print cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False) print(cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False))
def skiptestsuite(name, reason): def skiptestsuite(name, reason):
@ -114,7 +115,7 @@ def skiptestsuite(name, reason):
:param reason: Reason the test suite was skipped :param reason: Reason the test suite was skipped
""" """
# FIXME: Report this using subunit, but re-adjust the testsuite count somehow # FIXME: Report this using subunit, but re-adjust the testsuite count somehow
print >>sys.stderr, "skipping %s (%s)" % (name, reason) print("skipping %s (%s)" % (name, reason), file=sys.stderr)
def planperltestsuite(name, path): def planperltestsuite(name, path):

View File

@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
__all__ = ['parse_results'] __all__ = ['parse_results']
import datetime import datetime
@ -65,7 +66,7 @@ def parse_results(msg_ops, statistics, fh):
try: try:
dt = iso8601.parse_date(arg.rstrip("\n")) dt = iso8601.parse_date(arg.rstrip("\n"))
except TypeError as e: except TypeError as e:
print "Unable to parse time line: %s" % arg.rstrip("\n") print("Unable to parse time line: %s" % arg.rstrip("\n"))
else: else:
msg_ops.time(dt) msg_ops.time(dt)
elif command in VALID_RESULTS: elif command in VALID_RESULTS:
@ -600,7 +601,7 @@ class PlainFormatter(TestsuiteEnabledTestResult):
unexpected = False unexpected = False
if not name in self.test_output: if not name in self.test_output:
print "no output for name[%s]" % name print("no output for name[%s]" % name)
if result in ("success", "xfail"): if result in ("success", "xfail"):
self.suites_ok+=1 self.suites_ok+=1
@ -686,11 +687,11 @@ class PlainFormatter(TestsuiteEnabledTestResult):
if not self.immediate and not self.verbose: if not self.immediate and not self.verbose:
for suite in self.suitesfailed: for suite in self.suitesfailed:
print "=" * 78 print("=" * 78)
print "FAIL: %s" % suite print("FAIL: %s" % suite)
if suite in self.test_output: if suite in self.test_output:
print self.test_output[suite] print(self.test_output[suite])
print "" print("")
f.write("= Skipped tests =\n") f.write("= Skipped tests =\n")
for reason in self.skips.keys(): for reason in self.skips.keys():
@ -706,13 +707,13 @@ class PlainFormatter(TestsuiteEnabledTestResult):
not self.statistics['TESTS_ERROR']): not self.statistics['TESTS_ERROR']):
ok = (self.statistics['TESTS_EXPECTED_OK'] + ok = (self.statistics['TESTS_EXPECTED_OK'] +
self.statistics['TESTS_EXPECTED_FAIL']) self.statistics['TESTS_EXPECTED_FAIL'])
print "\nALL OK (%d tests in %d testsuites)" % (ok, self.suites_ok) print("\nALL OK (%d tests in %d testsuites)" % (ok, self.suites_ok))
else: else:
print "\nFAILED (%d failures, %d errors and %d unexpected successes in %d testsuites)" % ( print("\nFAILED (%d failures, %d errors and %d unexpected successes in %d testsuites)" % (
self.statistics['TESTS_UNEXPECTED_FAIL'], self.statistics['TESTS_UNEXPECTED_FAIL'],
self.statistics['TESTS_ERROR'], self.statistics['TESTS_ERROR'],
self.statistics['TESTS_UNEXPECTED_OK'], self.statistics['TESTS_UNEXPECTED_OK'],
len(self.suitesfailed)) len(self.suitesfailed)))
def skip_testsuite(self, name, reason="UNKNOWN"): def skip_testsuite(self, name, reason="UNKNOWN"):
self.skips.setdefault(reason, []).append(name) self.skips.setdefault(reason, []).append(name)