3
VmWo                 @   s`  d Z ddlmZmZ ddlZddlmZmZmZ ddl	m
Z
mZ ddlmZ dd	lmZmZ d7d
dZd8ddZedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zd#d$ Zed%d& Zed'd( Zed)d* Z ed+d, Z!ed-d. Z"ed/d0 Z#ed1d2 Z$ed3d4 Z%ed5d6 Z&dS )9z
    weasyprint.tests.test_css_properties
    ------------------------------------

    Test expanders for shorthand properties.

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

    )divisionunicode_literalsN   )assert_no_logscapture_logsalmost_equal   )PARSERpreprocess_declarations)INITIAL_VALUES)LinearGradientRadialGradientc             C   s~   t j| \}}| stt }d}tt||}W dQ R X |rbt|dksPt||d ksltn
| slttdd |D S )z7Helper to test shorthand properties expander functions.zhttp://weasyprint.org/foo/Nr   r   c             s   s$   | ]\}}}|d kr||fV  qdS )initialN ).0namevalueZ	_priorityr   r   d/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/tests/test_css_validation.py	<genexpr>'   s    z!expand_to_dict.<locals>.<genexpr>)r	   Zparse_style_attrAssertionErrorr   listr
   lendict)cssZexpected_errorZdeclarationserrorsZlogsZbase_urlr   r   r   expand_to_dict   s    

r   invalidc             C   s   t | |i kstd S )N)r   r   )r   messager   r   r   assert_invalid+   s    r   c               C   s   t ddi kstd S )Nz
volume: 42z/the property does not apply for the print media)r   r   r   r   r   r   test_not_print/   s    r   c               C   sB   t ddddddgiksttd td	d
 td td d S )Nz clip: rect(1px, 3em, auto, auto)Zclipr   px   emautoz"clip: square(1px, 3em, auto, auto)zclip: rect(1px, 3em, auto auto)r   zclip: rect(1px, 3em, auto)zclip: rect(1px, 3em / auto))r   r    )r!   r"   )r   r   r   r   r   r   r   test_function5   s    
r$   c               C   s   t dddddgikstt dd	dddgiks4tt dddgiksJtt dddgiks`tt dd	dd d!giksztt ddg ikstt ddi kstt ddi ksttd td d S )"Nzcounter-reset: foo bar 2 bazZcounter_resetfoor   barr   bazz counter-increment: foo bar 2 bazZcounter_incrementr   zcounter-reset: foozcounter-reset: FoOFoOz counter-increment: foo bAr 2 BarbArBarzcounter-reset: nonezcounter-reset: foo nonezInvalid counter namezcounter-reset: foo initialzcounter-reset: foo 3pxzcounter-reset: 3)r%   r   )r&   r   )r'   r   )r%   r   )r&   r   )r'   r   )r%   r   )r(   r   )r%   r   )r)   r   )r*   r   )r   r   r   r   r   r   r   test_counters?   s$    r+   c               C   sv   t dddikstt dddiks(ttd t dd	i ksBtt d
ddiksVtt dddiksjttd d S )Nzletter-spacing: normalZletter_spacingnormalzletter-spacing: 3pxr!   r    zletter-spacing: 3zletter_spacing: normalzdid you mean letter-spacingzword-spacing: normalZword_spacingzword-spacing: 3pxzword-spacing: 3)r!   r    )r!   r    )r   r   r   r   r   r   r   test_spacingU   s    r-   c               C   sN   t dddikstt ddtdgiks.tt ddtddgiksJtd S )Nztext-decoration: noneZtext_decorationnoneztext-decoration: overlineZoverlinez,text-decoration: overline blink line-throughzline-through)r   r   	frozensetr   r   r   r   test_decorationf   s    r0   c               C   s   t dddikstt dddiks(tt ddd iks<tt ddd#iksPtt ddd&iksdtt ddd)iksxtt ddd,ikstt ddd/ik stt ddd2ik sttd td td td td d S )3Nzsize: 200pxsize   r    zsize: 200px 300pt,  ptz
size: auto   mm)  zsize: portraitzsize: landscapezsize: A3 portrait  zsize: A3 landscapezsize: portrait A3zsize: landscape A3zsize: A3 landscape A3zsize: A9z	size: foozsize: foo barz	size: 20%r2   r    r2   r    )r9   r:   r2   r    r3   r4   )r;   r<   r5   r6   r7   r6   )r=   r>   r5   r6   r7   r6   )r?   r@   r7   r6   r5   r6   )rA   rB   r7   r6   r8   r6   )rC   rD   r8   r6   r7   r6   )rE   rF   r7   r6   r8   r6   )rG   rH   r8   r6   r7   r6   )rI   rJ   )r   r   r   r   r   r   r   	test_sizeq   s.    rK   c               C   s   t ddg ikstt ddddtjd	 fgiks6tt d
dd giksLtt ddd$giksbtt ddd&giksxttd td td td td tdd d S )'Nztransform: none	transformz'transform: translate(6px) rotate(90deg)	translate   r    r   rotater   ztransform: translate(-4px, 0)   ztransform: translate(6px, 20%)   %ztransform: scale(2)scaleztransform: translate(6px 20%)ztransform: lipsumize(6px)ztransform: fooztransform: scale(2) fooztransform: 6pxz-weasy-transform: nonez*the property was unprefixed, use transformrN   r    r   r    rT   rU   )rM   rV   rW   r    r   NrX   rY   )rM   rZ   rN   r    rQ   rR   r[   r\   )rM   r]   r   r   )rS   r^   )r   r   mathpir   r   r   r   r   test_transforms   s,    ra   c               C   s   t ddddddkstt ddddddks4tt dd dd!ddksNtt dd"d#d$d%dkshtt dd&d'd(d)dkstt dd*d+d,d-dkstt ddi ksttd td td td td dS ).zTest the 4-value properties.zmargin: inheritinherit)Z
margin_topZmargin_rightZmargin_bottomZmargin_leftzmargin: 1emr   r"   zmargin: -1em auto 20%r#   rQ   rR   zpadding: 1em 0r   N)Zpadding_topZpadding_rightZpadding_bottomZpadding_leftzpadding: 1em 0 2%r   zpadding: 1em 0 2em 5px   r    zpadding: 1 2 3 4 5z&Expected 1 to 4 token components got 5zmargin: rgb(0, 0, 0)zpadding: autozpadding: -12pxzborder-width: -3emzborder-width: 12%)r   r"   )r   r"   )r   r"   )r   r"   )rd   r"   )rQ   rR   )r   r"   )r   N)r   r"   )r   N)r   r"   )r   N)r   rR   )r   N)r   r"   )r   N)r   r"   )rc   r    )r   r   r   r   r   r   r   test_expand_four_sides   sL    re   c               C   s   t dddddkstt dddd	ks.tt d
dddksDtt dddiksXtt ddddddddddd dd!dksttd dS )"zTest the ``border`` property.zborder-top: 3px dotted redr!   r    Zdottedr   r   )border_top_widthborder_top_styleborder_top_colorzborder-top: 3px dotted)rf   rg   zborder-top: 3px red)rf   rh   zborder-top: solidrg   Zsolidzborder: 6px dashed limerN   Zdashed)rf   rg   rh   Zborder_left_widthZborder_left_styleZborder_left_colorZborder_bottom_widthZborder_bottom_styleZborder_bottom_colorZborder_right_widthZborder_right_styleZborder_right_colorzborder: 6px dashed leftN)r!   r    )r   r   r   r   )r!   r    )r!   r    )r   r   r   r   )rN   r    )r   r   r   r   )rN   r    )r   r   r   r   )rN   r    )r   r   r   r   )rN   r    )r   r   r   r   )r   r   r   r   r   r   r   test_expand_borders   s4    ri   c               C   s   t dddddkstt dddiks,tt dd	d
iks@tt ddddksVtt dddddksntt dddddksttd td tdd dS )z!Test the ``list_style`` property.zlist-style: inheritrb   )list_style_positionlist_style_imagelist_style_typez"list-style: url(../bar/lipsum.png)rk   url$http://weasyprint.org/bar/lipsum.pngzlist-style: squarerl   Zsquarezlist-style: circle insideZinsidecircle)rj   rl   zlist-style: none circle insider.   Nzlist-style: none inside nonez!list-style: none inside none nonezlist-style: redzlist-style: circle discz2got multiple type values in a list-style shorthand)rm   rn   )r.   N)r.   N)r   r   r   r   r   r   r   test_expand_list_style   s.    rp   c             K   s   t d|  }|jd|jdtd ks*tt|d }x&|j D ]\}}|j||ks@tq@W x(|j D ]\}}|t| | kshtqhW dS )z*Helper checking the background properties.zbackground: background_colorbackground_imageN)r   popr   r   r   items)r   expectedexpandedZ	nb_layersr   r   r   r   r   assert_background   s    rw   c               C   s  t ddEd t ddFgd t d	dGgd
 t ddgd t ddHgdgd t ddKgd t ddNgd t ddQgd t ddTgd t ddUgdXgd t ddYgd\gd t dd]gd`gd t d dagddgd t d!dedfgdggdgdjgd# t d$dkdngd' t d(dgdqgd* t d+d,gdtgdud- t d.dvgdygdzd- t d0d|gdgd2 t d3dgdgd2 t d7dd8gd8gd9 t d:dd;gd8gd9 t d<dddgddgddgd? td@ tdA tdB tdC tdD d>S )z!Test the ``background`` property.redr   r   )rq   zurl(lipsum.png)rm   $http://weasyprint.org/foo/lipsum.png)rr   	no-repeat)background_repeatZfixed)background_attachmentzrepeat no-repeat fixedrepeat)r{   r|   topleft2   rR   )background_positionz	top rightd   ztop right 20pxrightrQ   r    ztop 1% right 20pxztop no-repeat)r{   r   ztop right no-repeatztop right 20px no-repeatztop 1% right 20px no-repeatz(url(bar) #f00 repeat-y center left fixedhttp://weasyprint.org/foo/bar)rq   rr   r{   r|   r   z#00f 10% 200px
   r2   )rq   r   zright 78px fixedN   )r|   r   zcenter / cover redZcover)background_sizer   rq   zcenter / auto redr#   zcenter / 42px*   )r   r   zcenter / 7% 4em   rP   r"   zred content-boxzcontent-box)rq   Zbackground_originZbackground_clipzred border-box content-boxz
border-boxzurl(bar) center, no-repeatr.   N)rq   rr   r   r{   zbackground: 10px lipsumz background-position: 10px lipsumz'background: content-box red content-boxz2background-image: inexistent-gradient(blue, green)zbackground: red, url(foo))r   r   r   r   )rm   ry   )rz   rz   )r}   rz   r   rR   r   rR   )r   r   r~   r   r   rR   r   rR   )r   r   r~   r   rQ   r    r   rR   )r   r   r~   r   rQ   r    r   rR   )r   r   r~   r   )rz   rz   r   rR   r   rR   )r   r   r~   r   )rz   rz   r   rR   r   rR   )r   r   r~   r   )rz   rz   rQ   r    r   rR   )r   r   r~   r   )rz   rz   rQ   r    r   rR   )r   r   r~   r   )r   r   r   r   )rm   r   )rz   r}   r   rR   r   rR   )r   r   r~   r   )r   r   r   r   r   rR   r2   r    )r   r   r~   r   r   rR   r   r    )r   r   r~   r   r   rR   r   rR   )r   r   r~   r   )r   r   r   r   )r#   r#   r   rR   r   rR   )r   r   r~   r   )r   r   r   r   r   r    )r   r#   r   rR   r   rR   )r   r   r~   r   r   rR   rP   r"   )r   r   r   rR   r   rR   )r   r   r~   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )rm   r   )r.   Nr   rR   r   rR   )r   r   r~   r   r   rR   r   rR   )r   r   r~   r   )r}   r}   )rz   rz   )rw   r   r   r   r   r   test_expand_background,  s    

















r   c              C   s  dd } xJd;D ]B\}}x(dFD ] \}}| d||f d|d| qW | |d|ddG qW | dddHddI | dddJddK | dddLddM | dddNddO | dddPddQ | dddRddS | dddTddU | dddVddW | dddXddY | dddZdd[ | ddd\dd] | d dd^dd_ | d!dd`dda | d"ddbddc | d#ddddde | d$ddfddg | d%ddhddi | d&ddjddk | d'ddlddm | d)ddnddo | d*ddpddq | d+ddrdds t d, t d- t d. t d/ d0S )tz*Test the ``background-position`` property.c             W   s4   t d|  j \\}\}|dks$t||ks0td S )Nzbackground-position:r   )r   rt   r   )r   ru   r   r   r   r   r   position  s    z1test_expand_background_position.<locals>.positionr   r   rR   centerr   r   r   4.5%      @12px   r    r~   bottom7%r   1.5px      ?z%s %szcenter top 10%r   ztop 10% centerzcenter bottom 10%zbottom 10% centerzright top 10%ztop 10% rightzright bottom 10%zbottom 10% rightzcenter left 10%zleft 10% centerzcenter right 10%zright 10% centerzbottom left 10%zleft 10% bottomzbottom right 10%zright 10% bottomzleft 10% bottom 3pxr!   zbottom 3px left 10%zright 10% top 3pxztop 3px right 10%z$background-position: left center 3pxzbackground-position: 3px leftzbackground-position: bottom 4%zbackground-position: bottom topNr   rR   r   r   r   rR   r   r   r   rR   r   r   r   rR   r   r   r   r    r   r   )r   r   r   r   r   r   rR   r~   r   r   rR   r   r   r   rR   r   r   r   rR   r   r   r   r    r   r   )r   r   r   r   r   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r   rR   )r!   r    )r   rR   )r!   r    )r   rR   )r!   r    )r   rR   )r!   r    )r   )r   Zcss_xZval_xZcss_yZval_yr   r   r   test_expand_background_position  sF      r   c               C   s   t ddddgdkstt ddd ddgdks6tt ddddddgdksTtt ddddddgdksrttd td td tdd td td td td d
S )!zTest the ``font`` property.zfont: 12px My Fancy Font, serifr   r    zMy Fancy FontZserif)	font_sizefont_familyz"font: small/1.2 "Some Font", serifZsmall333333?Nz	Some Font)r   line_heightr   z'font: small-caps italic 700 large serifZitalicz
small-capsi  Zlarge)Z
font_stylefont_variantfont_weightr   r   z1font: small-caps condensed normal 700 large serifZ	condensed)Zfont_stretchr   r   r   r   zfont-family: "My" Font, serifzfont-family: "My" "Font", serifzfont-family: "My", 12pt, serifz
font: menuzSystem fonts are not supportedz font: 12deg My Fancy Font, serifz
font: 12pxzfont: 12px/foo serifzfont: 12px "Invalid" family)r   r    )r   N)r   r   r   r   r   r   r   	test_font  s8    
r   c               C   s   t dddikstt dddiks(tt dddiks<tt d
ddiksPtt dddiksdtt dddiksxtt dddiksttd td td td td dS )z"Test the ``line-height`` property.zline-height: 1pxr   r   r    zline-height: 1.1%皙?rR   zline-height: 1emr"   zline-height: 1Nzline-height: 1.3?zline-height: -0r   zline-height: 0pxzline-height: 1degzline-height: -1pxzline-height: -1zline-height: -0.5%zline-height: 1px 1px)r   r    )r   rR   )r   r"   )r   N)r   N)r   N)r   r    )r   r   r   r   r   r   r   test_line_height  s    r   c            
   C   s  t dddd#gfgikstt dddd$gfgiks8tt dddd%gfgiksTtt dddd&gfdd'gfgiksxtt dddd(gfgikstt ddddddgfgfgikstt ddddddgfgfgikstt dddddddgfgfgikstt dddddddgfgfgiks,tt dddd)d*d+d,dddgfgfgiksZttd td td td  td! d"S )-z!Test the ``string-set`` property.z%-weasy-string-set: test content(text)Z
