summaryrefslogtreecommitdiff
path: root/QMTest
diff options
context:
space:
mode:
authorRussel Winder <russel@winder.org.uk>2016-01-19 17:30:41 +0000
committerRussel Winder <russel@winder.org.uk>2016-01-19 17:30:41 +0000
commit6f1a00e0e368ce59e2a8b6b4a088e48f463fe94e (patch)
treee3da370799409e61468868397770eeba5a5fe4bf /QMTest
parentfbae6623da1b88e402b62ceb71606734a9c9c314 (diff)
parent9815eb77cc93998db8e4ca28a9028bc19ddbd742 (diff)
downloadscons-6f1a00e0e368ce59e2a8b6b4a088e48f463fe94e.tar.gz
Merge in default.
Diffstat (limited to 'QMTest')
-rw-r--r--QMTest/SConscript4
-rw-r--r--QMTest/TestCmd.py36
-rw-r--r--QMTest/TestCmdTests.py213
-rw-r--r--QMTest/TestCommon.py76
-rw-r--r--QMTest/TestSCons.py58
-rw-r--r--QMTest/TestSConsMSVS.py2
-rw-r--r--QMTest/TestSCons_time.py4
-rw-r--r--QMTest/TestSConsign.py3
-rw-r--r--QMTest/scons_tdb.py16
9 files changed, 214 insertions, 198 deletions
diff --git a/QMTest/SConscript b/QMTest/SConscript
index 33fe9030..5469d298 100644
--- a/QMTest/SConscript
+++ b/QMTest/SConscript
@@ -44,12 +44,12 @@ files = [
def copy(target, source, env):
t = str(target[0])
s = str(source[0])
- c = open(s, 'rb').read()
+ c = open(s, 'r').read()
# Note: We construct the __ VERSION __ substitution string at
# run-time so it doesn't get replaced when this file gets copied
# into the tree for packaging.
c = c.replace('__' + 'VERSION' + '__', env['VERSION'])
- open(t, 'wb').write(c)
+ open(t, 'w').write(c)
for file in files:
# Guarantee that real copies of these files always exist in
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py
index cd559b75..d6457315 100644
--- a/QMTest/TestCmd.py
+++ b/QMTest/TestCmd.py
@@ -285,7 +285,9 @@ version.
# PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS,
# AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-from __future__ import division
+from __future__ import division, print_function
+
+from SCons.compat.six import PY3
__author__ = "Steven Knight <knight at baldmt dot com>"
__revision__ = "TestCmd.py 1.3.D001 2010/06/03 12:58:27 knight"
@@ -477,17 +479,17 @@ def match_re(lines = None, res = None):
if not is_List(res):
res = res.split("\n")
if len(lines) != len(res):
- print "match_re: expected %d lines, found %d"%(len(res), len(lines))
+ print("match_re: expected %d lines, found %d"%(len(res), len(lines)))
return
for i in range(len(lines)):
s = "^" + res[i] + "$"
try:
expr = re.compile(s)
- except re.error, e:
+ except re.error as e:
msg = "Regular expression error in %s: %s"
raise re.error(msg % (repr(s), e.args[0]))
if not expr.search(lines[i]):
- print "match_re: mismatch at line %d:\n search re='%s'\n line='%s'"%(i,s,lines[i])
+ print("match_re: mismatch at line %d:\n search re='%s'\n line='%s'"%(i,s,lines[i]))
return
return 1
@@ -501,7 +503,7 @@ def match_re_dotall(lines = None, res = None):
s = "^" + res + "$"
try:
expr = re.compile(s, re.DOTALL)
- except re.error, e:
+ except re.error as e:
msg = "Regular expression error in %s: %s"
raise re.error(msg % (repr(s), e.args[0]))
return expr.match(lines)
@@ -551,7 +553,7 @@ def diff_re(a, b, fromfile='', tofile='',
s = "^" + aline + "$"
try:
expr = re.compile(s)
- except re.error, e:
+ except re.error as e:
msg = "Regular expression error in %s: %s"
raise re.error(msg % (repr(s), e.args[0]))
if not expr.search(bline):
@@ -627,7 +629,7 @@ else:
st = os.stat(f)
except OSError:
continue
- if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
+ if stat.S_IMODE(st[stat.ST_MODE]) & 0o111:
return f
return None
@@ -730,7 +732,7 @@ class Popen(subprocess.Popen):
(errCode, written) = WriteFile(x, input)
except ValueError:
return self._close('stdin')
- except (subprocess.pywintypes.error, Exception), why:
+ except (subprocess.pywintypes.error, Exception) as why:
if why.args[0] in (109, errno.ESHUTDOWN):
return self._close('stdin')
raise
@@ -751,7 +753,7 @@ class Popen(subprocess.Popen):
(errCode, read) = ReadFile(x, nAvail, None)
except ValueError:
return self._close(which)
- except (subprocess.pywintypes.error, Exception), why:
+ except (subprocess.pywintypes.error, Exception) as why:
if why.args[0] in (109, errno.ESHUTDOWN):
return self._close(which)
raise
@@ -770,7 +772,7 @@ class Popen(subprocess.Popen):
try:
written = os.write(self.stdin.fileno(), input)
- except OSError, why:
+ except OSError as why:
if why.args[0] == errno.EPIPE: #broken pipe
return self._close('stdin')
raise
@@ -964,7 +966,7 @@ class TestCmd(object):
condition = self.condition
if self._preserve[condition]:
for dir in self._dirlist:
- print unicode("Preserved directory " + dir + "\n"),
+ print("Preserved directory " + dir + "\n")
else:
list = self._dirlist[:]
list.reverse()
@@ -1030,10 +1032,10 @@ class TestCmd(object):
if diff_function is None:
diff_function = self.simple_diff
if name is not None:
- print self.banner(name)
+ print(self.banner(name))
args = (a.splitlines(), b.splitlines()) + args
for line in diff_function(*args, **kw):
- print line
+ print(line)
def diff_stderr(self, a, b, *args, **kw):
"""Compare actual and expected file contents.
@@ -1659,12 +1661,12 @@ class TestCmd(object):
def do_chmod(fname):
try: st = os.stat(fname)
except OSError: pass
- else: os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]|0200))
+ else: os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]|0o200))
else:
def do_chmod(fname):
try: st = os.stat(fname)
except OSError: pass
- else: os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]&~0200))
+ else: os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]&~0o200))
if os.path.isfile(top):
do_chmod(top)
@@ -1719,7 +1721,7 @@ class TestCmd(object):
do_chmod(os.path.join(dirpath, name))
do_chmod(top)
- def write(self, file, content, mode = 'wb'):
+ def write(self, file, content, mode = 'w'):
"""Writes the specified content text (second argument) to the
specified file name (first argument). The file name may be
a list, in which case the elements are concatenated with the
@@ -1728,6 +1730,8 @@ class TestCmd(object):
exist. The I/O mode for the file may be specified; it must
begin with a 'w'. The default is 'wb' (binary write).
"""
+ if PY3:
+ content = re.sub(r'print (.+)', r'print(\1)', content)
file = self.canonicalize(file)
if mode[0] != 'w':
raise ValueError("mode must begin with 'w'")
diff --git a/QMTest/TestCmdTests.py b/QMTest/TestCmdTests.py
index 1044ed1e..a2e70229 100644
--- a/QMTest/TestCmdTests.py
+++ b/QMTest/TestCmdTests.py
@@ -19,6 +19,8 @@ AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
"""
+from SCons.compat.six import PY3
+
__author__ = "Steven Knight <knight at baldmt dot com>"
__revision__ = "TestCmdTests.py 1.3.D001 2010/06/03 12:58:27 knight"
@@ -26,13 +28,20 @@ import os
import shutil
import signal
import stat
-import StringIO
+if PY3:
+ from io import StringIO
+else:
+ from StringIO import StringIO
import sys
import tempfile
import time
import types
import unittest
-import UserList
+if PY3:
+ from collections import UserList
+else:
+ from UserList import UserList
+
# Strip the current directory so we get the right TestCmd.py module.
sys.path = sys.path[1:]
@@ -131,11 +140,11 @@ class TestCmdTestCase(unittest.TestCase):
run_env.write(t.scriptout_path, textout)
run_env.write(t.scripterr_path, texterr)
- os.chmod(t.script_path, 0644) # XXX UNIX-specific
- os.chmod(t.scriptx_path, 0755) # XXX UNIX-specific
- os.chmod(t.script1_path, 0644) # XXX UNIX-specific
- os.chmod(t.scriptout_path, 0644) # XXX UNIX-specific
- os.chmod(t.scripterr_path, 0644) # XXX UNIX-specific
+ os.chmod(t.script_path, 0o644) # XXX UNIX-specific
+ os.chmod(t.scriptx_path, 0o755) # XXX UNIX-specific
+ os.chmod(t.script1_path, 0o644) # XXX UNIX-specific
+ os.chmod(t.scriptout_path, 0o644) # XXX UNIX-specific
+ os.chmod(t.scripterr_path, 0o644) # XXX UNIX-specific
t.orig_cwd = os.getcwd()
@@ -220,8 +229,8 @@ class cleanup_TestCase(TestCmdTestCase):
test = TestCmd.TestCmd(workdir = '')
wdir = test.workdir
test.write('file2', "Test file #2\n")
- os.chmod(test.workpath('file2'), 0400)
- os.chmod(wdir, 0500)
+ os.chmod(test.workpath('file2'), 0o400)
+ os.chmod(wdir, 0o500)
test.cleanup()
assert not os.path.exists(wdir)
@@ -286,35 +295,35 @@ class chmod_TestCase(TestCmdTestCase):
test.chmod(['sub', 'file2'], stat.S_IWRITE)
file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE])
- assert file1_mode == 0444, '0%o' % file1_mode
+ assert file1_mode == 0o444, '0%o' % file1_mode
file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE])
- assert file2_mode == 0666, '0%o' % file2_mode
+ assert file2_mode == 0o666, '0%o' % file2_mode
test.chmod('file1', stat.S_IWRITE)
test.chmod(wdir_sub_file2, stat.S_IREAD)
file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE])
- assert file1_mode == 0666, '0%o' % file1_mode
+ assert file1_mode == 0o666, '0%o' % file1_mode
file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE])
- assert file2_mode == 0444, '0%o' % file2_mode
+ assert file2_mode == 0o444, '0%o' % file2_mode
else:
- test.chmod(wdir_file1, 0700)
- test.chmod(['sub', 'file2'], 0760)
+ test.chmod(wdir_file1, 0o700)
+ test.chmod(['sub', 'file2'], 0o760)
file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE])
- assert file1_mode == 0700, '0%o' % file1_mode
+ assert file1_mode == 0o700, '0%o' % file1_mode
file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE])
- assert file2_mode == 0760, '0%o' % file2_mode
+ assert file2_mode == 0o760, '0%o' % file2_mode
- test.chmod('file1', 0765)
- test.chmod(wdir_sub_file2, 0567)
+ test.chmod('file1', 0o765)
+ test.chmod(wdir_sub_file2, 0o567)
file1_mode = stat.S_IMODE(os.stat(wdir_file1)[stat.ST_MODE])
- assert file1_mode == 0765, '0%o' % file1_mode
+ assert file1_mode == 0o765, '0%o' % file1_mode
file2_mode = stat.S_IMODE(os.stat(wdir_sub_file2)[stat.ST_MODE])
- assert file2_mode == 0567, '0%o' % file2_mode
+ assert file2_mode == 0o567, '0%o' % file2_mode
@@ -1032,14 +1041,14 @@ class match_exact_TestCase(TestCmdTestCase):
assert test.match_exact("abcde\n", "abcde\n")
assert not test.match_exact(["12345\n", "abcde\n"], ["1[0-9]*5\n", "a.*e\n"])
assert test.match_exact(["12345\n", "abcde\n"], ["12345\n", "abcde\n"])
- assert not test.match_exact(UserList.UserList(["12345\n", "abcde\n"]),
+ assert not test.match_exact(UserList(["12345\n", "abcde\n"]),
["1[0-9]*5\n", "a.*e\n"])
- assert test.match_exact(UserList.UserList(["12345\n", "abcde\n"]),
+ assert test.match_exact(UserList(["12345\n", "abcde\n"]),
["12345\n", "abcde\n"])
assert not test.match_exact(["12345\n", "abcde\n"],
- UserList.UserList(["1[0-9]*5\n", "a.*e\n"]))
+ UserList(["1[0-9]*5\n", "a.*e\n"]))
assert test.match_exact(["12345\n", "abcde\n"],
- UserList.UserList(["12345\n", "abcde\n"]))
+ UserList(["12345\n", "abcde\n"]))
assert not test.match_exact("12345\nabcde\n", "1[0-9]*5\na.*e\n")
assert test.match_exact("12345\nabcde\n", "12345\nabcde\n")
lines = ["vwxyz\n", "67890\n"]
@@ -1098,28 +1107,28 @@ sys.exit(0)
["1.*j\n"])
assert test.match_re_dotall(["12345\n", "abcde\n", "fghij\n"],
["12345\n", "abcde\n", "fghij\n"])
- assert test.match_re_dotall(UserList.UserList(["12345\n",
- "abcde\n",
- "fghij\n"]),
+ assert test.match_re_dotall(UserList(["12345\n",
+ "abcde\n",
+ "fghij\n"]),
["1[0-9]*5\n", "a.*e\n", "f.*j\n"])
- assert test.match_re_dotall(UserList.UserList(["12345\n",
- "abcde\n",
- "fghij\n"]),
+ assert test.match_re_dotall(UserList(["12345\n",
+ "abcde\n",
+ "fghij\n"]),
["1.*j\n"])
- assert test.match_re_dotall(UserList.UserList(["12345\n",
- "abcde\n",
- "fghij\n"]),
+ assert test.match_re_dotall(UserList(["12345\n",
+ "abcde\n",
+ "fghij\n"]),
["12345\n", "abcde\n", "fghij\n"])
assert test.match_re_dotall(["12345\n", "abcde\n", "fghij\n"],
- UserList.UserList(["1[0-9]*5\n",
- "a.*e\n",
- "f.*j\n"]))
+ UserList(["1[0-9]*5\n",
+ "a.*e\n",
+ "f.*j\n"]))
assert test.match_re_dotall(["12345\n", "abcde\n", "fghij\n"],
- UserList.UserList(["1.*j\n"]))
+ UserList(["1.*j\n"]))
assert test.match_re_dotall(["12345\n", "abcde\n", "fghij\n"],
- UserList.UserList(["12345\n",
- "abcde\n",
- "fghij\n"]))
+ UserList(["12345\n",
+ "abcde\n",
+ "fghij\n"]))
assert test.match_re_dotall("12345\nabcde\nfghij\n",
"1[0-9]*5\na.*e\nf.*j\n")
assert test.match_re_dotall("12345\nabcde\nfghij\n", "1.*j\n")
@@ -1176,14 +1185,14 @@ sys.exit(0)
assert test.match_re("abcde\n", "abcde\n")
assert test.match_re(["12345\n", "abcde\n"], ["1[0-9]*5\n", "a.*e\n"])
assert test.match_re(["12345\n", "abcde\n"], ["12345\n", "abcde\n"])
- assert test.match_re(UserList.UserList(["12345\n", "abcde\n"]),
+ assert test.match_re(UserList(["12345\n", "abcde\n"]),
["1[0-9]*5\n", "a.*e\n"])
- assert test.match_re(UserList.UserList(["12345\n", "abcde\n"]),
+ assert test.match_re(UserList(["12345\n", "abcde\n"]),
["12345\n", "abcde\n"])
assert test.match_re(["12345\n", "abcde\n"],
- UserList.UserList(["1[0-9]*5\n", "a.*e\n"]))
+ UserList(["1[0-9]*5\n", "a.*e\n"]))
assert test.match_re(["12345\n", "abcde\n"],
- UserList.UserList(["12345\n", "abcde\n"]))
+ UserList(["12345\n", "abcde\n"]))
assert test.match_re("12345\nabcde\n", "1[0-9]*5\na.*e\n")
assert test.match_re("12345\nabcde\n", "12345\nabcde\n")
lines = ["vwxyz\n", "67890\n"]
@@ -1463,7 +1472,7 @@ class preserve_TestCase(TestCmdTestCase):
def test_preserve(self):
"""Test preserve()"""
def cleanup_test(test, cond=None, stdout=""):
- io = StringIO.StringIO()
+ io = StringIO()
save = sys.stdout
sys.stdout = io
try:
@@ -1603,7 +1612,7 @@ class read_TestCase(TestCmdTestCase):
_file_matches(wdir_foo_file3, test.read(['foo', 'file3']),
"Test\nfile\n#3.\n")
_file_matches(wdir_foo_file3,
- test.read(UserList.UserList(['foo', 'file3'])),
+ test.read(UserList(['foo', 'file3'])),
"Test\nfile\n#3.\n")
_file_matches(wdir_file4, test.read('file4', mode = 'r'),
"Test\nfile\n#4.\n")
@@ -1861,24 +1870,24 @@ class run_verbose_TestCase(TestCmdTestCase):
interpreter = 'python',
workdir = '',
verbose = 1)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
o = sys.stdout.getvalue()
assert o == '', o
e = sys.stderr.getvalue()
expect = 'python "%s" "arg1 arg2"\n' % t.script_path
assert expect == e, (expect, e)
-
+
testx = TestCmd.TestCmd(program = t.scriptx,
workdir = '',
verbose = 1)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
testx.run(arguments = ['arg1 arg2'])
expect = '"%s" "arg1 arg2"\n' % t.scriptx_path
o = sys.stdout.getvalue()
@@ -1912,10 +1921,10 @@ class run_verbose_TestCase(TestCmdTestCase):
interpreter = 'python',
workdir = '',
verbose = 2)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
line_fmt = "script: %s: %s: ['arg1 arg2']\n"
@@ -1929,14 +1938,14 @@ class run_verbose_TestCase(TestCmdTestCase):
expect = 'python "%s" "arg1 arg2"\n' % t.script_path
e = sys.stderr.getvalue()
assert e == expect, (e, expect)
-
+
testx = TestCmd.TestCmd(program = t.scriptx,
workdir = '',
verbose = 2)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
testx.run(arguments = ['arg1 arg2'])
line_fmt = "scriptx.bat: %s: %s: ['arg1 arg2']\n"
@@ -1957,10 +1966,10 @@ class run_verbose_TestCase(TestCmdTestCase):
interpreter = 'python',
workdir = '',
verbose = 2)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
line_fmt = "scriptout: %s: %s: ['arg1 arg2']\n"
@@ -1977,10 +1986,10 @@ class run_verbose_TestCase(TestCmdTestCase):
interpreter = 'python',
workdir = '',
verbose = 3)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
line_fmt = "scriptout: %s: %s: ['arg1 arg2']\n"
@@ -2001,10 +2010,10 @@ class run_verbose_TestCase(TestCmdTestCase):
test = TestCmd.TestCmd(program = t.script,
interpreter = 'python',
workdir = '')
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
line_fmt = "script: %s: %s: ['arg1 arg2']\n"
@@ -2018,13 +2027,13 @@ class run_verbose_TestCase(TestCmdTestCase):
expect = 'python "%s" "arg1 arg2"\n' % t.script_path
e = sys.stderr.getvalue()
assert e == expect, (e, expect)
-
+
testx = TestCmd.TestCmd(program = t.scriptx,
workdir = '')
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
testx.run(arguments = ['arg1 arg2'])
line_fmt = "scriptx.bat: %s: %s: ['arg1 arg2']\n"
@@ -2047,24 +2056,24 @@ class run_verbose_TestCase(TestCmdTestCase):
interpreter = 'python',
workdir = '',
verbose = 1)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
test.run(arguments = ['arg1 arg2'])
o = sys.stdout.getvalue()
assert o == '', o
e = sys.stderr.getvalue()
expect = 'python "%s" "arg1 arg2"\n' % t.script_path
assert expect == e, (expect, e)
-
+
testx = TestCmd.TestCmd(program = t.scriptx,
workdir = '',
verbose = 1)
-
- sys.stdout = StringIO.StringIO()
- sys.stderr = StringIO.StringIO()
-
+
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+
testx.run(arguments = ['arg1 arg2'])
expect = '"%s" "arg1 arg2"\n' % t.scriptx_path
o = sys.stdout.getvalue()
@@ -2347,7 +2356,7 @@ while 1:
logfp.close()
""" % t.recv_out_path
t.run_env.write(t.recv_script_path, text)
- os.chmod(t.recv_script_path, 0644) # XXX UNIX-specific
+ os.chmod(t.recv_script_path, 0o644) # XXX UNIX-specific
return t
def test_start(self):
@@ -2765,11 +2774,11 @@ class subdir_TestCase(TestCmdTestCase):
assert test.subdir('bar') == 1
assert test.subdir(['foo', 'succeed']) == 1
if os.name != "nt":
- os.chmod(test.workpath('foo'), 0500)
+ os.chmod(test.workpath('foo'), 0o500)
assert test.subdir(['foo', 'fail']) == 0
assert test.subdir(['sub', 'dir', 'ectory'], 'sub') == 1
assert test.subdir('one',
- UserList.UserList(['one', 'two']),
+ UserList(['one', 'two']),
['one', 'two', 'three']) == 3
assert os.path.isdir(test.workpath('foo'))
assert os.path.isdir(test.workpath('bar'))
@@ -2962,7 +2971,7 @@ class unlink_TestCase(TestCmdTestCase):
test.unlink(['foo', 'file3a'])
assert not os.path.exists(wdir_foo_file3a)
- test.unlink(UserList.UserList(['foo', 'file3b']))
+ test.unlink(UserList(['foo', 'file3b']))
assert not os.path.exists(wdir_foo_file3b)
test.unlink([test.workdir, 'foo', 'file4'])
@@ -2971,8 +2980,8 @@ class unlink_TestCase(TestCmdTestCase):
# Make it so we can't unlink file5.
# For UNIX, remove write permission from the dir and the file.
# For Windows, open the file.
- os.chmod(test.workdir, 0500)
- os.chmod(wdir_file5, 0400)
+ os.chmod(test.workdir, 0o500)
+ os.chmod(wdir_file5, 0o400)
f = open(wdir_file5, 'r')
try:
@@ -2983,8 +2992,8 @@ class unlink_TestCase(TestCmdTestCase):
except:
raise
finally:
- os.chmod(test.workdir, 0700)
- os.chmod(wdir_file5, 0600)
+ os.chmod(test.workdir, 0o700)
+ os.chmod(wdir_file5, 0o600)
f.close()
@@ -3208,11 +3217,11 @@ class executable_TestCase(TestCmdTestCase):
def make_executable(fname):
st = os.stat(fname)
- os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]|0100))
+ os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]|0o100))
def make_non_executable(fname):
st = os.stat(fname)
- os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]&~0100))
+ os.chmod(fname, stat.S_IMODE(st[stat.ST_MODE]&~0o100))
test.executable(test.workdir, 0)
# XXX skip these tests if euid == 0?
@@ -3282,7 +3291,7 @@ class write_TestCase(TestCmdTestCase):
test.write('file9', "Test file #9.\r\n", mode = 'wb')
if os.name != "nt":
- os.chmod(test.workdir, 0500)
+ os.chmod(test.workdir, 0o500)
try:
test.write('file10', "Test file #10 (should not get created).\n")
except IOError: # expect "Permission denied"
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index dc4c97c2..f878636a 100644
--- a/QMTest/TestCommon.py
+++ b/QMTest/TestCommon.py
@@ -93,6 +93,8 @@ The TestCommon module also provides the following variables
# AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
+from __future__ import print_function
+
__author__ = "Steven Knight <knight at baldmt dot com>"
__revision__ = "TestCommon.py 1.3.D001 2010/06/03 12:58:27 knight"
__version__ = "1.3"
@@ -258,9 +260,9 @@ class TestCommon(TestCmd):
existing, missing = separate_files(files)
unwritable = [x for x in existing if not is_writable(x)]
if missing:
- print "Missing files: `%s'" % "', `".join(missing)
+ print("Missing files: `%s'" % "', `".join(missing))
if unwritable:
- print "Unwritable files: `%s'" % "', `".join(unwritable)
+ print("Unwritable files: `%s'" % "', `".join(unwritable))
self.fail_test(missing + unwritable)
def must_contain(self, file, required, mode = 'rb', find = None):
@@ -275,11 +277,11 @@ class TestCommon(TestCmd):
return None
contains = find(file_contents, required)
if not contains:
- print "File `%s' does not contain required string." % file
- print self.banner('Required string ')
- print required
- print self.banner('%s contents ' % file)
- print file_contents
+ print("File `%s' does not contain required string." % file)
+ print(self.banner('Required string '))
+ print(required)
+ print(self.banner('%s contents ' % file))
+ print(file_contents)
self.fail_test(not contains)
def must_contain_all(self, output, input, title=None, find=None):
@@ -306,10 +308,10 @@ class TestCommon(TestCmd):
if find(output, input) is None:
if title is None:
title = 'output'
- print 'Missing expected input from %s:' % title
- print input
- print self.banner(title + ' ')
- print output
+ print('Missing expected input from {}:'.format(title))
+ print(input)
+ print(self.banner(title + ' '))
+ print(output)
self.fail_test()
def must_contain_all_lines(self, output, lines, title=None, find=None):
@@ -444,7 +446,7 @@ class TestCommon(TestCmd):
files = [is_List(x) and os.path.join(*x) or x for x in files]
missing = [x for x in files if not os.path.exists(x) and not os.path.islink(x) ]
if missing:
- print "Missing files: `%s'" % "', `".join(missing)
+ print("Missing files: `%s'" % "', `".join(missing))
self.fail_test(missing)
def must_exist_one_of(self, files):
@@ -464,7 +466,7 @@ class TestCommon(TestCmd):
if glob.glob(xpath):
return
missing.append(xpath)
- print "Missing one of: `%s'" % "', `".join(missing)
+ print("Missing one of: `%s'" % "', `".join(missing))
self.fail_test(missing)
def must_match(self, file, expect, mode = 'rb', match=None):
@@ -481,7 +483,7 @@ class TestCommon(TestCmd):
except KeyboardInterrupt:
raise
except:
- print "Unexpected contents of `%s'" % file
+ print("Unexpected contents of `%s'" % file)
self.diff(expect, file_contents, 'contents ')
raise
@@ -497,11 +499,11 @@ class TestCommon(TestCmd):
return None
contains = find(file_contents, banned)
if contains:
- print "File `%s' contains banned string." % file
- print self.banner('Banned string ')
- print banned
- print self.banner('%s contents ' % file)
- print file_contents
+ print("File `%s' contains banned string." % file)
+ print(self.banner('Banned string '))
+ print(banned)
+ print(self.banner('%s contents ' % file))
+ print(file_contents)
self.fail_test(contains)
def must_not_contain_any_line(self, output, lines, title=None, find=None):
@@ -548,7 +550,7 @@ class TestCommon(TestCmd):
files = [is_List(x) and os.path.join(*x) or x for x in files]
existing = [x for x in files if os.path.exists(x) or os.path.islink(x)]
if existing:
- print "Unexpected files exist: `%s'" % "', `".join(existing)
+ print("Unexpected files exist: `%s'" % "', `".join(existing))
self.fail_test(existing)
def must_not_exist_any_of(self, files):
@@ -568,7 +570,7 @@ class TestCommon(TestCmd):
if glob.glob(xpath):
existing.append(xpath)
if existing:
- print "Unexpected files exist: `%s'" % "', `".join(existing)
+ print("Unexpected files exist: `%s'" % "', `".join(existing))
self.fail_test(existing)
def must_not_be_writable(self, *files):
@@ -582,9 +584,9 @@ class TestCommon(TestCmd):
existing, missing = separate_files(files)
writable = list(filter(is_writable, existing))
if missing:
- print "Missing files: `%s'" % "', `".join(missing)
+ print("Missing files: `%s'" % "', `".join(missing))
if writable:
- print "Writable files: `%s'" % "', `".join(writable)
+ print("Writable files: `%s'" % "', `".join(writable))
self.fail_test(missing + writable)
def _complete(self, actual_stdout, expected_stdout,
@@ -597,23 +599,23 @@ class TestCommon(TestCmd):
expect = ''
if status != 0:
expect = " (expected %s)" % str(status)
- print "%s returned %s%s" % (self.program, _status(self), expect)
- print self.banner('STDOUT ')
- print actual_stdout
- print self.banner('STDERR ')
- print actual_stderr
+ print("%s returned %s%s" % (self.program, _status(self), expect))
+ print(self.banner('STDOUT '))
+ print(actual_stdout)
+ print(self.banner('STDERR '))
+ print(actual_stderr)
self.fail_test()
if (expected_stdout is not None
and not match(actual_stdout, expected_stdout)):
self.diff(expected_stdout, actual_stdout, 'STDOUT ')
if actual_stderr:
- print self.banner('STDERR ')
- print actual_stderr
+ print(self.banner('STDERR '))
+ print(actual_stderr)
self.fail_test()
if (expected_stderr is not None
and not match(actual_stderr, expected_stderr)):
- print self.banner('STDOUT ')
- print actual_stdout
+ print(self.banner('STDOUT '))
+ print(actual_stdout)
self.diff(expected_stderr, actual_stderr, 'STDERR ')
self.fail_test()
@@ -633,15 +635,15 @@ class TestCommon(TestCmd):
universal_newlines, **kw)
except KeyboardInterrupt:
raise
- except Exception, e:
- print self.banner('STDOUT ')
+ except Exception as e:
+ print(self.banner('STDOUT '))
try:
- print self.stdout()
+ print(self.stdout())
except IndexError:
pass
- print self.banner('STDERR ')
+ print(self.banner('STDERR '))
try:
- print self.stderr()
+ print(self.stderr())
except IndexError:
pass
cmd_args = self.command_args(program, interpreter, arguments)
diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py
index 43832e89..6820ae18 100644
--- a/QMTest/TestSCons.py
+++ b/QMTest/TestSCons.py
@@ -13,7 +13,7 @@ attributes defined in this subclass.
"""
# __COPYRIGHT__
-from __future__ import division
+from __future__ import division, print_function
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
@@ -355,7 +355,7 @@ class TestSCons(TestCommon):
# raised so as to not mask possibly serious disk or
# network issues.
continue
- if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
+ if stat.S_IMODE(st[stat.ST_MODE]) & 0o111:
return os.path.normpath(f)
else:
import SCons.Environment
@@ -502,9 +502,9 @@ class TestSCons(TestCommon):
self.pass_test()
else:
# test failed; have to do this by hand...
- print self.banner('STDOUT ')
- print self.stdout()
- print self.diff(warning, stderr, 'STDERR ')
+ print(self.banner('STDOUT '))
+ print(self.stdout())
+ print(self.diff(warning, stderr, 'STDERR '))
self.fail_test()
return warning
@@ -573,7 +573,7 @@ class TestSCons(TestCommon):
We stick the requested file name and line number in the right
places, abstracting out the version difference.
"""
- exec 'import traceback; x = traceback.format_stack()[-1]'
+ exec('import traceback; x = traceback.format_stack()[-1]')
x = x.lstrip()
x = x.replace('<string>', file)
x = x.replace('line 1,', 'line %s,' % line)
@@ -936,7 +936,7 @@ if ARGUMENTS.get('variant_dir', 0):
else:
builddir = 'build'
VariantDir(builddir, '.', duplicate=dup)
- print builddir, dup
+ print(builddir, dup)
sconscript = Dir(builddir).File('SConscript')
else:
sconscript = File('SConscript')
@@ -1021,7 +1021,7 @@ SConscript( sconscript )
raise NoMatch(lastEnd)
return m.end() + lastEnd
try:
- #print len(os.linesep)
+ #print(len(os.linesep))
ls = os.linesep
nols = "("
for i in range(len(ls)):
@@ -1095,27 +1095,27 @@ SConscript( sconscript )
if doCheckLog and lastEnd != len(logfile):
raise NoMatch(lastEnd)
- except NoMatch, m:
- print "Cannot match log file against log regexp."
- print "log file: "
- print "------------------------------------------------------"
- print logfile[m.pos:]
- print "------------------------------------------------------"
- print "log regexp: "
- print "------------------------------------------------------"
- print log
- print "------------------------------------------------------"
+ except NoMatch as m:
+ print("Cannot match log file against log regexp.")
+ print("log file: ")
+ print("------------------------------------------------------")
+ print(logfile[m.pos:])
+ print("------------------------------------------------------")
+ print("log regexp: ")
+ print("------------------------------------------------------")
+ print(log)
+ print("------------------------------------------------------")
self.fail_test()
if doCheckStdout:
exp_stdout = self.wrap_stdout(".*", rdstr)
if not self.match_re_dotall(self.stdout(), exp_stdout):
- print "Unexpected stdout: "
- print "-----------------------------------------------------"
- print repr(self.stdout())
- print "-----------------------------------------------------"
- print repr(exp_stdout)
- print "-----------------------------------------------------"
+ print("Unexpected stdout: ")
+ print("-----------------------------------------------------")
+ print(repr(self.stdout()))
+ print("-----------------------------------------------------")
+ print(repr(exp_stdout))
+ print("-----------------------------------------------------")
self.fail_test()
def get_python_version(self):
@@ -1149,12 +1149,12 @@ except AttributeError:
try:
import distutils.sysconfig
exec_prefix = distutils.sysconfig.EXEC_PREFIX
- print distutils.sysconfig.get_python_inc()
- print os.path.join(exec_prefix, 'libs')
+ print(distutils.sysconfig.get_python_inc())
+ print(os.path.join(exec_prefix, 'libs'))
except:
- print os.path.join(sys.prefix, 'include', py_ver)
- print os.path.join(sys.prefix, 'lib', py_ver, 'config')
-print py_ver
+ print(os.path.join(sys.prefix, 'include', py_ver)
+ print(os.path.join(sys.prefix, 'lib', py_ver, 'config'))
+print(py_ver)
""")
return [python] + self.stdout().strip().split('\n')
diff --git a/QMTest/TestSConsMSVS.py b/QMTest/TestSConsMSVS.py
index 65a09ebd..7459af0c 100644
--- a/QMTest/TestSConsMSVS.py
+++ b/QMTest/TestSConsMSVS.py
@@ -1149,7 +1149,7 @@ print "self._msvs_versions =", str(SCons.Tool.MSCommon.query_versions())
try:
host = _ARCH_TO_CANONICAL[host_platform]
- except KeyError, e:
+ except KeyError as e:
# Default to x86 for all other platforms
host = 'x86'
diff --git a/QMTest/TestSCons_time.py b/QMTest/TestSCons_time.py
index abe8ccf1..ba7fbd8d 100644
--- a/QMTest/TestSCons_time.py
+++ b/QMTest/TestSCons_time.py
@@ -225,7 +225,7 @@ class TestSCons_time(TestCommon):
def write_fake_aegis_py(self, name):
name = self.workpath(name)
self.write(name, aegis_py)
- os.chmod(name, 0755)
+ os.chmod(name, 0o755)
return name
def write_fake_scons_py(self):
@@ -235,7 +235,7 @@ class TestSCons_time(TestCommon):
def write_fake_svn_py(self, name):
name = self.workpath(name)
self.write(name, svn_py)
- os.chmod(name, 0755)
+ os.chmod(name, 0o755)
return name
def write_sample_directory(self, archive, dir, files):
diff --git a/QMTest/TestSConsign.py b/QMTest/TestSConsign.py
index 700c242c..a48b6484 100644
--- a/QMTest/TestSConsign.py
+++ b/QMTest/TestSConsign.py
@@ -1,4 +1,5 @@
# __COPYRIGHT__
+from __future__ import print_function
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
@@ -68,7 +69,7 @@ class TestSConsign(TestSCons):
elif os.path.exists(self.script_path('sconsign')):
sconsign = 'sconsign'
else:
- print "Can find neither 'sconsign.py' nor 'sconsign' scripts."
+ print("Can find neither 'sconsign.py' nor 'sconsign' scripts.")
self.no_result()
self.set_sconsign(sconsign)
diff --git a/QMTest/scons_tdb.py b/QMTest/scons_tdb.py
index 6be4696b..76c7fe10 100644
--- a/QMTest/scons_tdb.py
+++ b/QMTest/scons_tdb.py
@@ -20,7 +20,7 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-from __future__ import division
+from __future__ import division, print_function
"""
QMTest classes to support SCons' testing and Aegis-inspired workflow.
@@ -337,14 +337,14 @@ class AegisChangeStream(AegisStream):
# We'd like to use the _FormatStatistics() method to do
# this, but it's wrapped around the list in Result.outcomes,
# so it's simpler to just do it ourselves.
- print " %6d tests total\n" % self._num_tests
+ print(" %6d tests total\n" % self._num_tests)
for outcome in AegisTest.aegis_outcomes:
if self._outcome_counts[outcome] != 0:
- print " %6d (%3.0f%%) tests %s" % (
+ print(" %6d (%3.0f%%) tests %s" % (
self._outcome_counts[outcome],
self._percent(outcome),
outcome
- )
+ ))
class AegisBaselineStream(AegisStream):
def WriteResult(self, result):
@@ -368,19 +368,19 @@ class AegisBaselineStream(AegisStream):
# this, but it's wrapped around the list in Result.outcomes,
# so it's simpler to just do it ourselves.
if self._outcome_counts[AegisTest.FAIL]:
- print " %6d (%3.0f%%) tests as expected" % (
+ print(" %6d (%3.0f%%) tests as expected" % (
self._outcome_counts[AegisTest.FAIL],
self._percent(AegisTest.FAIL),
- )
+ ))
non_fail_outcomes = list(AegisTest.aegis_outcomes[:])
non_fail_outcomes.remove(AegisTest.FAIL)
for outcome in non_fail_outcomes:
if self._outcome_counts[outcome] != 0:
- print " %6d (%3.0f%%) tests unexpected %s" % (
+ print(" %6d (%3.0f%%) tests unexpected %s" % (
self._outcome_counts[outcome],
self._percent(outcome),
outcome,
- )
+ ))
class AegisBatchStream(FileResultStream):
def __init__(self, arguments):