Skip to content

Commit

Permalink
Merge pull request #66 from plone/gforcada-patch-1
Browse files Browse the repository at this point in the history
Avoid resource warnings
  • Loading branch information
jensens authored Apr 22, 2019
2 parents 68fdce4 + 3e41dd6 commit 1306e3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Products/CMFEditions/StorageMigrationSupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def editImage(context, version=0):
name = name[:-4]
filename = "%s_v%s.gif" % (name, version)
path = os.path.join(PACKAGE_HOME, "tests", "images", filename)
with open(path) as image_handle:
image = image_handle.read()
if not title:
title = "0: %s image title" % name
desc = "0: %s image description" % name
image = open(path).read()
else:
title = "%s%s" % (version, title[1:])
desc = "%s%s" % (version, desc[1:])
image = open(path).read()
context.update(title=title, description=desc, image=image)

def editLink(context, version=0):
Expand Down
39 changes: 14 additions & 25 deletions Products/CMFEditions/tests/test_ATContentTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
import six


def read_image(file_path):
with open(os.path.join(PACKAGE_HOME, file_path), 'rb') as image:
data = image.read()
return data


if six.PY2:
from Products.CMFEditions import PACKAGE_HOME
from plone.app.testing.bbb_at import PloneTestCase
Expand Down Expand Up @@ -100,14 +106,8 @@ def testNewsItem(self):

def testImage(self):
self.folder.invokeFactory('Image', id='image')
img1 = open(
os.path.join(PACKAGE_HOME, 'tests/images/img1.png'),
'rb'
).read()
img2 = open(
os.path.join(PACKAGE_HOME, 'tests/images/img2.png'),
'rb'
).read()
img1 = read_image('tests/images/img1.png')
img2 = read_image('tests/images/img2.png')
portal_repository = self.portal_repository
content = self.folder.image
content.edit(image=img1)
Expand All @@ -125,14 +125,8 @@ def testImage(self):

def testFile(self):
self.folder.invokeFactory('File', id='file')
file1 = open(
os.path.join(PACKAGE_HOME, 'tests/file1.dat'),
'rb'
).read()
file2 = open(
os.path.join(PACKAGE_HOME, 'tests/file2.dat'),
'rb'
).read()
file1 = read_image('tests/file1.dat')
file2 = read_image('tests/file2.dat')
portal_repository = self.portal_repository
content = self.folder.file
content.edit(file=file1)
Expand Down Expand Up @@ -169,14 +163,8 @@ def testFolder(self):

def testBlobsNotResavedUnlessChanged(self):
self.folder.invokeFactory('File', id='file')
file1 = open(
os.path.join(PACKAGE_HOME, 'tests/images/img1.png'),
'rb'
).read()
file2 = open(
os.path.join(PACKAGE_HOME, 'tests/images/img2.png'),
'rb'
).read()
file1 = read_image('tests/images/img1.png')
file2 = read_image('tests/images/img2.png')
portal_repository = self.portal_repository
content = self.folder.file
content.edit(file=file1)
Expand Down Expand Up @@ -215,7 +203,8 @@ def testBlobsNotResavedUnlessChanged(self):
self.assertEqual(content.getFile().getBlob(), blob1)

def testBlobsNotStringConverted(self):
file1 = open(os.path.join(PACKAGE_HOME, 'tests/file1.dat')).read()
with open(os.path.join(PACKAGE_HOME, 'tests/file1.dat')) as handle:
file1 = handle.read()
content = self.folder[
self.folder.invokeFactory('File', id='file', file=file1)]

Expand Down
14 changes: 10 additions & 4 deletions Products/CMFEditions/tests/test_ContentTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
import os


def read_image(file_path):
with open(os.path.join(PACKAGE_HOME, file_path), 'rb') as image:
data = image.read()
return data


class TestPloneContents(CMFEditionsBaseTestCase):

def setUp(self):
Expand Down Expand Up @@ -105,8 +111,8 @@ def testNewsItem(self):
def testImage(self):
self.folder.invokeFactory('Image', id='image')
portal_repository = self.portal_repository
img1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
img2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
img1 = read_image('tests/images/img1.png')
img2 = read_image('tests/images/img2.png')
content = self.folder.image
content.image = NamedBlobImage(img1, u'img1.png', u'image/png')
content.title = u'content'
Expand Down Expand Up @@ -136,8 +142,8 @@ def testImage(self):

def testFile(self):
self.folder.invokeFactory('File', id='file')
file1 = open(os.path.join(PACKAGE_HOME, 'tests/images/img1.png'), 'rb').read()
file2 = open(os.path.join(PACKAGE_HOME, 'tests/images/img2.png'), 'rb').read()
file1 = read_image('tests/images/img1.png')
file2 = read_image('tests/images/img2.png')
portal_repository = self.portal_repository
content = self.folder.file
content.file = NamedBlobFile(file1, u'img1.png', u'image/png')
Expand Down
2 changes: 2 additions & 0 deletions news/65.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid ResourceWarnings.
[gforcada]

0 comments on commit 1306e3a

Please sign in to comment.