Fix failing tests

This commit is contained in:
Simon Conseil
2013-09-29 00:20:35 +02:00
parent 21c4041f3b
commit 3e342b8ffb
3 changed files with 16 additions and 7 deletions

View File

@@ -73,7 +73,7 @@ class PathsDb(object):
# basepath must to be a unicode string so that os.walk will return
# unicode dirnames and filenames. If basepath is a str, we must
# convert it to unicode.
if isinstance(path, str):
if compat.PY2 and isinstance(path, str):
enc = locale.getpreferredencoding()
self.basepath = path.decode(enc)
else:
@@ -105,8 +105,13 @@ class PathsDb(object):
relpath = os.path.relpath(path, self.basepath)
# sort images and sub-albums by name
filenames.sort(cmp=locale.strcoll)
dirnames.sort(cmp=locale.strcoll)
if compat.PY2:
filenames.sort(cmp=locale.strcoll)
dirnames.sort(cmp=locale.strcoll)
else:
from functools import cmp_to_key
filenames.sort(key=cmp_to_key(locale.strcoll))
dirnames.sort(key=cmp_to_key(locale.strcoll))
self.db['paths_list'].append(relpath)
self.db[relpath] = {

View File

@@ -91,8 +91,7 @@ def generate_image(source, outname, settings, options=None):
outformat = img.format or original_format or 'JPEG'
logger.debug(u'Save resized image to {0} ({1})'.format(outname, outformat))
with open(outname, 'w') as fp:
save_image(img, fp, outformat, options=options, autoconvert=True)
save_image(img, outname, outformat, options=options, autoconvert=True)
def generate_thumbnail(source, outname, box, fit=True, options=None):
@@ -109,8 +108,7 @@ def generate_thumbnail(source, outname, box, fit=True, options=None):
outformat = img.format or original_format or 'JPEG'
logger.debug(u'Save thumnail image: {0} ({1})'.format(outname, outformat))
with open(outname, 'w') as fp:
save_image(img, fp, outformat, options=options, autoconvert=True)
save_image(img, outname, outformat, options=options, autoconvert=True)
def add_copyright(img, text):

View File

@@ -27,6 +27,8 @@ import re
import shutil
import sigal.image
from . import compat
def vid_size(source):
"""Returns the dimensions of the video"""
@@ -35,6 +37,10 @@ def vid_size(source):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if not compat.PY2:
stderr = stderr.decode('utf8')
match = pattern.search(stderr)
if match:
x, y = int(match.groups()[0]), int(match.groups()[1])