summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/Docbook/basic/xinclude/xinclude.py2
-rw-r--r--test/Docbook/dependencies/xinclude/xinclude.py2
-rw-r--r--testing/framework/TestCommon.py24
3 files changed, 18 insertions, 10 deletions
diff --git a/test/Docbook/basic/xinclude/xinclude.py b/test/Docbook/basic/xinclude/xinclude.py
index 302c777..9b22c13 100644
--- a/test/Docbook/basic/xinclude/xinclude.py
+++ b/test/Docbook/basic/xinclude/xinclude.py
@@ -44,7 +44,7 @@ test.dir_fixture('image')
# Normal invocation
test.run()
test.must_exist(test.workpath('manual_xi.xml'))
-test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an included text.')
+test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an included text.', mode='r')
# Cleanup
diff --git a/test/Docbook/dependencies/xinclude/xinclude.py b/test/Docbook/dependencies/xinclude/xinclude.py
index 115163c..c3d9e25 100644
--- a/test/Docbook/dependencies/xinclude/xinclude.py
+++ b/test/Docbook/dependencies/xinclude/xinclude.py
@@ -44,7 +44,7 @@ test.dir_fixture('image')
# Normal invocation
test.run()
test.must_exist(test.workpath('manual_xi.xml'))
-test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an included text.')
+test.must_contain(test.workpath('manual_xi.xml'),'<para>This is an included text.', mode='r')
# Change included file
test.write('include.txt', 'This is another text.')
diff --git a/testing/framework/TestCommon.py b/testing/framework/TestCommon.py
index e551cce..e55b491 100644
--- a/testing/framework/TestCommon.py
+++ b/testing/framework/TestCommon.py
@@ -265,18 +265,26 @@ class TestCommon(TestCmd):
print("Unwritable files: `%s'" % "', `".join(unwritable))
self.fail_test(missing + unwritable)
- def must_contain(self, file, required, mode = 'rb', find = None):
- """Ensures that the specified file contains the required text.
+ def must_contain(self, file, required, mode='rb', find=None):
+ """Ensures specified file contains the required text.
+
+ Args:
+ file (string): name of file to search in.
+ required (string): text to search for. For the default
+ find function, type must match the return type from
+ reading the file; current implementation will convert.
+ mode (string): file open mode.
+ find (func): optional custom search routine. Must take the
+ form "find(output, line)" returning non-zero on success
+ and None on failure.
+
+ Calling test exits FAILED if search result is false
"""
if 'b' in mode:
# Python 3: reading a file in binary mode returns a
# bytes object. We cannot find the index of a different
- # (str) type in that, so encode "required". For Py2
- # it is all just strings, so it still works.
- try:
- required = required.encode()
- except AttributeError:
- pass # in case it's encoded already
+ # (str) type in that, so convert.
+ required = to_bytes(required)
file_contents = self.read(file, mode)
if find is None:
def find(o, l):