3
sĸW                 @   s   d Z ddlmZmZ ddlmZmZ ddlmZ	 ddl
mZm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eddd Zedd Zedd ZdS )z
    weasyprint.tests.tables
    -----------------------

    Tests for layout of tables.

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

    )divisionunicode_literals   )assert_no_logscapture_logs)render_pages)requires_cairoassert_pixelsc              C   s   t d\} | j\}|j\}|j\}|j\}}|j\}|j\}|j\}|j\}	}
|jdks\t|jdksjt|	jdksxt|	jdkst|
jdkst|
jdkst|jdkst|j d	kst|jd	kstd
S )z%Test the inline-table elements sizes.a2  
        <table style="display: inline-table; border-spacing: 10px;
                      margin: 5px">
            <tr>
                <td><img src=pattern.png style="width: 20px"></td>
                <td><img src=pattern.png style="width: 30px"></td>
            </tr>
        </table>
        foo
    r            -      P   Z   N)parsechildren
position_xAssertionErrorwidthmargin_width)pagehtmlbodylinetable_wrappertexttable	row_grouprowtd_1td_2 r"   \/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/weasyprint/tests/test_tables.pytest_inline_table   s&    	

r$   c        	      C   s   t d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}t d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}dS )zTest table with implicit width.z
        <table>
            <col style="width:25%"></col>
            <col></col>
            <tr>
                <td></td>
                <td></td>
            </tr>
        </table>
    z
        <table>
            <tr>
                <td style="width:25%"></td>
                <td></td>
            </tr>
        </table>
    N)r   r   )	r   r   r   r   r   r   r   r    r!   r"   r"   r#   test_implicit_width_table4   s$    	
