Skip to content

Commit

Permalink
fix tests for py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jun 15, 2018
1 parent 9d52c0a commit bf84944
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 21 deletions.
14 changes: 8 additions & 6 deletions plone/app/i18n/locales/browser/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class LanguageSelector(BrowserView):
>>> ls.available()
True
>>> ls.languages()
[{'code': 'en', 'selected': True}, {'code': 'ar', 'selected': False},
{'code': 'nl', 'selected': False}]
>>> result = [{'code': 'en', 'selected': True}, {'code': 'ar', 'selected': False},
... {'code': 'nl', 'selected': False}]
>>> ls.languages() == result
True
>>> ls.showFlags()
True
Expand All @@ -67,10 +69,10 @@ class LanguageSelector(BrowserView):
>>> ls.available()
True
>>> from zope.interface import implements
>>> from zope.interface import implementer
>>> from OFS.interfaces import IItem
>>> class Dummy(object):
... implements(IItem)
>>> @implementer(IItem)
... class Dummy(object):
... def getPortalObject(self):
... return self
... def absolute_url(self):
Expand Down
23 changes: 17 additions & 6 deletions plone/app/i18n/locales/browser/tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
# -*- coding: UTF-8 -*-
from zope.component.testing import setUp, tearDown

import doctest
import re
import six
import unittest

from zope.component.testing import setUp, tearDown
import doctest

class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub("u'(.*?)'", "'\\1'", got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite('plone.app.i18n.locales.browser.selector',
setUp=setUp(),
tearDown=tearDown,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE),
doctest.DocTestSuite(
'plone.app.i18n.locales.browser.selector',
setUp=setUp(),
tearDown=tearDown,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
checker=Py23DocChecker(),
)
))
4 changes: 2 additions & 2 deletions plone/app/i18n/locales/tests/countries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Country tests.

>>> de = countries[u'de']
>>> de[u'name']
u'Germany'
'Germany'

>>> de[u'flag']
u'/++resource++country-flags/de.gif'
'/++resource++country-flags/de.gif'

>>> old = util.getAvailableCountries()
>>> countries = ['de']
Expand Down
2 changes: 1 addition & 1 deletion plone/app/i18n/locales/tests/languages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Language tests
>>> old = util.getAvailableLanguages()
>>> util.setAvailableLanguages((u'en', u'de'))
>>> util.getAvailableLanguages()
[u'en', u'de']
['en', 'de']

>>> util.setAvailableLanguages(old)

Expand Down
22 changes: 16 additions & 6 deletions plone/app/i18n/locales/tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
# -*- coding: UTF-8 -*-
from plone.app.testing import PLONE_INTEGRATION_TESTING
from plone.testing import layered

import unittest
import doctest

from plone.app.testing.bbb import PTC_FUNCTIONAL_TESTING
from plone.testing import layered
import re
import six
import unittest

OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE |
doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE)


class Py23DocChecker(doctest.OutputChecker):
def check_output(self, want, got, optionflags):
if six.PY2:
got = re.sub("u'(.*?)'", "'\\1'", got)
return doctest.OutputChecker.check_output(self, want, got, optionflags)


def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite('plone.app.i18n.locales.countries'),
doctest.DocTestSuite('plone.app.i18n.locales.languages'),
layered(doctest.DocFileSuite('countries.txt',
optionflags=OPTIONFLAGS,
package='plone.app.i18n.locales.tests',
), layer=PTC_FUNCTIONAL_TESTING),
checker=Py23DocChecker(),
), layer=PLONE_INTEGRATION_TESTING),
layered(doctest.DocFileSuite('languages.txt',
optionflags=OPTIONFLAGS,
package='plone.app.i18n.locales.tests',
), layer=PTC_FUNCTIONAL_TESTING)
checker=Py23DocChecker(),
), layer=PLONE_INTEGRATION_TESTING)
))

0 comments on commit bf84944

Please sign in to comment.