string_settestcontenttextz'-weasy-string-set: test content(before)beforez -weasy-string-set: test "string"STRINGstringz1-weasy-string-set: test1 "string", test2 "string"Ztest1Ztest2z#-weasy-string-set: test attr(class)attrclassz&-weasy-string-set: test counter(count)countercountZdecimalz3-weasy-string-set: test counter(count, upper-roman)zupper-romanz,-weasy-string-set: test counters(count, ".")Zcounters.z9-weasy-string-set: test counters(count, ".", upper-roman)zU-weasy-string-set: test content(text) "string" attr(title) attr(title) counter(count)titlez-weasy-string-set: testz-weasy-string-set: test test1z%-weasy-string-set: test content(test)z!-weasy-string-set: test unknown()z'-weasy-string-set: test attr(id, class)N)r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   r   r   r   r   r   test_string_set  sF    " r   c              C   s  d9} d:}d;}t j}|gd gfdd}dd }|d |d |d	 |d
 |d |d |dd|f |dd|f| gd g |dd|f||| gd<d d=g |d |dd|d f |dd> |dd|d f |dd|d f |dd?||| gd@d dAg |d |d |d |d dB |d!d|d f |d"d|f |d#d|d$ d f |d%d|d f||| gdCd dDg |d& |d' |d( |d) |d*dE |d-dF |d.dG |d0dH |d1dI |d3dJ |d4dK |d6dL |d7 |d8 d S )MNr   r   c       
      S   s   xd	D ]\}}t d|| f }|j \\}\\}}	|dks>tt|	tsLt|	j|ksZtt|	j|	jf|sptt|	j	|stt|	j