r%   c              C   s
  t d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdksRt|jdks`t|jdksnt|jdks|t|jdkst|jdkst|jdkstt d	\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jdkst|jdkst|jd
ks(t|jdks8t|jdksHt|jdksXtt d\} | j\}|j\}|j\}|j\}|j\}|j\}	}
|	j\}}|
j\}}|jdkst|jdkst|jdkst|jdkst|jdkst|jdkst|jdkst|jdks(t|jdks8t|jdksHt|jdksXtt d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jdkst|jdkst|jdkst|jdkst|jdkst|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdks`t|jdkspt|jdkst|jdkst|j dkst|jdkst|jdkst|jdkst|j dkst|jdkst|j dkstdS )z+Test the fixed layout table elements sizes.a@  
        <table style="table-layout: fixed; border-spacing: 10px;
                      margin: 5px">
            <colgroup>
              <col style="width: 20px" />
            </colgroup>
            <tr>
                <td></td>
                <td style="width: 40px">a</td>
            </tr>
        </table>
    r   r
   r   r   r   (   r   a	  
        <table style="table-layout: fixed; border-spacing: 10px;
                      width: 200px; margin: 5px">
            <tr>
                <td style="width: 20px">a</td>
                <td style="width: 40px"></td>
            </tr>
        </table>
    K   d   _      aw  
        <table style="table-layout: fixed; border-spacing: 10px;
                      width: 110px; margin: 5px">
            <tr>
                <td style="width: 40px">a</td>
                <td>b</td>
            </tr>
            <tr>
                <td style="width: 50px">a</td>
                <td style="width: 30px">b</td>
            </tr>
        </table>
    A   n   ab  
        <table style="table-layout: fixed; border-spacing: 0;
                      width: 100px; margin: 10px">
            <colgroup>
              <col />
              <col style="width: 20px" />
            </colgroup>
            <tr>
                <td></td>
                <td style="width: 40px">a</td>
            </tr>
        </table>
    
   r   a  
        <style>
          /* Do not apply: */
          colgroup, col, tbody, tr, td { margin: 1000px }
        </style>
        <table style="table-layout: fixed;
                      border-collapse: collapse; border: 10px solid;
                      /* ignored with collapsed borders: */
                      border-spacing: 10000px; padding: 1000px">
            <colgroup>
              <col style="width: 30px" />
            </colgroup>
            <tbody>
              <tr>
                <td style="padding: 2px"></td>
                <td style="width: 34px; padding: 10px; border: 2px solid"></td>
              </tr>
            </tbody>
        </table>
    r   #   "   <   N)r   r   r   r   r   border_left_widthr   )r   r   r   r   r   r   r   r    r!   row_1row_2td_3td_4r"   r"   r#   test_fixed_layout_table[   s    






r6   c        !      C   s  t d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdksRt|jdks`t|jdksnt|jdks|t|jdkst|jdkst|jdkst|jdkst|jdkst|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdks$t|jd	ks4t|jd
ksDt|jdksTt|jdksdt|jdkstt|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}	}
|	j\}}|
j\}}|jdkst|jd	kst|j|j  kod
kn  st|j|j  ko0dkn  s<t|j|j  koTdkn  s`t|j|j  koxdkn  st|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}	}
|	j\}}|
j\}}|jdkst|jd	kst|j|j  kod
kn  s(t|jdks8t|jdksHt|j|j  ko`dkn  slt|jdks|t|jdkst|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}	}
|	j\}}|
j\}|jdkst|jdks
t|j|j  ko"dkn  s.t|j|j  koFdkn  sRt|jd
ksbt|jdksrt|jdkstt d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jd	kst|jdkst|jdkst|jdkst|jdks&t|jdks6tt d\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jd	kst|jdkst|jdkst|jdkst|jdkst|jd kstt d!\} | j\}|j\}|j\}|j\}|j\}|j\}}|j\}}|j\}}|jdksJt|jd	ksZt|jdksjt|jdkszt|jd"kst|jd#kst|jd$kst|jd$kst|jd"kst|jd#kst|jd kstt d%\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdks>t|jdksNt|jdks^t|jd
ksnt|jd&ks~t|jdkst|jdkstt d'\} | j\}|j\}|j\}|j\}|j\}|j\}	}
}|	j\}}|
j\}}}|j\}}}|jdkst|jdkst|jdks.t|jd(ks>t|jd)ksNt|jdks^t|jdksnt|jdks~t|jdkst|jd&kst|jdkstt d*\} | j\}|j\}|j\}|j\}|j\}|j\}	}
}|	j\}}|
j\}}}|j\}}}|jdk	st|jdk	s.t|jdk	s>t|jd+k	sNt|jd,k	s^t|jdk	snt|jdk	s~t|jdk	st|jdk	st|jd-k	st|jd.k	stt d/\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdk
st|jdk
s"t|jd#k
s2tt d0\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|jdk
st|jdk
stt d1\} | j\}|j\}|j\}|j\}|j\}|j\}}|jdk
st|jdk
stt d2\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdksDt|jdksTt|jd#ksdtt d3\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jdkst|jd	kst|jd	kst|j	 d#kst|jdks
t|jd4kst|jd5ks*t|j	 d"ks<t|jdksLt|j	 d6ks^tt d7\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jd8kst|jd"kst|jd9kstt d:\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}}|jd6ks(t|jd6ks8t|jd6ksHt|jd;ksXtt d<\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}}}|jd6kst|jd6kst|jd=kst|jd=kst|jd>kstt d?\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}}}|jd@ksHt|jd@ksXt|jd9ksht|jd9ksxt|jd>kstt dA\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jd6kst|jd6kst|jd9kstt dB\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jd8ksPt|jd"ks`t|jd9ksptt dC\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jd8kst|jd"kst|jd9kstt dD\} t dE\} t dF\} t dG\} t dH\} t dI\} t dJ\} | j\}|j\}|j\}|j	 dKks\tt dL\} | j\}|j\}|j\}|j\}|j	 dKkst|j	 dKkstt dM\} | j\}|j\}|j\}|j\}|j	 dKkst|j	 dKkstt dN\} | j\}|j\}|j\}|j\}|j	 dKks4t|j	 dKksFtt dO\} t dP\} t dQ\} t dR\} t dS\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdkst|jd#kst|jd6kstt dT\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|jdks>t|jd#ksNt|jd6ks^tt dU\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|j\}}}|jd4kst|jd#kst|jd4kst|jd6kstt dV\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|j\}}}}}|jdksNt|jd#ks^t|jdksnt|jdks~t|jdkst|jd6kstt dW\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}}|j\}}}}}|j\}}}|jdkst|jd;kst|jdXks.t|jdYks>t|jdksNt|jdZks^t|jdXksnt|jd[ks~t|jd\kstt d]\} | j\}|j\}|j\}|j\}|j\}|j\}|j\}|j\} | jd9kst|jd9kst|jd^kstd_S )`z*Test the auto layout table elements sizes.z
        <body style="width: 100px">
        <table style="border-spacing: 10px; margin: auto">
            <tr>
                <td><img src=pattern.png></td>
                <td><img src=pattern.png></td>
            </tr>
        </table>
    r   &      )      7   an  
        <body style="width: 50px">
        <table style="border-spacing: 1px; margin: 10%">
            <tr>
                <td style="border: 3px solid black"><img src=pattern.png></td>
                <td style="border: 3px solid black">
                    <img src=pattern.png><img src=pattern.png>
                </td>
            </tr>
        </table>
    r
               a  
        <table style="border-spacing: 1px; margin: 5px; font-size: 0">
            <tr>
                <td></td>
                <td><img src=pattern.png><img src=pattern.png></td>
            </tr>
            <tr>
                <td>
                    <img src=pattern.png>
                    <img src=pattern.png>
                    <img src=pattern.png>
                </td>
                <td><img src=pattern.png></td>
            </tr>
        </table>
             a  
        <table style="border-spacing: 1px; margin: 5px">
            <tr>
                <td style="border: 1px solid black"><img src=pattern.png></td>
                <td style="border: 2px solid black; padding: 1px">
                    <img src=pattern.png>
                </td>
            </tr>
            <tr>
                <td style="border: 5px solid black"><img src=pattern.png></td>
                <td><img src=pattern.png></td>
            </tr>
        </table>
       r-   a  
        <style>
            @page { size: 100px 1000px; }
        </style>
        <table style="border-spacing: 1px; margin-right: 79px; font-size: 0">
            <tr>
                <td><img src=pattern.png></td>
                <td>
                    <img src=pattern.png> <img src=pattern.png>
                    <img src=pattern.png> <img src=pattern.png>
                    <img src=pattern.png> <img src=pattern.png>
                    <img src=pattern.png> <img src=pattern.png>
                    <img src=pattern.png>
                </td>
            </tr>
            <tr>
                <td></td>
            </tr>
        </table>
    r      a  
        <table style="border-spacing: 10px; margin: 5px">
            <colgroup>
              <col style="width: 20px" />
            </colgroup>
            <tr>
                <td></td>
                <td style="width: 40px">a</td>
            </tr>
        </table>
    r   r   r   r&   r   a+  
        <table style="border-spacing: 10px; width: 120px; margin: 5px;
                      font-size: 0">
            <tr>
                <td style="width: 20px"><img src=pattern.png></td>
                <td><img src=pattern.png style="width: 40px"></td>
            </tr>
        </table>
    F   x   aH  
        <table style="border-spacing: 10px; width: 110px; margin: 5px">
            <tr>
                <td style="width: 60px"></td>
                <td></td>
            </tr>
            <tr>
                <td style="width: 50px"></td>
                <td style="width: 30px"></td>
            </tr>
        </table>
    r0   r   U   a]  
        <table style="border-spacing: 0; width: 14px; margin: 10px">
            <colgroup>
              <col />
              <col style="width: 6px" />
            </colgroup>
            <tr>
                <td><img src=pattern.png><img src=pattern.png></td>
                <td style="width: 8px"></td>
            </tr>
        </table>
       a  
        <table style="border-spacing: 0">
            <tr>
                <td style="width: 10px"></td>
                <td colspan="3"></td>
            </tr>
            <tr>
                <td colspan="2" style="width: 22px"></td>
                <td style="width: 8px"></td>
                <td style="width: 8px"></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td colspan="2"></td>
            </tr>
        </table>
          a  
        <table style="border-spacing: 10px">
            <tr>
                <td style="width: 10px"></td>
                <td colspan="3"></td>
            </tr>
            <tr>
                <td colspan="2" style="width: 32px"></td>
                <td style="width: 8px"></td>
                <td style="width: 8px"></td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td colspan="2"></td>
            </tr>
        </table>
    0          X   z
        <table style="width: 30px">
            <tr>
                <td colspan=2></td>
                <td></td>
            </tr>
        </table>
    z
        <table style="width: 20px">
            <col />
            <col />
            <tr>
                <td></td>
            </tr>
        </table>
    zb
        <table style="width: 20px">
            <col />
            <col />
        </table>
    z
        <table style="width: 30px; position: absolute">
            <tr>
                <td colspan=2></td>
                <td></td>
            </tr>
        </table>
    ay  
        <style>
          /* Do not apply: */
          colgroup, col, tbody, tr, td { margin: 1000px }
        </style>
        <table style="border-collapse: collapse; border: 10px solid;
                      /* ignored with collapsed borders: */
                      border-spacing: 10000px; padding: 1000px">
            <colgroup>
              <col style="width: 30px" />
            </colgroup>
            <tbody>
              <tr>
                <td style="padding: 2px"></td>
                <td style="width: 34px; padding: 10px; border: 2px solid"></td>
              </tr>
            </tbody>
        </table>
    r.   r/   r(   aD  
        <table style="width: 200px">
            <colgroup>
              <col style="width: 70%" />
              <col style="width: 30%" />
            </colgroup>
            <tbody>
              <tr>
                <td>a</td>
                <td>abc</td>
              </tr>
            </tbody>
        </table>
       r*   aw  
        <table style="width: 200px">
            <colgroup style="width: 100px">
              <col />
              <col />
            </colgroup>
            <col style="width: 100px" />
            <tbody>
              <tr>
                <td>a</td>
                <td>a</td>
                <td>abc</td>
              </tr>
            </tbody>
        </table>
    i,  a  
        <table style="width: 500px">
            <colgroup style="width: 100px">
              <col />
              <col />
            </colgroup>
            <colgroup style="width: 30%">
              <col />
              <col />
            </colgroup>
            <tbody>
              <tr>
                <td>a</td>
                <td>a</td>
                <td>abc</td>
                <td>abc</td>
              </tr>
            </tbody>
        </table>
       i  a  
        <table>
            <colgroup style="width: 10%">
              <col />
              <col />
            </colgroup>
            <colgroup style="width: 200px">
              <col />
              <col />
            </colgroup>
            <tbody>
              <tr>
                <td>a a</td>
                <td>a b</td>
                <td>a c</td>
                <td>a d</td>
              </tr>
            </tbody>
        </table>
    2   a/  
        <table style="width: 200px">
            <colgroup style="width: 20%">
              <col />
              <col />
            </colgroup>
            <tbody>
              <tr>
                <td>a</td>
                <td>a</td>
              </tr>
            </tbody>
        </table>
    aE  
        <table style="width: 200px">
            <colgroup>
              <col style="width: 70%" />
              <col />
            </colgroup>
            <tbody>
              <tr>
                <td>a</td>
                <td style="width: 60px">abc</td>
              </tr>
            </tbody>
        </table>
    a  
        <div style="width: 400px">
            <table style="width: 50%">
                <colgroup>
                    <col style="width: 70%" />
                    <col />
                </colgroup>
                <tbody>
                    <tr>
                        <td>a</td>
                        <td style="width: 30%">abc</td>
                    </tr>
                </tbody>
            </table>
        </div>
    zj
        <table style="max-width: 300px">
            <td style="width: 400px"></td>
        </table>
    zf
        <table style="width: 300px">
            <td style="width: 400px"></td>
        </table>
    zx
        <table style="width: 300px; max-width: 350px">
            <td style="width: 400px"></td>
        </table>
    z
        <table style="width: 300px; max-width: 350px">
            <td style="padding: 50px">
                <div style="width: 300px"></div>
            </td>
        </table>
    zy
        <table style="max-width: 300px; margin: 100px">
            <td style="width: 400px"></td>
        </table>
    z{
        <table style="width: 300px; border-spacing: 2px">
            <td style="width: 299px"></td>
        </table>
    zu
        <table style="width: 300px; margin: 100px">
            <td style="width: 400px"></td>
        </table>
    iX  z
        <div style="float: left">
            <table style="min-width: 400px; margin: 100px">
                <td></td>
            </table>
        </div>
    zz
        <div style="float: left">
            <table style="min-width: 400px; margin: 100px"></table>
        </div>
    z
        <div style="float: left">
            <table style="max-width: 300px; margin: 100px">
                <td style="width: 400px"></td>
            </table>
        </div>
    zJ
        <table>
            <td style="width: 50%">
        </table>
    aq  
        <table>
          <tr>
            <td>
              <table>
                <tr>
                  <th>Test</th>
                </tr>
                <tr>
                  <td style="min-width: 100%;"></td>
                  <td style="width: 48px;"></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
    a  
        <table>
          <tr>
            <td>
              <table>
                <tr>
                  <td style="width: 100%;"></td>
                  <td style="width: 48px;">
                    <img src="http://weasyprint.org/samples/acid2-small.png">
                  </td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
    a+  
        <table>
          <tr>
            <td>
              <table style="display: inline-table">
                <tr>
                  <td style="width: 100%;"></td>
                  <td></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
    a9  
        <div style="width: 100px">
            <table>
                <tbody>
                    <tr>
                        <td>a a a a a a a a</td>
                        <td style="width: 30%">a a a a a a a a</td>
                    </tr>
                </tbody>
            </table>
        </div>
    z
        <table>
            <tbody>
                <tr>
                    <td style="width: 70px">a a a a a a a a</td>
                    <td style="width: 30%">a a a a a a a a</td>
                </tr>
            </tbody>
        </table>
    at  
        <div style="width: 100px">
            <table>
                <tbody>
                    <tr>
                        <td>a a a a a a a a</td>
                        <td style="width: 30%" colspan=2>a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                    </tr>
                </tbody>
            </table>
        </div>
    a  
        <div style="width: 100px">
            <table>
                <tbody>
                    <tr>
                        <td>a a a a a a a a</td>
                        <td style="width: 30%" colspan=2>a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                        <td style="width: 40%">a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                    </tr>
                </tbody>
            </table>
        </div>
    a  
        <div style="width: 1000px">
            <table>
                <tbody>
                    <tr>
                        <td>a a a a a a a a</td>
                        <td style="width: 30%">a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                        <td style="width: 40%">a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                    </tr>
                    <tr>
                        <td style="width: 31%" colspan=2>a a a a a a a a</td>
                        <td>a a a a a a a a</td>
                        <td style="width: 42%" colspan=2>a a a a a a a a</td>
                    </tr>
                </tbody>
            </table>
        </div>
    i  i  i6  i  i  a  
        <div style="position: absolute">
            <table style="margin: 50px; border: 20px solid black">
                <tr>
                    <td style="width: 200px; height: 200px"></td>
                </tr>
            </table>
        </div>
    iT  N)
r   r   r   r   r   margin_leftZmargin_rightZcolumn_groupsr1   r   )!r   r   r   r   r   r   r   r    r!   Zrow1Zrow2Ztd_11Ztd_12Ztd_21Ztd_22r2   r3   r4   r5   Zrow3Ztd_23Ztd_31Ztd_32Ztd_33Zcolumn_groupZcolumn_1Zcolumn_2ZdivZtd_5Ztd_13Ztd_14Ztd_15tdr"   r"   r#   test_auto_layout_table   s   





