diff options
author | Mats Wichmann <mats@linux.com> | 2018-07-31 22:57:26 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2018-07-31 22:57:26 (GMT) |
commit | 0cf044543fb089bcd997b3ad2d877b71026ce5bf (patch) | |
tree | 758b4878d18514a4797af6480984428aaa74e2b1 /testing/framework | |
parent | d15065cdcfccf8943fa3ede7b225b698f3aec707 (diff) | |
download | SCons-0cf044543fb089bcd997b3ad2d877b71026ce5bf.zip SCons-0cf044543fb089bcd997b3ad2d877b71026ce5bf.tar.gz SCons-0cf044543fb089bcd997b3ad2d877b71026ce5bf.tar.bz2 |
Try a more scons-y file conversion for Py3 file reads
Instead of custom conversion as in the previous iteration,
use the to_bytes function.
The two known tests which incorrectly let the text-mode xml file
be opened in binary mode are adjusted to supply mode='r'
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'testing/framework')
-rw-r--r-- | testing/framework/TestCommon.py | 24 |
1 files changed, 16 insertions, 8 deletions
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): |