Skip to content

Commit

Permalink
Review comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
thefunny42 committed Oct 18, 2018
1 parent 1d97d8d commit 9a06529
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/zope/i18nmessageid/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ def __new__(cls, ustr, domain=None, default=None, mapping=None,
msgid_plural=None, default_plural=None, number=None):
self = six.text_type.__new__(cls, ustr)
if isinstance(ustr, self.__class__):
domain = ustr.domain and ustr.domain[:] or domain
default = ustr.default and ustr.default[:] or default
mapping = ustr.mapping and ustr.mapping.copy() or mapping
domain = domain if ustr.domain is None else ustr.domain[:]
default = default if ustr.default is None else ustr.default[:]
mapping = mapping if ustr.mapping is None else ustr.mapping.copy()
msgid_plural = (
ustr.msgid_plural and ustr.msgid_plural[:] or msgid_plural)
msgid_plural if ustr.msgid_plural is None else
ustr.msgid_plural[:])
default_plural = (
ustr.default_plural and ustr.default_plural[:]
or default_plural)
number = ustr.number is not None and ustr.number or number
default_plural if ustr.default_plural is None else
ustr.default_plural[:])
number = number if ustr.number is None else ustr.number
ustr = six.text_type(ustr)

self.domain = domain
Expand All @@ -55,7 +56,6 @@ def __new__(cls, ustr, domain=None, default=None, mapping=None,

if number is not None and not isinstance(
number, six.integer_types + (float,)):
# Number must be an integer
raise TypeError('`number` should be an integer or a float')

self.number = number
Expand Down
15 changes: 15 additions & 0 deletions src/zope/i18nmessageid/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ def test_values_with_float_for_number(self):
if self._TEST_READONLY:
self.assertTrue(message._readonly)

def test_values_with_zero(self):
mapping = {'key': 'value'}
message = self._makeOne(
'testing', 'domain', 'default', mapping,
msgid_plural='testings', default_plural="defaults", number=0)
self.assertEqual(message, 'testing')
self.assertEqual(message.domain, 'domain')
self.assertEqual(message.default, 'default')
self.assertEqual(message.mapping, mapping)
self.assertEqual(message.msgid_plural, 'testings')
self.assertEqual(message.default_plural, 'defaults')
self.assertEqual(message.number, 0)
if self._TEST_READONLY:
self.assertTrue(message._readonly)

def test_copy(self):
mapping = {'key': 'value'}
source = self._makeOne(
Expand Down

0 comments on commit 9a06529

Please sign in to comment.