$$$$


$$

$$

















	

rT   c           
   C   s  d} t  }t| \}W d Q R X t|dks0t|d jdsBt|j\}|j\}|j\}|j\}|j\}|j\}}	}
|j|	j|
jg}t|jdkstt|	jdkstt|
jdkst|jdkst|jdkst|jdkst|j dkst|j	dkst|jdkst|j	dks&t|jd	ks6t|j	d
ksFt|j|jksXt|j	|j	ksjt|d d jd	kst|d d j	dkst|d d j
 dkst|d d jdkst|d d j
 dkst|d d j	dkst|d d jd	kst|d d j
 dks0t|d d j	dksHt|d d jdks`t|d d j
 dkszt|d d j	dkst|d d jdkst|d d j
 dkst|d d j	dkst|d d jdkst|d d j
 dkst|d d j	dks&t|d d jd	ks>t|d d j
 dksXt|d d j	dkspt|d d jdkst|d d j
 dkst|d d j	dkst|d d jdksttd\}|j\}|j\}|j\}|j\}|j\}|j\}|jd j	dks"t|jd j	dks8t|jd j	dksNt|j	dks^ttd\}|j\}|j\}|j\}|j\}|j\}|j\}|j\}}|j	dkst|j	dkst|j	dkst|j	|j	kstd S )Na	  
        <style>
            body { width: 20000px; margin: 0 }
            table {
              width: 10000px; margin: 0 auto; border-spacing: 100px 0;
              table-layout: fixed
            }
            td { border: 10px solid; padding: 1px }
        </style>
        <table>
            <col style="width: 10%">
            <tr>
                <td style="width: 30%" colspan=3>
                <td>
            </tr>
            <tr>
                <td>
                <td>
                <td>
                <td>
            </tr>
            <tr>
                <td>
                <td colspan=12>This cell will be truncated to grid width
                <td>This cell will be removed as it is beyond the grid width
            </tr>
        </table>
    r   r   zGWARNING: This table row has more columns than the table, ignored 1 cell   r:   i  i'  i  iH&  i  i  i   i  i   i  i  i8  i  iy  i+     i!  i!  a  
        <style>
            table { width: 1000px; border-spacing: 100px; table-layout: fixed }
        </style>
        <table>
            <tr>
                <td style="width: 50%">
                <td style="width: 60%">
                <td>
            </tr>
        </table>
    i  iX  i  a  
        <style>
            table { width: 1000px; border-spacing: 100px; table-layout: fixed }
            td { width: 60% }
        </style>
        <table>
            <tr>
                <td>
                <td>
            </tr>
        </table>
    )r   r   lenr   
startswithr   r   rR   Zcontent_box_xr   Zborder_widthZcolspan)sourceZlogsr   r   r   wrapperr   r   Z	first_rowZ
second_rowZ	third_rowcellsr   Zcell_1Zcell_2r"   r"   r#   test_table_column_width  s    
r\   c              C   s   t d\} | j\}|j\}|j\}|j\}|j\}|jdks@t|jdksNt|jdks\t|j|jkslt|jdkszt|jdkstdd |jD d	d
ddgkstdd |jD ddddgkstdd |jD ddddddgddgg dggkstdd |jD dd	d	d	d	d	gd
d
gg dggks.tdd |jD ddddd
dgddgg dggksbtdd |jD ddddd
dgddgg dggkstdd |jD ddddddgddgg dggkstt d\} | j\}|j\}|j\}|j\}|j\}d S )Na  
        <table style="width: 1000px; border-spacing: 0 100px;
                      font: 20px/1em serif; margin: 3px; table-layout: fixed">
            <tr>
                <td rowspan=0 style="height: 420px; vertical-align: top"></td>
                <td>X<br>X<br>X</td>
                <td><table style="margin-top: 20px; border-spacing: 0">
                    <tr><td>X</td></tr></table></td>
                <td style="vertical-align: top">X</td>
                <td style="vertical-align: middle">X</td>
                <td style="vertical-align: bottom">X</td>
            </tr>
            <tr>
                <!-- cells with no text (no line boxes) is a corner case
                     in cell baselines -->
                <td style="padding: 15px"></td>
                <td><div style="height: 10px"></div></td>
            </tr>
            <tr></tr>
            <tr>
                <td style="vertical-align: bottom"></td>
            </tr>
        </table>
    r   rV   il  g   i  c             S   s   g | ]
}|j qS r"   )height).0r   r"   r"   r#   
<listcomp>  s    z)test_table_row_height.<locals>.<listcomp>r   r   r-   c             S   s   g | ]
}|j qS r"   )
position_y)r_   r   r"   r"   r#   r`     s    i  i  i  c             S   s   g | ]}d d |j D qS )c             S   s   g | ]
}|j qS r"   )r^   )r_   cellr"   r"   r#   r`     s    z4test_table_row_height.<locals>.<listcomp>.<listcomp>)r   )r_   r   r"   r"   r#   r`     s   r0   r&   r   c             S   s   g | ]}d d |j D qS )c             S   s   g | ]}|j  qS r"   )border_height)r_   rb   r"   r"   r#   r`     s    z4test_table_row_height.<locals>.<listcomp>.<listcomp>)r   )r_   r   r"   r"   r#   r`     s   c             S   s   g | ]}d d |j D qS )c             S   s   g | ]
}|j qS r"   )Zpadding_top)r_   rb   r"   r"   r#   r`     s    z4test_table_row_height.<locals>.<listcomp>.<listcomp>)r   )r_   r   r"   r"   r#   r`     s   r   r
   c             S   s   g | ]}d d |j D qS )c             S   s   g | ]
}|j qS r"   )Zpadding_bottom)r_   rb   r"   r"   r#   r`     s    z4test_table_row_height.<locals>.<listcomp>.<listcomp>)r   )r_   r   r"   r"   r#   r`     s   c             S   s   g | ]}d d |j D qS )c             S   s   g | ]
}|j qS r"   )ra   )r_   rb   r"   r"   r#   r`     s    z4test_table_row_height.<locals>.<listcomp>.<listcomp>)r   )r_   r   r"   r"   r#   r`     s   a  
        <table style="border-spacing: 0">
            <tr style="height: 10px">
                <td rowspan=5></td>
                <td></td>
            </tr>
            <tr style="height: 10px">
                <td></td>
            </tr>
        </table>
    )r   r   ra   r   r^   )r   r   r   rZ   r   r   r"   r"   r#   test_table_row_heighte  sl    
