Commit 0ef616f2 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Arnaud Fontaine

py2/py3: use BytesIO for bytes.

parent 22da6ba0
......@@ -28,7 +28,7 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.Localizer.itools.i18n.accept import AcceptLanguage
from PIL import Image
import cStringIO
from io import BytesIO
import math
import os.path
from lxml.html import fromstring, tostring
......@@ -120,8 +120,8 @@ class TestCorporateIdentityTemplateList(ERP5TypeTestCase):
# http://snipplr.com/view/757/compare-two-pil-images-in-python/
# http://effbot.org/zone/pil-comparing-images.htm
# http://effbot.org/imagingbook/image.htm
image1 = Image.open(cStringIO.StringIO(image_data_1))
image2 = Image.open(cStringIO.StringIO(image_data_2))
image1 = Image.open(BytesIO(image_data_1))
image2 = Image.open(BytesIO(image_data_2))
# image can be converted into greyscale without transparency
h1 = image1.histogram()
......
......@@ -28,7 +28,7 @@
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DateTime import DateTime
from PIL import Image
import cStringIO
from io import BytesIO
import math
import os.path
from Products.Localizer.itools.i18n.accept import AcceptLanguage
......@@ -57,8 +57,8 @@ class TestSimplifiedPayslipReport(ERP5TypeTestCase):
# http://snipplr.com/view/757/compare-two-pil-images-in-python/
# http://effbot.org/zone/pil-comparing-images.htm
# http://effbot.org/imagingbook/image.htm
image1 = Image.open(cStringIO.StringIO(image_data_1))
image2 = Image.open(cStringIO.StringIO(image_data_2))
image1 = Image.open(BytesIO(image_data_1))
image2 = Image.open(BytesIO(image_data_2))
# image can be converted into greyscale without transparency
h1 = image1.histogram()
......
......@@ -29,11 +29,12 @@
import os
import unittest
from six.moves import cStringIO as StringIO
from io import BytesIO
from zipfile import ZipFile
from Products.ERP5Type.tests.utils import FileUpload
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import DummyLocalizer
from Products.ERP5Type.Utils import bytes2str
from Products.ERP5OOo.tests.utils import Validator
from Products.ERP5OOo.OOoUtils import OOoBuilder
......@@ -126,7 +127,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
self.assertEqual(200, response.getStatus())
ooo_builder = OOoBuilder(response.getBody())
styles_xml_body = ooo_builder.extract('styles.xml')
styles_xml_body = bytes2str(ooo_builder.extract('styles.xml'))
self.assertTrue(len(styles_xml_body) > 0)
# 'Style sheet ja' text is in the odt document header,
# and the header is in the 'styles.xml'.
......@@ -139,7 +140,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
response = self.publish('/' + self.getPortal().Dynamic_viewAsOdt.absolute_url(1))
self._validate(response.getBody())
ooo_builder = OOoBuilder(response.getBody())
styles_xml_body = ooo_builder.extract('styles.xml')
styles_xml_body = bytes2str(ooo_builder.extract('styles.xml'))
self.assertTrue(styles_xml_body.find('Style sheet en') > 0)
# 3. test a fail case, reset a not existed stylesheet
......@@ -152,7 +153,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
self.getPortal().Localizer.changeLanguage('en')
response = self.publish('/' + self.getPortal().Dynamic_viewAsOdt.absolute_url(1))
# then, it is not a zip stream
self.assertFalse(response.getBody().startswith('PK'))
self.assertFalse(response.getBody().startswith(b'PK'))
self.assertEqual(500, response.getStatus())
......@@ -179,7 +180,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
response.getHeader('content-disposition'))
self._validate(response.getBody())
ooo_builder = OOoBuilder(response.getBody())
styles_xml_body = ooo_builder.extract('styles.xml')
styles_xml_body = bytes2str(ooo_builder.extract('styles.xml'))
self.assertTrue(len(styles_xml_body) > 0)
self.assertTrue(styles_xml_body.find('Style sheet ja') > 0)
......@@ -191,7 +192,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
self.assertEqual(200, response.getStatus())
self._validate(response.getBody())
ooo_builder = OOoBuilder(response.getBody())
styles_xml_body = ooo_builder.extract('styles.xml')
styles_xml_body = bytes2str(ooo_builder.extract('styles.xml'))
self.assertTrue(len(styles_xml_body) > 0)
self.assertTrue(styles_xml_body.find('Style sheet en') > 0)
......@@ -200,7 +201,7 @@ return getattr(context, "%s_%s" % (parameter, current_language))
Static_viewAsOdt.doSettings(request, title='', xml_file_id='content.xml',
ooo_stylesheet='NotFound_getODTStyleSheet', script_name='')
response = self.publish('/' + self.getPortal().Static_viewAsOdt.absolute_url(1))
self.assertFalse(response.getBody().startswith('PK'))
self.assertFalse(response.getBody().startswith(b'PK'))
self.assertEqual(500, response.getStatus())
def test_include_img(self):
......@@ -237,14 +238,14 @@ return getattr(context, "%s_%s" % (parameter, current_language))
response.getHeader('content-type').split(';')[0])
self.assertEqual('attachment; filename="Base_viewIncludeImageAsOdt.odt"',
response.getHeader('content-disposition'))
cs = StringIO()
cs = BytesIO()
cs.write(body)
zip_document = ZipFile(cs)
picture_list = filter(lambda x: "Pictures" in x.filename,
zip_document.infolist())
self.assertNotEqual([], picture_list)
manifest = zip_document.read('META-INF/manifest.xml')
content = zip_document.read('content.xml')
manifest = bytes2str(zip_document.read('META-INF/manifest.xml'))
content = bytes2str(zip_document.read('content.xml'))
for picture in picture_list:
self.assertIn(picture.filename, manifest)
self.assertIn(picture.filename, content)
......
......@@ -112,9 +112,9 @@ class ZuiteTests( unittest.TestCase ):
return old
def _verifyArchive( self, bits, contents ):
import StringIO
from io import BytesIO
import zipfile
stream = StringIO.StringIO( bits )
stream = BytesIO( bits )
archive = zipfile.ZipFile( stream, 'r' )
names = list( archive.namelist() )
......@@ -139,9 +139,9 @@ class ZuiteTests( unittest.TestCase ):
def _verifyManifest( self, bits, name, contents ):
import StringIO
from io import BytesIO
import zipfile
stream = StringIO.StringIO( bits )
stream = BytesIO( bits )
archive = zipfile.ZipFile( stream, 'r' )
manifest = filter( None, archive.read( name ).split( '\n' ) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment