From 71c3528cbc563529735b2f768480dd67e4d8f614 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Tue, 6 Dec 2016 11:53:56 -0800 Subject: [PATCH] Fixes Py3.4 tests --- celery/utils/saferepr.py | 2 +- t/unit/utils/test_saferepr.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/celery/utils/saferepr.py b/celery/utils/saferepr.py index a7b84fc1709..5eea3745a37 100644 --- a/celery/utils/saferepr.py +++ b/celery/utils/saferepr.py @@ -125,7 +125,7 @@ def _repr_binary_bytes(val): ashex = val.hex except AttributeError: # pragma: no cover # Python 3.4 - return val.decode('utf-8', errors='backslashreplace') + return val.decode('utf-8', errors='replace') else: # Python 3.5+ return ashex() diff --git a/t/unit/utils/test_saferepr.py b/t/unit/utils/test_saferepr.py index 3e8b92b160d..e3b6a3914e1 100644 --- a/t/unit/utils/test_saferepr.py +++ b/t/unit/utils/test_saferepr.py @@ -208,11 +208,17 @@ def test_unicode_bytes__long(self): @skip.unless_python3() def test_binary_bytes(self): val = struct.pack('>QQQ', 12223, 1234, 3123) - assert '2fbf' in saferepr(val, maxlen=128) + if hasattr(bytes, 'hex'): # Python 3.5+ + assert '2fbf' in saferepr(val, maxlen=128) + else: # Python 3.4 + assert saferepr(val, maxlen=128) @skip.unless_python3() def test_binary_bytes__long(self): val = struct.pack('>QQQ', 12223, 1234, 3123) * 1024 result = saferepr(val, maxlen=128) - assert '2fbf' in result - assert result.endswith("...'") + if hasattr(bytes, 'hex'): # Python 3.5+ + assert '2fbf' in result + assert result.endswith("...'") + else: # Python 3.4 + assert result