From d15065cdcfccf8943fa3ede7b225b698f3aec707 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 25 Jul 2018 16:46:25 -0600 Subject: 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 --- src/CHANGES.txt | 5 +++-- testing/framework/TestCommon.py | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index c875f1f..cc8e5c6 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -103,8 +103,9 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - update wiki links to new github location - update bug links to new github location - convert TestCmd.read to use with statement on open (quiets 17 py3 warnings) - - quiet warning in UtilTests.py - - fix tests specifying octal constants for Py3 + - quiet py3 warning in UtilTests.py + - fix tests specifying octal constants for py3 + - fix must_contain tests for py3 From Hao Wu - typo in customized decider example in user guide 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): -- cgit v0.12