mcstrans: convert test scripts to Python 3

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2018-12-15 19:14:54 +01:00 committed by Petr Lautrbach
parent 5013d2ba97
commit 0ec2ed57c3
2 changed files with 9 additions and 10 deletions

View File

@ -20,17 +20,17 @@ for arg in sys.argv[1:]:
context, expected = line.split("=")
rc, raw = selinux_trans_to_raw_context(context)
if rc < 0:
print "Unable to get raw context of '%s'" % (context)
print("Unable to get raw context of '%s'" % (context))
errors += 1
continue
rc, colors = selinux_raw_context_to_color(raw)
if rc < 0:
print "Unable to get colors for '%s'" % (context)
print("Unable to get colors for '%s'" % (context))
errors += 1
continue
colors = colors.rstrip()
if colors != expected:
print "For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected)
print("For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected))
errors += 1
continue
f.close()
@ -38,6 +38,6 @@ for arg in sys.argv[1:]:
s = "s"
if errors == 1:
s = ""
print "mlscolor-test done with %d error%s" % (errors, s)
print("mlscolor-test done with %d error%s" % (errors, s))
sys.exit(errors)

View File

@ -10,22 +10,22 @@ def untrans(trans, val):
global errors, verbose
(rc, raw) = selinux_trans_to_raw_context(trans)
if raw != val:
print "untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val)
print("untrans: '%s' -> '%s' != '%s' FAILED" % (trans, raw, val))
errors += 1
else:
if verbose:
print "untrans: %s -> %s != %s SUCCESS" % (trans, raw, val)
print("untrans: %s -> %s != %s SUCCESS" % (trans, raw, val))
def trans(raw, val):
global errors, verbose
(rc, trans) = selinux_raw_to_trans_context(raw)
if trans != val:
print "trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val)
print("trans: '%s' -> '%s' != '%s' FAILED" % (raw, trans, val))
errors += 1
else:
if verbose:
print "trans: %s -> %s != %s SUCCESS" % (raw, trans, val)
print("trans: %s -> %s != %s SUCCESS" % (raw, trans, val))
if len(sys.argv) > 1 and sys.argv[1] == "-v":
verbose = 1
@ -38,7 +38,6 @@ for arg in sys.argv[1:]:
if not line.strip():
continue
line = line.rstrip('\n')
# print line
if (line.find("==") != -1):
t, r = line.split("==")
untrans("a:b:c:" + t, "a:b:c:" + r)
@ -51,6 +50,6 @@ for arg in sys.argv[1:]:
s = "s"
if errors == 1:
s = ""
print "mlstrans-test done with %d error%s" % (errors, s)
print("mlstrans-test done with %d error%s" % (errors, s))
sys.exit(errors)