Skip to content

Commit

Permalink
Fix another repr unicode problem
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueporta committed Sep 29, 2018
1 parent f04c980 commit 90b9323
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

0.2.6 (2018-09-29)
------------------

- Another fix repr with unicode chars

0.2.5 (2018-09-29)
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Test
> PYTHONPATH=$PYTHONPATH:. mamba
.. |Version Number| image:: https://img.shields.io/badge/version-0.2.5-blue.svg
.. |Version Number| image:: https://img.shields.io/badge/version-0.2.6-blue.svg

.. |Build Status| image:: https://travis-ci.org/quiqueporta/simple-value-object.svg?branch=master
:target: https://travis-ci.org/quiqueporta/simple-value-object
Expand Down
2 changes: 1 addition & 1 deletion simple_value_object/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .value_object import ValueObject
from .decorators import invariant

VERSION = (0, 2, 5, 'final')
VERSION = (0, 2, 6, 'final')
__version__ = VERSION


Expand Down
11 changes: 10 additions & 1 deletion simple_value_object/value_object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import six
import sys
from inspect import getargspec
import inspect

Expand Down Expand Up @@ -94,11 +95,19 @@ def __repr__(self):
value = value.encode('utf-8')
if isinstance(value, six.string_types) or isinstance(value, six.binary_type):
value = value.decode('utf-8')
if isinstance(value,ValueObject):
if sys.version_info[0] < 3:
value = repr(value).decode('utf-8')
args_values.append(u"{}={}".format(arg, value))

kwargs = u", ".join(args_values)

return u"{}({})".format(self.__class__.__name__, kwargs)
result = u"{}({})".format(self.__class__.__name__, kwargs)

if sys.version_info[0] < 3:
return result.encode('utf-8')

return result

def __hash__(self):
return self.hash
Expand Down
14 changes: 7 additions & 7 deletions specs/value_object_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

def py23_str(value):
try: # Python 2
return unicode(value)
except NameError: # Python 3
return repr(value)
return value.decode('utf-8')
except AttributeError: # Python 3
return value


class Point(ValueObject):
Expand Down Expand Up @@ -84,9 +84,9 @@ def __init__(self, x, y=3):
a_value_object_with_defaults = MyPoint(6)
a_value_object_within_value_object = Money(100, Currency(u'€'))

expect(py23_str(a_value_object)).to(equal(u'Point(x=6, y=7)'))
expect(py23_str(a_value_object_with_defaults)).to(equal(u'MyPoint(x=6, y=3)'))
expect(py23_str(a_value_object_within_value_object)).to(equal(u'Money(amount=100, currency=Currency(symbol=€))'))
expect(py23_str(repr(a_value_object))).to(equal(u'Point(x=6, y=7)'))
expect(py23_str(repr(a_value_object_with_defaults))).to(equal(u'MyPoint(x=6, y=3)'))
expect(py23_str(repr(a_value_object_within_value_object))).to(equal(u'Money(amount=100, currency=Currency(symbol=€))'))

with it('provides a representation of unicode parameters'):
class MyValueObject(ValueObject):
Expand All @@ -95,7 +95,7 @@ def __init__(self, text):

a_value_object = MyValueObject(u"Melón")

expect(py23_str(a_value_object)).to(equal(u"MyValueObject(text=Melón)"))
expect(py23_str(repr(a_value_object))).to(equal(u"MyValueObject(text=Melón)"))

with context('restrictions'):
with context('on initialization'):
Expand Down

0 comments on commit 90b9323

Please sign in to comment.