diff options
author | Mats Wichmann <mats@linux.com> | 2018-07-25 22:46:25 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2018-07-25 22:56:39 (GMT) |
commit | d15065cdcfccf8943fa3ede7b225b698f3aec707 (patch) | |
tree | 3e9d3be2c829b85a7d5750ab0b0d2e25ac4df01b /testing | |
parent | 33d3eec950dc1ac17b8e3771bca48c1f68a7532b (diff) | |
download | SCons-d15065cdcfccf8943fa3ede7b225b698f3aec707.zip SCons-d15065cdcfccf8943fa3ede7b225b698f3aec707.tar.gz SCons-d15065cdcfccf8943fa3ede7b225b698f3aec707.tar.bz2 |
Testing: python 3 fix for must_contain
TestCommon defines a method must_contain which checks for a file including
a given string. With Python 3, the test runs into some typing problems.
This could be fixed either by changing all the tests which call the
routine either omitting the mode argument (which then defaults to 'rb'),
or specifying a mode which includes 'b'; or by modifying must_contain to
align the types of the file data and the data to check for. This patch
uses the latter approach.
This is a test-only change, no run-time scons code is modified.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/framework/TestCommon.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/testing/framework/TestCommon.py b/testing/framework/TestCommon.py index 47a149b..e551cce 100644 --- a/testing/framework/TestCommon.py +++ b/testing/framework/TestCommon.py @@ -268,6 +268,15 @@ class TestCommon(TestCmd): def must_contain(self, file, required, mode = 'rb', find = None): """Ensures that the specified file contains the required text. """ + 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 file_contents = self.read(file, mode) if find is None: def find(o, l): |