summaryrefslogtreecommitdiffstats
path: root/QMTest
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2009-02-06 14:55:23 (GMT)
committerSteven Knight <knight@baldmt.com>2009-02-06 14:55:23 (GMT)
commite112f6b49c9063e6a584ff4f7abf9d7a644eef30 (patch)
tree978573b4ff11f036428c0a08a89085313ad990fa /QMTest
parent9405dad6e18db3934eec7b992e12a2016b1466db (diff)
downloadSCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.zip
SCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.tar.gz
SCons-e112f6b49c9063e6a584ff4f7abf9d7a644eef30.tar.bz2
Commonize new string-search-in-output methods:
test.must_contain_all_lines() test.must_contain_any_line() test.must_not_contain_any_line() Update tests to use them. Remove "import string" lines where the change made them unnecessary.
Diffstat (limited to 'QMTest')
-rw-r--r--QMTest/TestCommon.py78
-rw-r--r--QMTest/TestSCons_time.py18
2 files changed, 58 insertions, 38 deletions
diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py
index fe1e680..845dfd2 100644
--- a/QMTest/TestCommon.py
+++ b/QMTest/TestCommon.py
@@ -36,7 +36,9 @@ provided by the TestCommon class:
test.must_contain('file', 'required text\n')
- test.must_contain_lines(lines, output)
+ test.must_contain_all_lines(output, lines, ['title', find])
+
+ test.must_contain_any_line(output, lines, ['title', find])
test.must_exist('file1', ['file2', ...])
@@ -44,7 +46,7 @@ provided by the TestCommon class:
test.must_not_be_writable('file1', ['file2', ...])
- test.must_not_contain_lines(lines, output)
+ test.must_not_contain_any_line(output, lines, ['title', find])
test.must_not_exist('file1', ['file2', ...])
@@ -307,19 +309,46 @@ class TestCommon(TestCmd):
print file_contents
self.fail_test(not contains)
- def must_contain_lines(self, lines, output, title=None):
- if title is None:
- title = 'output'
-
- missing = filter(lambda l, o=output: string.find(o, l) == -1, lines)
+ def must_contain_all_lines(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ missing = []
+ for line in lines:
+ if not find(output, line):
+ missing.append(line)
if missing:
- print "Missing lines from %s:" % title
- print string.join(missing, '\n')
- print "%s ============================================================" % title
- print output
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Missing expected lines from %s:\n" % title)
+ for line in missing:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
self.fail_test()
+ def must_contain_any_line(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ for line in lines:
+ if find(output, line):
+ return
+
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Missing any expected line from %s:\n" % title)
+ for line in lines:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
+ self.fail_test()
+
+ def must_contain_lines(self, lines, output, title=None):
+ # Deprecated; retain for backwards compatibility.
+ return self.must_contain_all_lines(output, lines, title)
+
def must_exist(self, *files):
"""Ensures that the specified file(s) must exist. An individual
file be specified as a list of directory names, in which case the
@@ -348,19 +377,28 @@ class TestCommon(TestCmd):
self.diff(expect, file_contents, 'contents ')
raise
- def must_not_contain_lines(self, lines, output=None, title=None):
- if title is None:
- title = 'output'
-
- unexpected = filter(lambda l, o=output: string.find(o, l) != -1, lines)
+ def must_not_contain_any_line(self, output, lines, title=None, find=None):
+ if find is None:
+ find = lambda o, l: string.find(o, l) != -1
+ unexpected = []
+ for line in lines:
+ if find(output, line):
+ unexpected.append(line)
if unexpected:
- print "Unexpected lines in %s:" % title
- print string.join(unexpected, '\n')
- print "%s ============================================================" % title
- print output
+ if title is None:
+ title = 'output'
+ sys.stdout.write("Unexpected lines in %s:\n" % title)
+ for line in unexpected:
+ sys.stdout.write(' ' + repr(line) + '\n')
+ separator = title + ' ' + '=' * (78 - len(title) - 1)
+ sys.stdout.write(separator + '\n')
+ sys.stdout.write(output)
self.fail_test()
+ def must_not_contain_lines(self, lines, output, title=None, find=None):
+ return self.must_not_contain_any_line(output, lines, title, find)
+
def must_not_exist(self, *files):
"""Ensures that the specified file(s) must not exist.
An individual file be specified as a list of directory names, in
diff --git a/QMTest/TestSCons_time.py b/QMTest/TestSCons_time.py
index f3ea49a..1fc9dea 100644
--- a/QMTest/TestSCons_time.py
+++ b/QMTest/TestSCons_time.py
@@ -213,24 +213,6 @@ class TestSCons_time(TestCommon):
else:
return os.path.splitext(path)
- def must_contain_all_lines(self, name, content, expected, exists=None):
- missing_lines = []
-
- if exists is None:
- exists = lambda e, c: string.find(c, e) != -1
-
- for e in expected:
- if not exists(e, content):
- missing_lines.append(e)
-
- if missing_lines:
- sys.stdout.write('%s is missing expected string(s):\n' % name)
- for m in missing_lines:
- sys.stdout.write(' ' + repr(m) + '\n')
- sys.stdout.write('%s content:\n' % name)
- sys.stdout.write(content)
- self.fail_test()
-
def fake_logfile(self, logfile_name, index=0):
self.write(self.workpath(logfile_name), logfile_contents % locals())