diff options
Diffstat (limited to 'QMTest')
-rw-r--r-- | QMTest/TestCmd.py | 19 | ||||
-rw-r--r-- | QMTest/TestCommon.py | 2 |
2 files changed, 19 insertions, 2 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index b0a456b..d7b8d94 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -328,12 +328,27 @@ __all__ = [ 'match_re_dotall', 'python', '_python_', - 'TestCmd' + 'TestCmd', + 'to_bytes', + 'to_str', ] def is_List(e): return isinstance(e, (list, UserList)) +def to_bytes (s): + if isinstance (s, bytes) or bytes is str: + return s + else: + return bytes (s, 'utf-8') + +def to_str (s): + if bytes is str: + return s + elif not is_String(s): + return str (s, 'utf-8') + return s + try: eval('unicode') except NameError: @@ -513,6 +528,8 @@ def simple_diff(a, b, fromfile='', tofile='', (diff -c) and difflib.unified_diff (diff -u) but which prints output like the simple, unadorned 'diff" command. """ + a = [to_str(q) for q in a] + b = [to_str(q) for q in b] sm = difflib.SequenceMatcher(None, a, b) def comma(x1, x2): return x1+1 == x2 and str(x2) or '%s,%s' % (x1+1, x2) diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index f878636..9093cc9 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -479,7 +479,7 @@ class TestCommon(TestCmd): if not match: match = self.match try: - self.fail_test(not match(file_contents, expect)) + self.fail_test(not match(to_str(file_contents), to_str(expect))) except KeyboardInterrupt: raise except: |