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

Python3 testfixes #34

Merged
merged 9 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ New features:

Bug fixes:

- *add item here*
- fix test for python 3
[petschki]


3.1.3 (2018-06-21)
Expand Down
18 changes: 10 additions & 8 deletions Products/PortalTransforms/TransformEngine.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# -*- coding: utf-8 -*-
import six

from AccessControl import ClassSecurityInfo
from Acquisition import aq_base
from AccessControl.class_init import InitializeClass
from logging import DEBUG
from Acquisition import aq_base
from OFS.Folder import Folder
from Persistence import PersistentMapping
from persistent.list import PersistentList
from Products.CMFCore.ActionProviderBase import ActionProviderBase
from Products.CMFCore.permissions import ManagePortal
from Products.CMFCore.permissions import View
from Products.CMFCore.utils import UniqueObject
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.utils import registerToolInterface
from Products.CMFCore.utils import UniqueObject
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from Products.PortalTransforms.Transform import Transform
from Products.PortalTransforms.cache import Cache
from Products.PortalTransforms.chain import chain
from Products.PortalTransforms.chain import TransformsChain
from Products.PortalTransforms.chain import chain
from Products.PortalTransforms.data import datastream
from Products.PortalTransforms.interfaces import IDataStream
from Products.PortalTransforms.interfaces import IEngine
from Products.PortalTransforms.interfaces import IPortalTransformsTool
from Products.PortalTransforms.interfaces import ITransform
from Products.PortalTransforms.libtransforms.utils import MissingBinary
from Products.PortalTransforms.Transform import Transform
from Products.PortalTransforms.transforms import initialize
from Products.PortalTransforms.utils import TransformException
from Products.PortalTransforms.utils import _www
from Products.PortalTransforms.utils import log
from Products.PortalTransforms.utils import TransformException
from logging import DEBUG
from persistent.list import PersistentList
from zope.interface import implementer


Expand Down Expand Up @@ -391,7 +393,7 @@ def typesWithPathOfLength(length):
if outputs:
for reachedType, transforms in outputs.items():
# Does this lead to a type we never reached before ?
if reachedType not in pathToType.keys() and transforms:
if reachedType not in six.iterkeys(pathToType) and transforms: # noqa
# Yes, we did not know any path reaching this type
# Let's remember the path to here
pathToType[reachedType] = (
Expand Down
6 changes: 2 additions & 4 deletions Products/PortalTransforms/libtransforms/piltransform.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from Products.PortalTransforms.interfaces import ITransform
from zope.interface import implementer

import PIL.Image


from Products.PortalTransforms.interfaces import ITransform
from six import BytesIO
from zope.interface import implementer


@implementer(ITransform)
Expand Down
1 change: 0 additions & 1 deletion Products/PortalTransforms/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
22 changes: 22 additions & 0 deletions Products/PortalTransforms/tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import unittest

from Products.CMFPlone.utils import safe_unicode
from Products.PortalTransforms.testing import PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING # noqa


class TransformTestCase(unittest.TestCase):

layer = PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.transforms = self.portal.portal_transforms

def _baseAssertEqual(self, first, second, msg=None):
return unittest.TestCase._baseAssertEqual(
self, safe_unicode(first), safe_unicode(second), msg)

def assertMultiLineEqual(self, first, second, msg=None):
return unittest.TestCase.assertMultiLineEqual(
self, safe_unicode(first), safe_unicode(second), msg)
2 changes: 1 addition & 1 deletion Products/PortalTransforms/tests/output/demo1.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions Products/PortalTransforms/tests/test_engine.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import re

from Products.CMFPlone.utils import _createObjectByType
from Products.PortalTransforms.chain import chain
from Products.PortalTransforms.interfaces import ITransform
from Products.PortalTransforms.testing import PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING
from Products.PortalTransforms.tests.base import TransformTestCase
from Products.PortalTransforms.utils import TransformException
from six.moves import urllib
from zope.interface import implementer
import re
import unittest


class BaseTransform:
Expand Down Expand Up @@ -114,12 +114,10 @@ class BadTransformWildcardOutput(BaseTransform):
output = 'text/*'


class TestEngine(unittest.TestCase):

layer = PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING
class TestEngine(TransformTestCase):

def setUp(self):
self.portal = self.layer['portal']
super(TestEngine, self).setUp()
_createObjectByType('Folder', self.portal, id='folder')
self.folder = self.portal.folder
self.engine = self.portal.portal_transforms
Expand Down
34 changes: 14 additions & 20 deletions Products/PortalTransforms/tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
# -*- coding: utf-8 -*-
from Products.PortalTransforms.testing import PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING
from .utils import input_file_path
import unittest
from Products.PortalTransforms.tests.base import TransformTestCase
from Products.PortalTransforms.tests.utils import input_file_path

FILE_PATH = input_file_path("demo1.pdf")


class TestGraph(unittest.TestCase):

layer = PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.engine = self.portal.portal_transforms
class TestGraph(TransformTestCase):

def testGraph(self):
data = open(FILE_PATH, 'rb').read()
requirements = self.engine._policies.get('text/plain', [])
with open(FILE_PATH, 'rb') as fd:
data = fd.read()
requirements = self.transforms._policies.get('text/plain', [])
if requirements:
out = self.engine.convertTo('text/plain', data, filename=FILE_PATH)
out = self.transforms.convertTo('text/plain', data, filename=FILE_PATH)
self.assertTrue(out.getData())

def testFindPath(self):
originalMap = self.engine._mtmap
originalMap = self.transforms._mtmap
"""
The dummy map used for this test corresponds to a graph
depicted in ASCII art below :
Expand Down Expand Up @@ -78,7 +72,7 @@ def name(self):
'4-2': ['transform4-5', 'transform5-3', 'transform3-2'],
'5-3': ['transform5-3'],
}
self.engine._mtmap = dummyMap1
self.transforms._mtmap = dummyMap1
for orig in ['1', '2', '3', '4', '5', '6', '7']:
for target in ['1', '2', '3', '4', '5', '6', '7']:
# build the name of the path
Expand All @@ -88,24 +82,24 @@ def name(self):
# we do. Here is the expected shortest path
expectedPath = expectedPathes[pathName]
# what's the shortest path according to the engine ?
gotPath = self.engine._findPath(orig, target)
gotPath = self.transforms._findPath(orig, target)
# just keep the name of the transforms, please
if gotPath is not None:
gotPath = [transform.name() for transform in gotPath]
# this must be the same as in our expectation
self.assertEqual(expectedPath, gotPath)
self.engine._mtmap = originalMap
self.transforms._mtmap = originalMap

def testFindPathWithEmptyTransform(self):
""" _findPath should not throw "index out of range" when dealing with
empty transforms list
"""
dummyMap = {'1': {'2': []}}
self.engine._mtmap = dummyMap
self.engine._findPath('1', '2')
self.transforms._mtmap = dummyMap
self.transforms._findPath('1', '2')

def testIdentity(self):
orig = 'Some text'
converted = self.engine.convertTo(
converted = self.transforms.convertTo(
'text/plain', 'Some text', mimetype='text/plain')
self.assertEqual(orig, str(converted))
12 changes: 1 addition & 11 deletions Products/PortalTransforms/tests/test_intelligenttext.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# -*- coding: utf-8 -*-
from Products.PortalTransforms.testing import PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING
import unittest


class TransformTestCase(unittest.TestCase):

layer = PRODUCTS_PORTALTRANSFORMS_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.transforms = self.portal.portal_transforms
from Products.PortalTransforms.tests.base import TransformTestCase


class TestIntelligentTextToHtml(TransformTestCase):
Expand Down
Loading