-
-
Notifications
You must be signed in to change notification settings - Fork 710
/
Copy pathtest_table.py
2914 lines (2703 loc) · 83.6 KB
/
test_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Tests for layout of tables."""
import pytest
from ..testing_utils import assert_no_logs, capture_logs, render_pages
@assert_no_logs
def test_inline_table():
page, = render_pages('''
<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
''')
html, = page.children
body, = html.children
line, = body.children
table_wrapper, text = line.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 0 + border-spacing
assert td_1.width == 20
assert td_2.position_x == 45 # 15 + 20 + border-spacing
assert td_2.width == 30
assert table.width == 80 # 20 + 30 + 3 * border-spacing
assert table_wrapper.margin_width() == 90 # 80 + 2 * margin
assert text.position_x == 90
@assert_no_logs
def test_implicit_width_table_col_percent():
# See https://github.com/Kozea/WeasyPrint/issues/169
page, = render_pages('''
<table>
<col style="width:25%"></col>
<col></col>
<tr>
<td></td>
<td></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
@assert_no_logs
def test_implicit_width_table_td_percent():
page, = render_pages('''
<table>
<tr>
<td style="width:25%"></td>
<td></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
@assert_no_logs
def test_layout_table_fixed_1():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 5 + border-spacing
assert td_1.width == 20
assert td_2.position_x == 45 # 15 + 20 + border-spacing
assert td_2.width == 40
assert table.width == 90 # 20 + 40 + 3 * border-spacing
@assert_no_logs
def test_layout_table_fixed_2():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 5 + border-spacing
assert td_1.width == 75 # 20 + ((200 - 20 - 40 - 3 * border-spacing) / 2)
assert td_2.position_x == 100 # 15 + 75 + border-spacing
assert td_2.width == 95 # 40 + ((200 - 20 - 40 - 3 * border-spacing) / 2)
assert table.width == 200
@assert_no_logs
def test_layout_table_fixed_3():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row_1, row_2 = row_group.children
td_1, td_2 = row_1.children
td_3, td_4 = row_2.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 0 + border-spacing
assert td_3.position_x == 15
assert td_1.width == 40
assert td_2.width == 40
assert td_2.position_x == 65 # 15 + 40 + border-spacing
assert td_4.position_x == 65
assert td_3.width == 40
assert td_4.width == 40
assert table.width == 110 # 20 + 40 + 3 * border-spacing
@assert_no_logs
def test_layout_table_fixed_4():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 10 # 0 + margin-left
assert td_1.position_x == 10
assert td_1.width == 80 # 100 - 20
assert td_2.position_x == 90 # 10 + 80
assert td_2.width == 20
assert table.width == 100
@assert_no_logs
def test_layout_table_fixed_5():
# With border-collapse
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 0
assert table.border_left_width == 5 # half of the collapsed 10px border
assert td_1.position_x == 5 # border-spacing is ignored
assert td_1.margin_width() == 30 # as <col>
assert td_1.width == 20 # 30 - 5 (border-left) - 1 (border-right) - 2*2
assert td_2.position_x == 35
assert td_2.width == 34
assert td_2.margin_width() == 60 # 34 + 2*10 + 5 + 1
assert table.width == 90 # 30 + 60
assert table.margin_width() == 100 # 90 + 2*5 (border)
@assert_no_logs
def test_layout_table_auto_1():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table_wrapper.width == 38 # Same as table, see below
assert table_wrapper.margin_left == 31 # 0 + margin-left = (100 - 38) / 2
assert table_wrapper.margin_right == 31
assert table.position_x == 31
assert td_1.position_x == 41 # 31 + spacing
assert td_1.width == 4
assert td_2.position_x == 55 # 31 + 4 + spacing
assert td_2.width == 4
assert table.width == 38 # 3 * spacing + 2 * 4
@assert_no_logs
def test_layout_table_auto_2():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 6 # 5 + border-spacing
assert td_1.width == 4
assert td_2.position_x == 17 # 6 + 4 + spacing + 2 * border
assert td_2.width == 8
assert table.width == 27 # 3 * spacing + 4 + 8 + 4 * border
@assert_no_logs
def test_layout_table_auto_3():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row1, row2 = row_group.children
td_11, td_12 = row1.children
td_21, td_22 = row2.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_11.position_x == td_21.position_x == 6 # 5 + spacing
assert td_11.width == td_21.width == 12
assert td_12.position_x == td_22.position_x == 19 # 6 + 12 + spacing
assert td_12.width == td_22.width == 8
assert table.width == 23 # 3 * spacing + 12 + 8
@assert_no_logs
def test_layout_table_auto_4():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row1, row2 = row_group.children
td_11, td_12 = row1.children
td_21, td_22 = row2.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_11.position_x == td_21.position_x == 6 # 5 + spacing
assert td_11.width == 12 # 4 + 2 * 5 - 2 * 1
assert td_21.width == 4
assert td_12.position_x == td_22.position_x == 21 # 6 + 4 + 2 * b1 + sp
assert td_12.width == 4
assert td_22.width == 10 # 4 + 2 * 3
assert table.width == 27 # 3 * spacing + 4 + 4 + 2 * b1 + 2 * b2
@assert_no_logs
def test_layout_table_auto_5():
page, = render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
* { font-family: weasyprint }
</style>
<table style="width: 1000px; font-family: weasyprint">
<tr>
<td style="width: 40px">aa aa aa aa</td>
<td style="width: 40px">aaaaaaaaaaa</td>
<td>This will take the rest of the width</td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2, td_3 = row.children
assert table.width == 1000
assert td_1.width == 40
assert td_2.width == 11 * 16
assert td_3.width == 1000 - 40 - 11 * 16
@assert_no_logs
def test_layout_table_auto_6():
page, = render_pages('''
<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>
''')
# Preferred minimum width is 2 * 4 + 3 * 1 = 11
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row1, row2 = row_group.children
td_11, td_12 = row1.children
td_21, = row2.children
assert table_wrapper.position_x == 0
assert table.position_x == 0
assert td_11.position_x == td_21.position_x == 1 # spacing
assert td_11.width == td_21.width == 4 # minimum width
assert td_12.position_x == 6 # 1 + 5 + sp
assert td_12.width == 14 # available width
assert table.width == 21
@assert_no_logs
def test_layout_table_auto_7():
page, = render_pages('''
<table style="border-spacing: 10px; margin: 5px">
<colgroup>
<col style="width: 20px" />
</colgroup>
<tr>
<td></td>
<td style="width: 40px">a</td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 0 + border-spacing
assert td_1.width == 20
assert td_2.position_x == 45 # 15 + 20 + border-spacing
assert td_2.width == 40
assert table.width == 90 # 20 + 40 + 3 * border-spacing
@assert_no_logs
def test_layout_table_auto_8():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 5 + border-spacing
assert td_1.width == 20 # fixed
assert td_2.position_x == 45 # 15 + 20 + border-spacing
assert td_2.width == 70 # 120 - 3 * border-spacing - 20
assert table.width == 120
@assert_no_logs
def test_layout_table_auto_9():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row_1, row_2 = row_group.children
td_1, td_2 = row_1.children
td_3, td_4 = row_2.children
assert table_wrapper.position_x == 0
assert table.position_x == 5 # 0 + margin-left
assert td_1.position_x == 15 # 0 + border-spacing
assert td_3.position_x == 15
assert td_1.width == 60
assert td_2.width == 30
assert td_2.position_x == 85 # 15 + 60 + border-spacing
assert td_4.position_x == 85
assert td_3.width == 60
assert td_4.width == 30
assert table.width == 120 # 60 + 30 + 3 * border-spacing
@assert_no_logs
def test_layout_table_auto_10():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 10 # 0 + margin-left
assert td_1.position_x == 10
assert td_1.width == 6 # 14 - 8
assert td_2.position_x == 16 # 10 + 6
assert td_2.width == 8 # maximum of the minimum widths for the column
assert table.width == 14
@assert_no_logs
def test_layout_table_auto_11():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row1, row2, row3 = row_group.children
td_11, td_12 = row1.children
td_21, td_22, td_23 = row2.children
td_31, td_32, td_33 = row3.children
assert table_wrapper.position_x == 0
assert table.position_x == 0
assert td_11.width == 10 # fixed
assert td_12.width == 28 # 38 - 10
assert td_21.width == 22 # fixed
assert td_22.width == 8 # fixed
assert td_23.width == 8 # fixed
assert td_31.width == 10 # same as first line
assert td_32.width == 12 # 22 - 10
assert td_33.width == 16 # 8 + 8 from second line
assert table.width == 38
@assert_no_logs
def test_layout_table_auto_12():
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row1, row2, row3 = row_group.children
td_11, td_12 = row1.children
td_21, td_22, td_23 = row2.children
td_31, td_32, td_33 = row3.children
assert table_wrapper.position_x == 0
assert table.position_x == 0
assert td_11.width == 10 # fixed
assert td_12.width == 48 # 32 - 10 - sp + 2 * 8 + 2 * sp
assert td_21.width == 32 # fixed
assert td_22.width == 8 # fixed
assert td_23.width == 8 # fixed
assert td_31.width == 10 # same as first line
assert td_32.width == 12 # 32 - 10 - sp
assert td_33.width == 26 # 2 * 8 + sp
assert table.width == 88
@assert_no_logs
def test_layout_table_auto_13():
# Regression tests: these used to crash
page, = render_pages('''
<table style="width: 30px">
<tr>
<td colspan=2></td>
<td></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert td_1.width == 20 # 2 / 3 * 30
assert td_2.width == 10 # 1 / 3 * 30
assert table.width == 30
@assert_no_logs
def test_layout_table_auto_14():
page, = render_pages('''
<table style="width: 20px">
<col />
<col />
<tr>
<td></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, = row.children
assert td_1.width == 20
assert table.width == 20
@assert_no_logs
def test_layout_table_auto_15():
page, = render_pages('''
<table style="width: 20px">
<col />
<col />
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
column_group, = table.column_groups
column_1, column_2 = column_group.children
assert column_1.width == 0
assert column_2.width == 0
@assert_no_logs
def test_layout_table_auto_16():
# Absolute table
page, = render_pages('''
<table style="width: 30px; position: absolute">
<tr>
<td colspan=2></td>
<td></td>
</tr>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert td_1.width == 20 # 2 / 3 * 30
assert td_2.width == 10 # 1 / 3 * 30
assert table.width == 30
@assert_no_logs
def test_layout_table_auto_17():
# With border-collapse
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert table_wrapper.position_x == 0
assert table.position_x == 0
assert table.border_left_width == 5 # half of the collapsed 10px border
assert td_1.position_x == 5 # border-spacing is ignored
assert td_1.margin_width() == 30 # as <col>
assert td_1.width == 20 # 30 - 5 (border-left) - 1 (border-right) - 2*2
assert td_2.position_x == 35
assert td_2.width == 34
assert td_2.margin_width() == 60 # 34 + 2*10 + 5 + 1
assert table.width == 90 # 30 + 60
assert table.margin_width() == 100 # 90 + 2*5 (border)
@assert_no_logs
def test_layout_table_auto_18():
# Column widths as percentage
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert td_1.width == 140
assert td_2.width == 60
assert table.width == 200
@assert_no_logs
def test_layout_table_auto_19():
# Column group width
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2, td_3 = row.children
assert td_1.width == 100
assert td_2.width == 100
assert td_3.width == 100
assert table.width == 300
@assert_no_logs
def test_layout_table_auto_20():
# Multiple column width
page, = render_pages('''
<table style="width: 200px">
<colgroup>
<col style="width: 50px" />
<col style="width: 30px" />
<col />
</colgroup>
<tbody>
<tr>
<td>a</td>
<td>a</td>
<td>abc</td>
</tr>
</tbody>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2, td_3 = row.children
assert td_1.width == 50
assert td_2.width == 30
assert td_3.width == 120
assert table.width == 200
@assert_no_logs
def test_layout_table_auto_21():
# Fixed-width table with column group with widths as percentages and pixels
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2, td_3, td_4 = row.children
assert td_1.width == 100
assert td_2.width == 100
assert td_3.width == 150
assert td_4.width == 150
assert table.width == 500
@assert_no_logs
def test_layout_table_auto_22():
# Auto-width table with column group with widths as percentages and pixels
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2, td_3, td_4 = row.children
assert td_1.width == 50
assert td_2.width == 50
assert td_3.width == 200
assert td_4.width == 200
assert table.width == 500
@assert_no_logs
def test_layout_table_auto_23():
# Wrong column group width
page, = render_pages('''
<table style="width: 200px">
<colgroup style="width: 20%">
<col />
<col />
</colgroup>
<tbody>
<tr>
<td>a</td>
<td>a</td>
</tr>
</tbody>
</table>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert td_1.width == 100
assert td_2.width == 100
assert table.width == 200
@assert_no_logs
def test_layout_table_auto_24():
# Column width as percentage and cell width in pixels
page, = render_pages('''
<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>
''')
html, = page.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
row_group, = table.children
row, = row_group.children
td_1, td_2 = row.children
assert td_1.width == 140
assert td_2.width == 60
assert table.width == 200