|stqW d S )
NF T
repeating-z'background-image: %slinear-gradient(%s)zlinear-gradientFr   Tr   )r   r   )r   rt   r   
isinstancer   	repeatingr   Zdirection_type	directioncolorsstop_positions)
r   r   r   r   r   prefixrv   _type_imager   r   r   gradient4  s    
z&test_linear_gradient.<locals>.gradientc             S   s   t d|   t d|   d S )Nz%background-image: linear-gradient(%s)z/background-image: repeating-linear-gradient(%s))r   )r   r   r   r   r   A  s    z%test_linear_gradient.<locals>.invalid z1% bluez
blue 10degzblue 4zsoylent-green 4pxzred 4px 2pxblueanglerx   zblue 1%, lime,red 2em rR   r   r"   Z18degz18deg, bluer   z
4rad, bluerP   z.25turn, bluez100grad, bluez12rad, blue 1%, lime,red 2em r   z10arc-minutes, bluez
10px, bluezto 90deg, bluezto top, bluezto right, bluezto bottom, bluezto left, bluer!   z to right, blue 1%, lime,red 2em zto the top, bluezto up, bluezinto top, bluez	top, bluezto top left, bluecornertop_leftzto left top, bluezto top right, blue	top_rightzto right top, bluezto bottom left, bluebottom_leftzto left bottom, bluezto bottom right, bluebottom_rightzto right bottom, bluezto bottom up, bluezbottom left, blue)r   r   r   r   )r   r   r   r   )r   r   r   r   )r   rR   )r   r"   )r   rP   )r   r   )r   rR   )r   r"   )r   r   )r   rR   )r   r"   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r   r   )r_   r`   )rx   limer   r`   r   r   r   r   r   test_linear_gradient-  s\    