rd   z1.12c              C   st  ddl m} m}m} tddd|| | | | | | | | | | | | | | | | | | | | | | | | | | | || | | | | | | | | | | | | | | | | | | | | | | | | | | || | | | |  | | |  | | |  | | |  | | | | | | | | | | |  | | || | | | |  | | |  | | | | | | | | | | | | | | | | | | | || |  | | | | | |  | | | | | | | | | | | | | | | | | | | || |  | | | | | |  | | |  | | |  | | | | | | | | | | |  | | || |  | | |  | | | | | |  | | |  | | |  |  | | |  |  | | |  | | || |  | | |  | | | | | |  | | |  | | |  |  | | |  |  | | |  | | || | | | | | | | | | | | | | | | | | | | | | | | | | | || | | | | | | | | | | | | | | | | | | | | | | | | | | g
d d S )Nr   )_rBZtable_vertical_alignrI   r-   a  
      <style>
        @page { size: 28px 10px }
        html { background: #fff; font-size: 1px; color: red }
        body { margin: 0; width: 28px; height: 10px }
        td {
          width: 1em;
          padding: 0 !important;
          border: 1px solid blue;
          line-height: 1em;
          font-family: ahem;
        }
      </style>
      <table style="border: 1px solid red; border-spacing: 0">
        <tr>
          <!-- Test vertical-align: top, auto height -->
          <td style="vertical-align: top">o o</td>

          <!-- Test vertical-align: middle, auto height -->
          <td style="vertical-align: middle">o o</td>

          <!-- Test vertical-align: bottom, fixed useless height -->
          <td style="vertical-align: bottom; height: 2em">o o</td>

          <!-- Test default vertical-align value (baseline),
               fixed useless height -->
          <td style="height: 5em">o o</td>

          <!-- Test vertical-align: baseline with baseline set by next cell,
               auto height -->
          <td style="vertical-align: baseline">o o</td>

          <!-- Set baseline height to 2px, auto height -->
          <td style="vertical-align: baseline; font-size: 2em">o o</td>

          <!-- Test padding-bottom, fixed useless height,
               set the height of the cells to 2 lines * 2em + 2px = 6px -->
          <td style="vertical-align: baseline; height: 1em;
                     font-size: 2em; padding-bottom: 2px !important">
            o o
          </td>

          <!-- Test padding-top, auto height -->
          <td style="vertical-align: top; padding-top: 0.5em !important">
            o o
          </td>
        </tr>
      </table>
    )	test_drawre   rf   rg   r	   )re   rf   rg   r"   r"   r#   test_table_vertical_align  s    nnnnnnnnnp1ri   c              C   s   t d\} | j\}|j\}|j\}|j\}|jdks8t|jdksFt|jdksTt|j dksdt|jdksrt|j dkst|jdkst|j dkst|jdkst|j dkstt d	\} d S )
