<s> try : <EOL> from cStringIO import cStringIO as BytesIO <EOL> except ImportError : <EOL> from django . utils . six import BytesIO <EOL> from os import path <EOL> from django . test import TestCase <EOL> from django . utils import six , unittest <EOL> from easy_thumbnails import files , utils , signals , exceptions , models , engine <EOL> from easy_thumbnails . conf import settings <EOL> from easy_thumbnails . options import ThumbnailOptions <EOL> from easy_thumbnails . tests import utils as test <EOL> try : <EOL> from PIL import Image <EOL> except ImportError : <EOL> import Image <EOL> try : <EOL> from testfixtures import LogCapture <EOL> except ImportError : <EOL> LogCapture = None <EOL> class FilesTest ( test . BaseTest ) : <EOL> def setUp ( self ) : <EOL> super ( FilesTest , self ) . setUp ( ) <EOL> self . storage = test . TemporaryStorage ( ) <EOL> self . remote_storage = test . FakeRemoteStorage ( ) <EOL> filename = self . create_image ( self . storage , '<STR_LIT>' ) <EOL> self . thumbnailer = files . get_thumbnailer ( self . storage , filename ) <EOL> self . thumbnailer . thumbnail_storage = self . storage <EOL> filename = self . create_image ( self . remote_storage , '<STR_LIT>' ) <EOL> self . remote_thumbnailer = files . get_thumbnailer ( <EOL> self . remote_storage , filename ) <EOL> self . remote_thumbnailer . thumbnail_storage = self . remote_storage <EOL> self . ext_thumbnailer = files . get_thumbnailer ( self . storage , filename ) <EOL> self . ext_thumbnailer . thumbnail_storage = self . storage <EOL> filename = self . create_image ( <EOL> self . storage , '<STR_LIT>' , image_mode = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' ) <EOL> self . transparent_thumbnailer = files . get_thumbnailer ( <EOL> self . storage , filename ) <EOL> self . transparent_thumbnailer . thumbnail_storage = self . storage <EOL> filename = self . create_image ( <EOL> self . storage , '<STR_LIT>' , image_mode = '<STR_LIT>' , <EOL> image_format = '<STR_LIT>' ) <EOL> self . transparent_greyscale_thumbnailer = files . get_thumbnailer ( <EOL> self . storage , filename ) <EOL> self . transparent_greyscale_thumbnailer . thumbnail_storage = self . storage <EOL> def tearDown ( self ) : <EOL> self . storage . delete_temporary_storage ( ) <EOL> self . remote_storage . delete_temporary_storage ( ) <EOL> super ( FilesTest , self ) . tearDown ( ) <EOL> def assertRegex ( self , * args , ** kwargs ) : <EOL> func = getattr ( super ( FilesTest , self ) , '<STR_LIT>' , None ) <EOL> if func is None : <EOL> func = self . assertRegexpMatches <EOL> return func ( * args , ** kwargs ) <EOL> def test_tag ( self ) : <EOL> local = self . thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> remote = self . remote_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( <EOL> local . tag ( ) , '<STR_LIT>' <EOL> '<STR_LIT>' % local . url ) <EOL> self . assertEqual ( <EOL> local . tag ( alt = '<STR_LIT>' ) , '<STR_LIT>' <EOL> '<STR_LIT>' % local . url ) <EOL> self . assertEqual ( <EOL> remote . tag ( use_size = False ) , '<STR_LIT>' % remote . url ) <EOL> self . assertEqual ( <EOL> remote . tag ( ) , <EOL> '<STR_LIT>' % remote . url ) <EOL> remote = self . remote_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( <EOL> remote . tag ( ) , '<STR_LIT>' % remote . url ) <EOL> self . assertEqual ( <EOL> remote . tag ( use_size = True ) , <EOL> '<STR_LIT>' % remote . url ) <EOL> self . assertEqual ( <EOL> local . tag ( ** { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:class>' : '<STR_LIT>' } ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % local . url ) <EOL> def test_tag_cached_dimensions ( self ) : <EOL> settings . THUMBNAIL_CACHE_DIMENSIONS = True <EOL> self . remote_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> remote = self . remote_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( <EOL> remote . tag ( ) , <EOL> '<STR_LIT>' % remote . url ) <EOL> def test_transparent_thumbnailing ( self ) : <EOL> thumb_file = self . thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> thumb_file . seek ( <NUM_LIT:0> ) <EOL> thumb = Image . open ( thumb_file ) <EOL> self . assertFalse ( <EOL> utils . is_transparent ( thumb ) , <EOL> "<STR_LIT>" % thumb_file . name ) <EOL> thumb_file = self . transparent_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> thumb_file . seek ( <NUM_LIT:0> ) <EOL> thumb = Image . open ( thumb_file ) <EOL> self . assertTrue ( <EOL> utils . is_transparent ( thumb ) , <EOL> "<STR_LIT>" % thumb_file . name ) <EOL> thumb_file = self . transparent_greyscale_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> thumb_file . seek ( <NUM_LIT:0> ) <EOL> thumb = Image . open ( thumb_file ) <EOL> self . assertTrue ( <EOL> utils . is_transparent ( thumb ) , <EOL> "<STR_LIT>" % thumb_file . name ) <EOL> def test_missing_thumb ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> thumb_cache = self . thumbnailer . get_thumbnail_cache ( <EOL> thumbnail_name = thumb . name ) <EOL> thumb_cache . delete ( ) <EOL> thumb . storage . delete ( thumb . name ) <EOL> self . thumbnailer . get_thumbnail ( opts ) <EOL> def test_missing_thumb_from_storage ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> thumb . storage . delete ( thumb . name ) <EOL> new_thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( thumb . name , new_thumb . name ) <EOL> self . assertTrue ( thumb . storage . exists ( new_thumb . name ) ) <EOL> def test_missing_remote_thumb ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } <EOL> thumb = self . remote_thumbnailer . get_thumbnail ( opts ) <EOL> thumb_cache = self . remote_thumbnailer . get_thumbnail_cache ( <EOL> thumbnail_name = thumb . name ) <EOL> thumb_cache . delete ( ) <EOL> thumb . storage . delete ( thumb . name ) <EOL> self . remote_thumbnailer . get_thumbnail ( opts ) <EOL> def test_missing_source ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } <EOL> self . storage . delete ( self . thumbnailer . name ) <EOL> self . assertRaises ( <EOL> exceptions . InvalidImageFormatError , <EOL> self . thumbnailer . get_thumbnail , opts ) <EOL> def test_extensions ( self ) : <EOL> self . ext_thumbnailer . thumbnail_extension = '<STR_LIT>' <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( path . splitext ( thumb . name ) [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . ext_thumbnailer . thumbnail_preserve_extensions = ( '<STR_LIT:foo>' , ) <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( path . splitext ( thumb . name ) [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . ext_thumbnailer . thumbnail_preserve_extensions = True <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( path . splitext ( thumb . name ) [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . ext_thumbnailer . thumbnail_preserve_extensions = ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertEqual ( path . splitext ( thumb . name ) [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> def test_high_resolution ( self ) : <EOL> self . ext_thumbnailer . thumbnail_high_resolution = True <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> base , ext = path . splitext ( thumb . path ) <EOL> hires_thumb_file = '<STR_LIT>' . join ( [ base + '<STR_LIT>' , ext ] ) <EOL> self . assertTrue ( path . isfile ( hires_thumb_file ) ) <EOL> thumb = Image . open ( hires_thumb_file ) <EOL> self . assertEqual ( thumb . size , ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> def test_subsampling ( self ) : <EOL> samplings = { <EOL> <NUM_LIT:0> : ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> <NUM_LIT:1> : ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> <NUM_LIT:2> : ( <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> } <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> im = Image . open ( thumb . path ) <EOL> self . assertNotIn ( '<STR_LIT>' , thumb . name ) <EOL> sampling = im . layer [ <NUM_LIT:0> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:1> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:2> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( sampling , samplings [ <NUM_LIT:2> ] ) <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) , '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> im = Image . open ( thumb . path ) <EOL> self . assertIn ( '<STR_LIT>' , thumb . name ) <EOL> sampling = im . layer [ <NUM_LIT:0> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:1> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:2> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( sampling , samplings [ <NUM_LIT:1> ] ) <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> im = Image . open ( thumb . path ) <EOL> self . assertIn ( '<STR_LIT>' , thumb . name ) <EOL> sampling = im . layer [ <NUM_LIT:0> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:1> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:2> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( sampling , samplings [ <NUM_LIT:0> ] ) <EOL> def test_default_subsampling ( self ) : <EOL> settings . THUMBNAIL_DEFAULT_OPTIONS = { '<STR_LIT>' : <NUM_LIT:1> } <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> im = Image . open ( thumb . path ) <EOL> self . assertIn ( '<STR_LIT>' , thumb . name ) <EOL> sampling = im . layer [ <NUM_LIT:0> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:1> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] + im . layer [ <NUM_LIT:2> ] [ <NUM_LIT:1> : <NUM_LIT:3> ] <EOL> self . assertEqual ( sampling , ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> def test_high_resolution_force_off ( self ) : <EOL> self . ext_thumbnailer . thumbnail_high_resolution = True <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) , '<STR_LIT>' : False } ) <EOL> base , ext = path . splitext ( thumb . path ) <EOL> hires_thumb_file = '<STR_LIT>' . join ( [ base + '<STR_LIT>' , ext ] ) <EOL> self . assertFalse ( path . exists ( hires_thumb_file ) ) <EOL> def test_high_resolution_force ( self ) : <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) , '<STR_LIT>' : True } ) <EOL> base , ext = path . splitext ( thumb . path ) <EOL> hires_thumb_file = '<STR_LIT>' . join ( [ base + '<STR_LIT>' , ext ] ) <EOL> self . assertTrue ( path . isfile ( hires_thumb_file ) ) <EOL> thumb = Image . open ( hires_thumb_file ) <EOL> self . assertEqual ( thumb . size , ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> def test_highres_infix ( self ) : <EOL> self . ext_thumbnailer . thumbnail_high_resolution = True <EOL> self . ext_thumbnailer . thumbnail_highres_infix = '<STR_LIT>' <EOL> thumb = self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> base , ext = path . splitext ( thumb . path ) <EOL> hires_thumb_file = '<STR_LIT>' . join ( [ base + '<STR_LIT>' , ext ] ) <EOL> self . assertTrue ( path . isfile ( hires_thumb_file ) ) <EOL> thumb = Image . open ( hires_thumb_file ) <EOL> self . assertEqual ( thumb . size , ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> @ unittest . skipIf ( <EOL> '<STR_LIT>' not in settings . INSTALLED_APPS , <EOL> '<STR_LIT>' ) <EOL> @ unittest . skipIf ( LogCapture is None , '<STR_LIT>' ) <EOL> def test_postprocessor ( self ) : <EOL> """<STR_LIT>""" <EOL> settings . THUMBNAIL_OPTIMIZE_COMMAND = { <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> with LogCapture ( ) as logcap : <EOL> self . ext_thumbnailer . thumbnail_extension = '<STR_LIT>' <EOL> self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:10> ) } ) <EOL> actual = tuple ( logcap . actual ( ) ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( actual [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( actual [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertRegex ( <EOL> actual [ <NUM_LIT:2> ] , <EOL> '<STR_LIT>' ) <EOL> @ unittest . skipIf ( <EOL> '<STR_LIT>' not in settings . INSTALLED_APPS , <EOL> '<STR_LIT>' ) <EOL> @ unittest . skipIf ( LogCapture is None , '<STR_LIT>' ) <EOL> def test_postprocessor_fail ( self ) : <EOL> """<STR_LIT>""" <EOL> settings . THUMBNAIL_OPTIMIZE_COMMAND = { <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> with LogCapture ( ) as logcap : <EOL> self . ext_thumbnailer . thumbnail_extension = '<STR_LIT>' <EOL> self . ext_thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:10> ) } ) <EOL> actual = tuple ( logcap . actual ( ) ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( actual [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( actual [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> self . assertRegex ( <EOL> actual [ <NUM_LIT:2> ] , r'<STR_LIT>' ) <EOL> def test_USE_TZ ( self ) : <EOL> settings . USE_TZ = True <EOL> self . thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:20> ) } ) <EOL> settings . USE_TZ = False <EOL> self . thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:20> , <NUM_LIT> ) } ) <EOL> def test_thumbnailfile_options ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) , '<STR_LIT>' : True , '<STR_LIT>' : True } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( thumb . thumbnail_options , ThumbnailOptions ( opts ) ) <EOL> def test_get_thumbnail_name ( self ) : <EOL> opts = { <EOL> '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : True , <EOL> '<STR_LIT:target>' : ( <NUM_LIT:10> , <NUM_LIT:10> ) } <EOL> self . assertEqual ( <EOL> self . thumbnailer . get_thumbnail_name ( opts ) , <EOL> '<STR_LIT>' ) <EOL> def test_default_options_setting ( self ) : <EOL> settings . THUMBNAIL_DEFAULT_OPTIONS = { '<STR_LIT>' : True } <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT:50> , <NUM_LIT:50> ) ) <EOL> def test_dimensions_of_cached_image ( self ) : <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT:50> , <NUM_LIT> ) ) <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT:50> , <NUM_LIT> ) ) <EOL> def test_cached_dimensions_of_cached_image ( self ) : <EOL> settings . THUMBNAIL_CACHE_DIMENSIONS = True <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT:50> , <NUM_LIT> ) ) <EOL> dimensions = models . ThumbnailDimensions . objects . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( <EOL> ( thumb . width , thumb . height ) , <EOL> ( dimensions . width , dimensions . height ) ) <EOL> def test_remote_cached_dimensions_queries ( self ) : <EOL> settings . THUMBNAIL_CACHE_DIMENSIONS = True <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) } <EOL> thumb = self . remote_thumbnailer . get_thumbnail ( opts ) <EOL> thumb . height <EOL> thumb = self . remote_thumbnailer . get_thumbnail ( opts ) <EOL> with self . assertNumQueries ( <NUM_LIT:0> ) : <EOL> self . assertEqual ( thumb . width , <NUM_LIT:50> ) <EOL> def test_add_dimension_cache ( self ) : <EOL> settings . THUMBNAIL_CACHE_DIMENSIONS = True <EOL> opts = { '<STR_LIT:size>' : ( <NUM_LIT:50> , <NUM_LIT:50> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( ( thumb . width , thumb . height ) , ( <NUM_LIT:50> , <NUM_LIT> ) ) <EOL> models . ThumbnailDimensions . objects . all ( ) . delete ( ) <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( models . ThumbnailDimensions . objects . count ( ) , <NUM_LIT:0> ) <EOL> thumb . height <EOL> dimensions = models . ThumbnailDimensions . objects . get ( ) <EOL> thumb = self . thumbnailer . get_thumbnail ( opts ) <EOL> self . assertEqual ( <EOL> ( thumb . width , thumb . height ) , <EOL> ( dimensions . width , dimensions . height ) ) <EOL> def test_thumbnail_created_signal ( self ) : <EOL> def signal_handler ( sender , ** kwargs ) : <EOL> sender . signal_received = True <EOL> signals . thumbnail_created . connect ( signal_handler ) <EOL> try : <EOL> thumb = self . thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:20> ) } ) <EOL> self . assertTrue ( hasattr ( thumb , '<STR_LIT>' ) ) <EOL> finally : <EOL> signals . thumbnail_created . disconnect ( signal_handler ) <EOL> def test_passive_thumbnailer ( self ) : <EOL> options = { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:10> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( options , generate = False ) <EOL> self . assertEqual ( thumb , None ) <EOL> self . thumbnailer . generate = False <EOL> thumb = self . thumbnailer . get_thumbnail ( options ) <EOL> self . assertEqual ( thumb , None ) <EOL> thumb = self . thumbnailer . get_thumbnail ( options , generate = True ) <EOL> self . assertTrue ( thumb ) <EOL> thumb = self . thumbnailer . get_thumbnail ( options ) <EOL> self . assertTrue ( thumb ) <EOL> thumb = self . thumbnailer . get_thumbnail ( options , generate = False ) <EOL> self . assertTrue ( thumb ) <EOL> def test_thumbnail_missed_signal ( self ) : <EOL> def signal_handler ( sender , ** kwargs ) : <EOL> sender . missed_signal = kwargs . get ( '<STR_LIT>' ) <EOL> signals . thumbnail_missed . connect ( signal_handler ) <EOL> try : <EOL> self . thumbnailer . get_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } ) <EOL> self . assertFalse ( hasattr ( self . thumbnailer , '<STR_LIT>' ) ) <EOL> self . thumbnailer . get_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:100> ) } , generate = False ) <EOL> self . assertFalse ( hasattr ( self . thumbnailer , '<STR_LIT>' ) ) <EOL> options = { '<STR_LIT:size>' : ( <NUM_LIT:10> , <NUM_LIT:20> ) } <EOL> thumb = self . thumbnailer . get_thumbnail ( options , generate = False ) <EOL> self . assertEqual ( thumb , None ) <EOL> self . assertEqual ( <EOL> self . thumbnailer . missed_signal , ThumbnailOptions ( options ) ) <EOL> finally : <EOL> signals . thumbnail_created . disconnect ( signal_handler ) <EOL> def test_progressive_encoding ( self ) : <EOL> thumb = self . thumbnailer . generate_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT> , <NUM_LIT> ) , '<STR_LIT>' : True } ) <EOL> self . assertFalse ( utils . is_progressive ( Image . open ( thumb ) ) ) <EOL> thumb = self . thumbnailer . generate_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:1> , <NUM_LIT:100> ) , '<STR_LIT>' : True } ) <EOL> self . assertTrue ( utils . is_progressive ( Image . open ( thumb ) ) ) <EOL> thumb = self . thumbnailer . generate_thumbnail ( <EOL> { '<STR_LIT:size>' : ( <NUM_LIT:100> , <NUM_LIT:1> ) , '<STR_LIT>' : True } ) <EOL> self . assertTrue ( utils . is_progressive ( Image . open ( thumb ) ) ) <EOL> thumb = self . thumbnailer . generate_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:200> , <NUM_LIT:200> ) } ) <EOL> self . assertTrue ( utils . is_progressive ( Image . open ( thumb ) ) ) <EOL> def test_no_progressive_encoding ( self ) : <EOL> settings . THUMBNAIL_PROGRESSIVE = False <EOL> thumb = self . thumbnailer . generate_thumbnail ( { '<STR_LIT:size>' : ( <NUM_LIT:200> , <NUM_LIT:200> ) } ) <EOL> self . assertFalse ( utils . is_progressive ( Image . open ( thumb ) ) ) <EOL> class FakeSourceGenerator ( object ) : <EOL> def __init__ ( self , fail = False ) : <EOL> self . fail = fail <EOL> def __call__ ( self , source , ** kwargs ) : <EOL> if self . fail : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return source <EOL> class EngineTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . source = BytesIO ( six . b ( '<STR_LIT>' ) ) <EOL> def test_single_fail ( self ) : <EOL> source_generators = [ FakeSourceGenerator ( fail = True ) ] <EOL> self . assertRaises ( <EOL> ValueError , engine . generate_source_image , <EOL> self . source , { } , source_generators , fail_silently = False ) <EOL> def test_single_silent_fail ( self ) : <EOL> source_generators = [ FakeSourceGenerator ( fail = True ) ] <EOL> image = engine . generate_source_image ( <EOL> self . source , { } , source_generators ) <EOL> self . assertEqual ( image , None ) <EOL> def test_multiple_fail ( self ) : <EOL> source_generators = [ <EOL> FakeSourceGenerator ( fail = True ) , FakeSourceGenerator ( fail = True ) ] <EOL> self . assertRaises ( <EOL> engine . NoSourceGenerator , engine . generate_source_image , <EOL> self . source , { } , source_generators , fail_silently = False ) <EOL> def test_multiple_silent_fail ( self ) : <EOL> source_generators = [ <EOL> FakeSourceGenerator ( fail = True ) , FakeSourceGenerator ( fail = True ) ] <EOL> image = engine . generate_source_image ( <EOL> self . source , { } , source_generators ) <EOL> self . assertEqual ( image , None ) </s>
