@@ -572,3 +572,94 @@ def test_partially_invalid_table(): # 107
572572def test_data_with_carriage_return (): # 107
573573 # this used to hang
574574 assert Table ('{|\n }\n \r ' ).data () == [[]]
575+
576+
577+ def test_row_attrs_getter ():
578+ # simple case
579+ assert Table (
580+ '{|\n '
581+ '|- style="background: black;"\n '
582+ '| cell1\n '
583+ '|- style="background: white;"\n '
584+ '| cell2\n '
585+ '|}'
586+ ).row_attrs == [
587+ {'style' : 'background: black;' },
588+ {'style' : 'background: white;' },
589+ ]
590+
591+ # multiple attrs on a row
592+ assert Table (
593+ '{|\n '
594+ '|-style="color: red;" bgcolor=yellow"\n '
595+ '| cell1\n '
596+ '|}'
597+ ).row_attrs == [
598+ {'style' : 'color: red;' , 'bgcolor' : 'yellow' },
599+ ]
600+
601+ # test middle row with no attrs
602+ assert Table (
603+ '{|\n '
604+ '|- style="background: black;"\n '
605+ '| cell1\n '
606+ '|-\n '
607+ '| cell2\n '
608+ '|- style="background: white;"\n '
609+ '| cell3\n '
610+ '|}'
611+ ).row_attrs == [
612+ {'style' : 'background: black;' },
613+ {},
614+ {'style' : 'background: white;' },
615+ ]
616+
617+
618+ def test_row_attrs_containing_comment ():
619+ assert Table (
620+ '{|\n '
621+ '|- style="color: red;" <!--comment--> bgcolor=yellow\n '
622+ '| cell1\n '
623+ '|}'
624+ ).row_attrs == [
625+ {'style' : 'color: red;' , 'bgcolor' : 'yellow' },
626+ ]
627+
628+
629+ def test_row_attrs_containing_template ():
630+ assert Table (
631+ '{|\n '
632+ '|- style={{text|"color: red;"}}\n '
633+ '| cell1\n '
634+ '|}'
635+ ).row_attrs == [
636+ {'style' : '{{text|"color: red;"}}' },
637+ ]
638+
639+
640+ def test_row_attrs_setter ():
641+ table = Table (
642+ '{|\n '
643+ '|- style="background: black;"\n '
644+ '| cell1\n '
645+ '|-\n '
646+ '| cell2\n '
647+ '|- style="background: white;"\n '
648+ '| cell3\n '
649+ '|}'
650+ )
651+ table .row_attrs = [
652+ {'style' : 'color: white;' },
653+ {'style' : 'color: black;' },
654+ {},
655+ ]
656+ assert table .string == (
657+ '{|\n '
658+ '|- style="color: white;"\n '
659+ '| cell1\n '
660+ '|- style="color: black;"\n '
661+ '| cell2\n '
662+ '|-\n '
663+ '| cell3\n '
664+ '|}'
665+ )
0 commit comments