Skip to content

Commit

Permalink
Merge pull request #1 from zopefoundation/python3
Browse files Browse the repository at this point in the history
Python 3 support
  • Loading branch information
mgedmin committed Mar 7, 2016
2 parents e9f225f + a34dc41 commit aeda590
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,8 @@ language: python
sudo: false
python:
- 2.7
- 3.4
- 3.5
install:
- pip install tox-travis
script:
Expand Down
4 changes: 3 additions & 1 deletion CHANGES.rst
Expand Up @@ -5,7 +5,9 @@ CHANGES
1.1.2 (unreleased)
------------------

- Nothing changed yet.
- Python 3 support

- Tests now run with `python setup.py test`


1.1.1 (2015-11-09)
Expand Down
13 changes: 10 additions & 3 deletions setup.py
Expand Up @@ -17,8 +17,10 @@
from setuptools import setup, find_packages

def read(*rnames):
return open(os.path.join(os.path.dirname(__file__),
*rnames)).read().decode('utf-8').encode('latin-1', 'ignore')
return open(os.path.join(os.path.dirname(__file__), *rnames), 'rb'
).read().decode('utf-8')

tests_require = ['z3c.form', 'zope.testing']

setup (
name='z3c.currency',
Expand Down Expand Up @@ -47,6 +49,9 @@ def read(*rnames):
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Natural Language :: English',
'Operating System :: OS Independent',
Expand All @@ -58,7 +63,7 @@ def read(*rnames):
package_dir = {'':'src'},
namespace_packages = ['z3c'],
extras_require = dict(
test = ['z3c.form', 'zope.testing'],
test = tests_require,
form = ['z3c.form'],
),
install_requires = [
Expand All @@ -68,5 +73,7 @@ def read(*rnames):
'zope.interface',
'zope.schema',
],
tests_require = tests_require,
zip_safe = False,
test_suite = 'z3c.currency.tests.test_suite',
)
8 changes: 4 additions & 4 deletions src/z3c/currency/README.rst
Expand Up @@ -40,22 +40,22 @@ formatting the numerical value to a string.

>>> price.unit
u'$'
>>> price.unit = u''
>>> price.unit = u'SEK'
>>> price.unit
u'\xe2\x82\xac'
u'SEK'

Of course, both of those attributes are available as constructor arguments:

>>> price = field.Currency(
... title=u'Price',
... description=u'The price of the item.',
... precision=interfaces.DOLLARS,
... unit=u'')
... unit=u'SEK')

>>> price.precision is interfaces.DOLLARS
True
>>> price.unit
u'\xe2\x82\xac'
u'SEK'

Let's now have a look at the validation. First of all, the value must always
be a decimal:
Expand Down
4 changes: 2 additions & 2 deletions src/z3c/currency/converter.py
Expand Up @@ -20,10 +20,10 @@
from z3c.currency import interfaces
from zope.i18n import format

@zope.component.adapter(interfaces.ICurrency, IWidget)
@zope.interface.implementer(IDataConverter)
class CurrencyConverter(object):
"""Converts currency fields to text representations."""
zope.component.adapts(interfaces.ICurrency, IWidget)
zope.interface.implements(IDataConverter)

inputPatterns = (
'#,##0;-#,##0', '#,##0.00;-#,##0.00', '#,##0.00###;-#,##0.00###')
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/currency/field.py
Expand Up @@ -20,8 +20,8 @@

from z3c.currency import interfaces

@zope.interface.implementer(interfaces.ICurrency)
class Currency(zope.schema.Orderable, zope.schema.Field):
zope.interface.implements(interfaces.ICurrency)

precision = FieldProperty(interfaces.ICurrency['precision'])
unit = FieldProperty(interfaces.ICurrency['unit'])
Expand Down
15 changes: 15 additions & 0 deletions src/z3c/currency/tests.py
Expand Up @@ -13,15 +13,30 @@
##############################################################################
"""Currency Test Setup
"""
import re
import unittest
import doctest

from zope.testing import renormalizing


checker = renormalizing.OutputChecker([
# Python 3 unicode removed the "u".
(re.compile("u('.*?')"),
r"\1"),
(re.compile('u(".*?")'),
r"\1"),
# Normalize the module name in exceptions:
(re.compile(r'z3c\.currency\.interfaces\.'), r'')
])


def test_suite():
return unittest.TestSuite([
doctest.DocFileSuite(
'README.rst',
optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS,
checker=checker,
),
])

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
@@ -1,6 +1,8 @@
[tox]
envlist =
py27
py34
py35

[testenv]
deps =
Expand Down

0 comments on commit aeda590

Please sign in to comment.