Nz
        <style>
            @page { size: 1000px }
            table { width: 600px; height: 500px; table-layout: fixed;
                    padding: 1px; border: 10px solid; margin: 100px; }
        </style>
        <table></table>
    i  iX  r(   iB  i  i  i  z<html style="display: table">)	r   r   r   r   rR   r   rc   r^   Zmargin_height)r   r   r   rZ   r   r"   r"   r#   test_table_wrapper  s"    rj   c           	   C   s  dd } | d\}}|ddddgks(t |ddd	d
dd	d	d
gksDt | d\}}|d	ddgksbt |d	d
dd	gksvt | d\}}|d	ddgkst |d	d
dd	gkst | d\}}|ddgkst |dd	d
gkst td}g }xt|D ]\}}g }|j\}|j\}|j\}	|d	kr,|	jdkst nn|	j\}
xd|
jD ]Z}|jsPt dg }x4|jD ]*}|j\}|j\}|j\}|j|j q\W |j| q<W |j| qW |g dgdgdggdgddgdggdgdggdgggkst dS )z#Test the page breaks inside tables.c             S   s   t | }g }g }xt|D ]\}}|j\} | j\}|dkrJ|jdd  }n|j}|s`|jd q|\}|j\}	d}
xn|	jD ]d}|jstdxP|jD ]F}|
d7 }
|j|j |j\}|j\}|j\}|jdt| kstqW qzW |j|
 qW ||fS )Nr   r   zfound an empty table groupzrow %i)r   	enumerater   appendr   ra   r   rW   )r   pagesrows_per_pagerows_position_yir   r   Zbody_childrenr   r   Zrows_in_this_pagegroupr   rb   r   r   r"   r"   r#   run-  s4    
