Skip to content

Commit

Permalink
Debugging Python3 compatibility. Debugging tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-bnr committed Dec 27, 2017
1 parent e0fe616 commit d8e7d02
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rib/thumbnail/pil.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def generate(self, filepath):
filename = os.path.basename(filepath)
_, extension = os.path.splitext(filename)

thumbnail_filename = hashlib.sha1(filepath).hexdigest() + extension
thumbnail_filename = hashlib.sha1(filepath.encode('utf-8')).hexdigest() + extension
thumbnail_filepath = os.path.join(self.__path, thumbnail_filename)

if os.path.exists(thumbnail_filepath) is False:
Expand Down
8 changes: 5 additions & 3 deletions tests/handler/api/thumbnail/test_download.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import unittest
import StringIO
import io

import PIL.Image

Expand All @@ -21,6 +21,8 @@ def test_get__gnome(self):
if is_loaded is False:
raise unittest.SkipTest("Gnome not available.")

import rib.handler.api.thumbnail.download

with rib.test_support.environment(
IMAGE_ROOT_PATH=_ASSETS_PATH,
THUMBNAILER_CLASS='rib.thumbnail.gnome.GnomeThumbnailer',
Expand All @@ -32,7 +34,7 @@ def test_get__gnome(self):
self.assertEquals(r.status_code, 200)
self.assertEquals(r.headers['X-THUMBNAILER'], 'GnomeThumbnailer')

s = StringIO.StringIO(r.data)
s = io.BytesIO(r.data)
im = PIL.Image.open(s)
self.assertTrue(im.size[0] <= 128)
self.assertTrue(im.size[1] <= 128)
Expand All @@ -53,7 +55,7 @@ def test_get__pil(self):
self.assertEquals(r.status_code, 200)
self.assertEquals(r.headers['X-THUMBNAILER'], 'PilThumbnailer')

s = StringIO.StringIO(r.data)
s = io.BytesIO(r.data)
im = PIL.Image.open(s)
self.assertTrue(im.size[0] <= 128)
self.assertTrue(im.size[1] <= 128)
27 changes: 22 additions & 5 deletions tests/handler/image/test_browse.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import os
import unittest
import HTMLParser

import rib.test_support


class TestParser(HTMLParser.HTMLParser):
try:
import HTMLParser
except ImportError:
# Python 3

import html.parser

class _TestParserBase(html.parser.HTMLParser):
def __init__(self, *args, **kwargs):
html.parser.HTMLParser.__init__(self, *args, **kwargs)
else:
# Python 2

class _TestParserBase(HTMLParser.HTMLParser):
def __init__(self, *args, **kwargs):
HTMLParser.HTMLParser.__init__(self, *args, **kwargs)


class TestParser(_TestParserBase):
def __init__(self, *args, **kwargs):
self.__images = []

HTMLParser.HTMLParser.__init__(self, *args, **kwargs)
_TestParserBase.__init__(self, *args, **kwargs)

def handle_starttag(self, tag, attrs):
if tag != 'img':
Expand Down Expand Up @@ -49,7 +66,7 @@ def test_get__root(self):
self.assertEquals(r.status_code, 200)

p = TestParser()
p.feed(r.data)
p.feed(str(r.data))

expected = [
'/api/thumbnail/download?filepath=subdir',
Expand All @@ -73,7 +90,7 @@ def test_get__subdirectory(self):
self.assertEquals(r.status_code, 200)

p = TestParser()
p.feed(r.data)
p.feed(str(r.data))

expected = [
'/api/thumbnail/download?filepath=subdir%2Fimage3.jpg',
Expand Down
2 changes: 1 addition & 1 deletion tests/handler/system/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_get(self):

self.assertEquals(r.status_code, 200)

expected = """\
expected = b"""\
{}
"""

Expand Down
2 changes: 2 additions & 0 deletions tests/thumbnail/test_gnome.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def test_generate(self):
image_filepath = \
os.path.join(_ASSETS_PATH, 'childpath', 'gorillababy.jpg')

import rib.thumbnail.gnome

gt = rib.thumbnail.gnome.GnomeThumbnailer()
thumbnail_filepath, thumbnail_mimetype = \
gt.generate(image_filepath)
Expand Down

0 comments on commit d8e7d02

Please sign in to comment.