Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError comparing bytes #136

Closed
1 task done
carldunham opened this issue Apr 14, 2017 · 2 comments
Closed
1 task done

UnicodeDecodeError comparing bytes #136

carldunham opened this issue Apr 14, 2017 · 2 comments

Comments

@carldunham
Copy link

Issue Type

Please specify the type of the issue you want to submit:

  • Bug Report

Versions & Configuration

Please specify the following things:

  • version of sure: 1.4.5
  • implementation and version of python:
Python 2.7.13 (default, Mar 17 2017, 16:37:30)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
  • operating system: osx 10.11.6

Steps to reproduce (Expected and Actual Results)

Please specify the steps to reproduce your issue including the expected and the actual results.

% cat test_sure_bytes.py
import base64

from unittest import TestCase
import sure  # noqa


class TestBytesCompare(TestCase):

    def setUp(self):
        data_b64 = (
            'MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg11zwkcKSsSppm8Du13'
            'je6lmwR7hEVeKMw5L8NQEN/CehRANCAAT9RzcGN/S9yN7mWP+xfLGEuw/TyHRBiW4c'
            'GE6AczRgske/P8eq8trs8unSJPCp0YPKrmCEcuotL/8BHQ4Y1AVK'
        )
        self.data = base64.b64decode(data_b64)

    def tearDown(self):
        pass

    def test_bytes_compare(self):
        self.data.should.equal(self.data)

% nosetests test_sure_bytes.py
E
======================================================================
ERROR: test_bytes_compare (test_sure_bytes.TestBytesCompare)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/private/tmp/sure-test/test_sure_bytes.py", line 22, in test_bytes_compare
    self.data.should.equal(self.data)
  File "/Users/cdunham/.pyenv/versions/2.7.13/envs/sure-test-2.7.13/lib/python2.7/site-packages/sure/__init__.py", line 384, in wrapper
    value = func(self, *args, **kw)
  File "/Users/cdunham/.pyenv/versions/2.7.13/envs/sure-test-2.7.13/lib/python2.7/site-packages/sure/__init__.py", line 650, in equal
    comparison = DeepComparison(self.obj, what, epsilon).compare()
  File "/Users/cdunham/.pyenv/versions/2.7.13/envs/sure-test-2.7.13/lib/python2.7/site-packages/sure/core.py", line 238, in compare
    safe_X, safe_Y = safe_format_repr(X), safe_format_repr(Y)
  File "/Users/cdunham/.pyenv/versions/2.7.13/envs/sure-test-2.7.13/lib/python2.7/site-packages/sure/core.py", line 232, in safe_format_repr
    safe_repr = string.replace('{', '{{').replace('}', '}}')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x81 in position 1: ordinal not in range(128)

----------------------------------------------------------------------
Ran 1 test in 0.002s

FAILED (errors=1)
@timofurrer
Copy link
Collaborator

Thanks for the report!

Unfortunately, I am on vacations until thursday and can not provide a fix.
Maybe @gabrielfalcao can have a look at it?
Or I can review a PR ...

@timofurrer
Copy link
Collaborator

I've finally found time to fix this issue. See #137

I'll release v1.4.6 in a few 🎉

timofurrer added a commit that referenced this issue May 7, 2017
Fix safe representation in exception messages for bytes and unicode objects. Closes #136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants