<s> import os <EOL> import shutil <EOL> from PIL import Image <EOL> from django import test <EOL> from django . conf import settings <EOL> from . helpers import CropdusterTestCaseMediaMixin <EOL> class TestUtilsImage ( CropdusterTestCaseMediaMixin , test . TestCase ) : <EOL> def _get_img ( self , filename ) : <EOL> return Image . open ( os . path . join ( self . TEST_IMG_DIR , filename ) ) <EOL> def test_that_test_work ( self ) : <EOL> self . assertEqual ( True , True ) <EOL> def test_get_image_extension ( self ) : <EOL> from . . utils import get_image_extension <EOL> shutil . copyfile ( <EOL> os . path . join ( self . TEST_IMG_DIR , '<STR_LIT>' ) , <EOL> os . path . join ( self . TEST_IMG_DIR , '<STR_LIT>' ) ) <EOL> shutil . copyfile ( <EOL> os . path . join ( self . TEST_IMG_DIR , '<STR_LIT>' ) , <EOL> os . path . join ( self . TEST_IMG_DIR , '<STR_LIT>' ) ) <EOL> imgs = [ <EOL> ( self . _get_img ( '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( self . _get_img ( '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( self . _get_img ( '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( self . _get_img ( '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ( self . _get_img ( '<STR_LIT>' ) , '<STR_LIT>' ) , <EOL> ] <EOL> for img , ext in imgs : <EOL> self . assertEqual ( get_image_extension ( img ) , ext ) <EOL> def test_is_transparent ( self ) : <EOL> from . . utils import is_transparent <EOL> yes = self . _get_img ( '<STR_LIT>' ) <EOL> no = self . _get_img ( '<STR_LIT>' ) <EOL> self . assertTrue ( is_transparent ( yes ) ) <EOL> self . assertFalse ( is_transparent ( no ) ) <EOL> def test_correct_colorspace ( self ) : <EOL> from . . utils import correct_colorspace <EOL> img = self . _get_img ( '<STR_LIT>' ) <EOL> self . assertEqual ( img . mode , '<STR_LIT>' ) <EOL> converted = correct_colorspace ( img ) <EOL> self . assertEqual ( img . mode , '<STR_LIT>' ) <EOL> self . assertEqual ( converted . mode , '<STR_LIT>' ) <EOL> def test_is_animated_gif ( self ) : <EOL> from . . utils import is_animated_gif <EOL> yes = self . _get_img ( '<STR_LIT>' ) <EOL> no = self . _get_img ( '<STR_LIT>' ) <EOL> self . assertTrue ( is_animated_gif ( yes ) ) <EOL> self . assertFalse ( is_animated_gif ( no ) ) <EOL> class TestUtilsPaths ( CropdusterTestCaseMediaMixin , test . TestCase ) : <EOL> def test_get_upload_foldername ( self ) : <EOL> import uuid <EOL> from . . utils import get_upload_foldername <EOL> random = uuid . uuid4 ( ) . hex <EOL> path = os . path . join ( settings . MEDIA_ROOT , random ) <EOL> self . assertEqual ( get_upload_foldername ( '<STR_LIT>' , upload_to = random ) , <EOL> os . path . join ( path , '<STR_LIT>' ) ) <EOL> self . assertEqual ( get_upload_foldername ( '<STR_LIT>' , upload_to = random ) , <EOL> os . path . join ( path , '<STR_LIT>' ) ) <EOL> shutil . rmtree ( path ) <EOL> def test_get_min_size ( self ) : <EOL> from . . utils import get_min_size <EOL> from . . resizing import Size <EOL> sizes = [ <EOL> Size ( '<STR_LIT:a>' , w = <NUM_LIT:200> , h = <NUM_LIT:200> ) , <EOL> Size ( '<STR_LIT:b>' , w = <NUM_LIT:100> , h = <NUM_LIT> ) , <EOL> Size ( '<STR_LIT:c>' , w = <NUM_LIT:20> , h = <NUM_LIT:20> ) <EOL> ] <EOL> self . assertEqual ( get_min_size ( sizes ) , ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> sizes = [ <EOL> Size ( '<STR_LIT:a>' , min_w = <NUM_LIT:200> , min_h = <NUM_LIT:200> , max_h = <NUM_LIT> ) , <EOL> Size ( '<STR_LIT:b>' , min_w = <NUM_LIT:100> , min_h = <NUM_LIT> ) , <EOL> Size ( '<STR_LIT:c>' , w = <NUM_LIT:20> , h = <NUM_LIT:20> ) <EOL> ] <EOL> self . assertEqual ( get_min_size ( sizes ) , ( <NUM_LIT:200> , <NUM_LIT> ) ) <EOL> def test_get_media_path ( self ) : <EOL> from generic_plus . utils import get_media_path <EOL> img_name = '<STR_LIT>' <EOL> from_url = settings . MEDIA_URL + img_name <EOL> to_url = settings . MEDIA_ROOT + img_name <EOL> self . assertEqual ( get_media_path ( from_url ) , to_url ) </s>
