
uQi  c               @   s  d  d l  m Z m Z d  d l m Z m Z m Z m Z m Z d  d l	 m
 Z
 m Z d  d l m Z d d l m Z d  d l Z d d	   Z d
 d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z e j d  d d    Z e j d  d d     Z e j d  d! d"    Z e j d#  d$ d%    Z e j d&  d' d(    Z  d S()   i    (   u   Imageu	   ImageDraw(   u   Resizeu   ResizeToFillu   ResizeToFitu	   SmartCropu   SmartResize(   u   eq_u   assert_true(   u	   Thumbnaili   (   u   create_imageNc              C   s/   t  d d  j t    }  t |  j d  d  S(   Nid   (   id   id   (   u	   SmartCropu   processu   create_imageu   eq_u   size(   u   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_smartcrop
   s    u   test_smartcropc              C   s/   t  d d  j t    }  t |  j d  d  S(   Nid   (   id   id   (   u   ResizeToFillu   processu   create_imageu   eq_u   size(   u   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_resizetofill   s    u   test_resizetofillc              C   s>   t  j d d  }  t d d  j |   }  t |  j d  d  S(   Nu   RGBi   id   i2   (   i   id   (   id   i2   (   u   Imageu   newu   ResizeToFitu   processu   eq_u   size(   u   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_resizetofit   s    u   test_resizetofitc              C   s>   t  j d d  }  t d d  j |   }  t |  j d  d S(   u5   
    Regression test for matthewwithanm/pilkit#1
    u   RGBi_   i   N(   i_   i_   (   i   i   (   u   Imageu   newu   ResizeToFillu   processu   eq_u   size(   u   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_resize_rounding   s    u   test_resize_roundingc              C   sD   t  j d d  }  t d d d d j |   }  t |  j d  d  S(   Nu   RGBi   id   u	   mat_colori    (   i   id   (   id   id   (   u   Imageu   newu   ResizeToFitu   processu   eq_u   size(   u   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_resizetofit_mat)   s    u   test_resizetofit_matc           
   C   s   t  j d d d  }  |  j d d d d d d d d d g	  t j |   } | j d d d	 t d d  j |   }  t t t	 d
 |  j      } t | d	 k  d
 S(   u%  
    Test that the Resize processor antialiases.

    The Resize processor is used by all of the Resize* variants, so this should
    cover all of resize processors. Basically, this is to test that it converts
    to RGBA mode before resizing.

    Related: jdriscoll/django-imagekit#192

    u   Pi  i   i    i   id   i  u   filli   N(   i  i  (   id   id   i  i  (   u   Imageu   newu
   putpaletteu	   ImageDrawu   ellipseu   Resizeu   processu   lenu   listu   filteru   Noneu	   histogramu   assert_true(   u   imgu   du   color_count(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_resize_antialiasing/   s    		!u   test_resize_antialiasingc              C   s   t  j d d  }  xv t t t t g D]b } | d d d d j |   } t | j	 d  | d d d d	 j |   } t | j	 d
  q% Wd S(   u<   
    Test that the upscale argument works as expected.

    u   RGBid   i  u   upscaleN(   id   id   T(   i  i  F(   id   id   (   u   Imageu   newu   Resizeu   ResizeToFitu   ResizeToFillu   SmartResizeu   Trueu   processu   eq_u   sizeu   False(   u   imgu   Pu   img2(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   test_upscaleM   s    u   test_upscalec              C   sh   y) t  d d d d d d	 d d	 d d  Wn8 t k
 rc }  z t t |   d  WYd  d  }  ~  Xn Xd  S(
   Nu   heighti   u   widthu   upscaleu   cropu   anchoru   tu3   You can't specify an anchor point if crop is False.F(   u	   Thumbnailu   Falseu	   Exceptionu   eq_u   str(   u   e(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyuH   test_should_raise_exception_if_anchor_is_passed_and_crop_is_set_to_false]   s    )uH   test_should_raise_exception_if_anchor_is_passed_and_crop_is_set_to_falsec           	   C   s2   t  d d d d d d d d  }  t |  j  d  S(   Nu   heighti   u   widthu   upscaleu   anchoru   tF(   u	   Thumbnailu   Falseu   assert_trueu   crop(   u   thumb(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu=   test_should_set_crop_to_true_if_anchor_is_passed_without_cropd   s    !u=   test_should_set_crop_to_true_if_anchor_is_passed_without_cropc              C   sk   t  j d d  }  y t d d  j |   Wn8 t k
 rf } z t t |  d  WYd  d  } ~ Xn Xd  S(   Nu   RGBid   u   cropu7   You must provide both a width and height when cropping.(   id   id   T(   u   Imageu   newu	   Thumbnailu   Trueu   processu	   Exceptionu   eq_u   str(   u   imgu   e(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyuH   test_should_raise_exception_when_crop_is_passed_without_height_and_widthi   s
    uH   test_should_raise_exception_when_crop_is_passed_without_height_and_widthu$   pilkit.processors.resize.SmartResizec             C   sE   t  j d d  } t d d d d d d  j |  t |  j  d  S(	   Nu   RGBid   u   heighti   u   widthu   upscale(   id   id   F(   u   Imageu   newu	   Thumbnailu   Falseu   processu   assert_trueu   called(   u   my_mocku   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu1   test_should_call_smartresize_when_crop_not_passedq   s    "u1   test_should_call_smartresize_when_crop_not_passedc             C   sT   t  j d d  } t d d d d d d  j |  |  j d d d d d d  d  S(	   Nu   RGBid   u   heighti   u   widthu   upscale(   id   id   T(   u   Imageu   newu	   Thumbnailu   Trueu   processu   assert_called_once_with(   u   my_mocku   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu&   test_should_repass_upscale_option_truex   s    "u&   test_should_repass_upscale_option_truec             C   sT   t  j d d  } t d d d d d d  j |  |  j d d d d d d  d  S(	   Nu   RGBid   u   heighti   u   widthu   upscale(   id   id   F(   u   Imageu   newu	   Thumbnailu   Falseu   processu   assert_called_once_with(   u   my_mocku   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu'   test_should_repass_upscale_option_false   s    "u'   test_should_repass_upscale_option_falseu%   pilkit.processors.resize.ResizeToFillc             C   sE   t  j d d  } t d d d d d d  j |  t |  j  d  S(	   Nu   RGBid   u   heighti   u   widthu   anchoru   fake(   id   id   (   u   Imageu   newu	   Thumbnailu   processu   assert_trueu   called(   u   my_mocku   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu;   test_should_call_resizetofill_when_crop_and_ancho_is_passed   s    "u;   test_should_call_resizetofill_when_crop_and_ancho_is_passedu$   pilkit.processors.resize.ResizeToFitc             C   sE   t  j d d  } t d d d d d d  j |  t |  j  d  S(	   Nu   RGBid   u   heighti   u   widthu   crop(   id   id   F(   u   Imageu   newu	   Thumbnailu   Falseu   processu   assert_trueu   called(   u   my_mocku   img(    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu4   test_should_call_resizetofit_when_crop_is_not_passed   s    "u4   test_should_call_resizetofit_when_crop_is_not_passed(!   u
   pilkit.libu   Imageu	   ImageDrawu   pilkit.processorsu   Resizeu   ResizeToFillu   ResizeToFitu	   SmartCropu   SmartResizeu
   nose.toolsu   eq_u   assert_trueu   pilkit.processors.resizeu	   Thumbnailu   utilsu   create_imageu   mocku   test_smartcropu   test_resizetofillu   test_resizetofitu   test_resize_roundingu   test_resizetofit_matu   test_resize_antialiasingu   test_upscaleuH   test_should_raise_exception_if_anchor_is_passed_and_crop_is_set_to_falseu=   test_should_set_crop_to_true_if_anchor_is_passed_without_cropuH   test_should_raise_exception_when_crop_is_passed_without_height_and_widthu   patchu1   test_should_call_smartresize_when_crop_not_passedu&   test_should_repass_upscale_option_trueu'   test_should_repass_upscale_option_falseu;   test_should_call_resizetofill_when_crop_and_ancho_is_passedu4   test_should_call_resizetofit_when_crop_is_not_passed(    (    (    uH   /Users/mjt/Code/projects/django-imagekit/pilkit/tests/test_processors.pyu   <module>   s(   (
