Skip to content

Commit

Permalink
Fixes Py3.4 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Dec 6, 2016
1 parent 10dec7b commit 71c3528
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion celery/utils/saferepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions t/unit/utils/test_saferepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 71c3528

Please sign in to comment.