r   c               C   s<   t dddikstt dddiks(ttd td d S )Nzoverflow-wrap: normaloverflow_wrapr,   zoverflow-wrap: break-wordz
break-wordzoverflow-wrap: nonez!overflow-wrap: normal, break-word)r   r   r   r   r   r   r   test_overflow_wrapo  s    r   c               C   s<   t dddikstt dddiks(ttd td d S )Nzword-wrap: normalr   r,   zword-wrap: break-wordz
break-wordzword-wrap: nonezword-wrap: normal, break-word)r   r   r   r   r   r   r   test_expand_word_wrapy  s    r   c           	   C   s  dD} dE}dF}ddGdJ|gd gfd
d}dd }|d |d |d |d |d |d |d |d| gd |d||| gdKd dLgd |dd |dd |d |d |d |d  |d!ddM |d#ddN |d%ddO |d&ddP |d(ddT |d,ddX |d-dd\ |d. |d/ |d0dd` |d3ddd |d4ddh |d5 |d6 |d7 |d8 |d9 |d0ddl |d: |d;dod= |d>ddrd@ |dAddud@ |dBddvdydC d S )zNr   r   Zellipsekeywordfarthest-cornerr   r   rR   r~   c             S   s   xd	D ]\}}t d|| f }|j \\}	\\}
}|
dks>tt|tsLt|j|ksZt|j|kshtt|j|j	f|s~tt|j
|stt|j|stt|j|stqW d S )
NFr   T
repeating-z'background-image: %sradial-gradient(%s)zradial-gradientFr   Tr  )r  r  )r   rt   r   r   r   r   shaper   Z	size_typer1   r   r   r   )r   r  r1   r   r   r   r   r   rv   r   r   r   r   r   r   r     s    z&test_radial_gradient.<locals>.gradientc             S   s   t d|   t d|   d S )Nz%background-image: radial-gradient(%s)z/background-image: repeating-radial-gradient(%s))r   )r   r   r   r   r     s    z%test_radial_gradient.<locals>.invalidr   z1% bluez
blue 10degzblue 4zsoylent-green 4pxzred 4px 2pxr   rx   )r   zblue 1%, lime,red 2em r   r"   )r   r   zcircle, bluero   zellipse, bluezsquare, bluezclosest-triangle, bluezcenter, bluezellipse closest-corner, blueclosest-cornerzcircle closest-side, blueclosest-sidezfarthest-corner circle, bluezfarthest-side, bluefarthest-sidez	5ch, blueexplicitrc   chz5ch circle, bluezcircle 5ch, bluezellipse 5chz5ch ellipsez10px 50px, bluer   r    z10px 50px ellipse, bluezellipse 10px 50px, bluezcircle 10px 50px, bluez10px 50px circle, bluez	10%, bluez10% circle, bluezcircle 10%, bluezat appex, bluezat top 10% right, bluer   )r   zcircle at bottom, bluer   )r  r   zcircle at 10px, bluez&closest-side circle at right 5em, blue)r  r1   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r  r  r   rR   r   rR   )r   r  r~   r  )r   rR   )r   r"   )r  r  )r  r  )r  r  )r  r	  rc   r  rc   r  r  r  )r
  r  rc   r  rc   r  r  r  )r
  r  rc   r  rc   r  r  r  )r
  r  r   r    r   r    r  r  )r
  r  r   r    r   r    r  r  )r
  r  r   r    r   r    r  r  )r
  r  r   r    r   r    r   r!  )r
  r"  r   rR   r   rR   )r   r#  r~   r$  r   rR   r   rR   )r   r%  r~   r&  r   r    r   rR   )r   r'  r~   r(  )r  r  r   rR   rc   r"   )r   r)  r~   r*  r   )rx   r   r   r   r   r   r   r   test_radial_gradient  s|    

r+  )N)r   )'__doc__
__future__r   r   r_   Ztesting_utilsr   r   r   r   r	   r
   Zcss.propertiesr   Zimagesr   r   r   r   r   r$   r+   r-   r0   rK   ra   re   ri   rp   rw   r   r   r   r   r   r   r   r   r+  r   r   r   r   <module>   s8   


1'"f9'*B