z#test_table_page_breaks.<locals>.runaa  
        <style>
            @page { size: 120px }
            table { table-layout: fixed; width: 100% }
            h1 { height: 30px }
            td { height: 40px }
        </style>
        <h1>Dummy title</h1>
        <table>
            <tr><td>row 1</td></tr>
            <tr><td>row 2</td></tr>

            <tr><td>row 3</td></tr>
            <tr><td>row 4</td></tr>
            <tr><td>row 5</td></tr>

            <tr><td style="height: 300px"> <!-- overflow the page -->
                row 6</td></tr>
            <tr><td>row 7</td></tr>
            <tr><td>row 8</td></tr>
        </table>
    rU   rV   r   r   rE   r   r&   r   a  
        <style>
            @page { size: 120px }
            h1 { height: 30px}
            td { height: 40px }
            table { table-layout: fixed; width: 100%;
                    page-break-inside: avoid }
        </style>
        <h1>Dummy title</h1>
        <table>
            <tr><td>row 1</td></tr>
            <tr><td>row 2</td></tr>
            <tr><td>row 3</td></tr>

            <tr><td>row 4</td></tr>
        </table>
    a  
        <style>
            @page { size: 120px }
            h1 { height: 30px}
            td { height: 40px }
            table { table-layout: fixed; width: 100%;
                    page-break-inside: avoid }
        </style>
        <h1>Dummy title</h1>
        <table>
            <tbody>
                <tr><td>row 1</td></tr>
                <tr><td>row 2</td></tr>
                <tr><td>row 3</td></tr>
            </tbody>

            <tr><td>row 4</td></tr>
        </table>
    a  
        <style>
            @page { size: 120px }
            h1 { height: 30px}
            td { height: 40px }
            table { table-layout: fixed; width: 100% }
        </style>
        <h1>Dummy title</h1>
        <table>
            <tr><td>row 1</td></tr>

            <tbody style="page-break-inside: avoid">
                <tr><td>row 2</td></tr>
                <tr><td>row 3</td></tr>
            </tbody>
        </table>
    a\  
        <style>
            @page { size: 100px }
        </style>
        <h1 style="margin: 0; height: 30px">Lipsum</h1>
        <!-- Leave 70px on the first page: enough for the header or row1
             but not both.  -->
        <table style="border-spacing: 0; font-size: 5px">
            <thead>
                <tr><td style="height: 20px">Header</td></tr>
            </thead>
            <tbody>
                <tr><td style="height: 60px">Row 1</td></tr>
                <tr><td style="height: 10px">Row 2</td></tr>
                <tr><td style="height: 50px">Row 3</td></tr>
                <tr><td style="height: 61px">Row 4</td></tr>
                <tr><td style="height: 90px">Row 5</td></tr>
            </tbody>
            <tfoot>
                <tr><td style="height: 20px">Footer</td></tr>
            </tfoot>
        </table>
    Zh1zfound an empty table groupHeaderzRow 1ZFooterzRow 2zRow 3zRow 4zRow 5N)r   r   rk   r   Zelement_tagrl   r   )rr   rn   ro   rm   rp   r   groupsr   r   r   r   rq   Zrowsr   rb   r   r   r"   r"   r#   test_table_page_breaks*  sX    





ru   N)__doc__
__future__r   r   Ztesting_utilsr   r   Z
test_boxesr   r   rh   r   r	   r$   r%   r6   rT   r\   rd   ri   rj   ru   r"   r"   r"   r#   <module>   s.    '        a eA