1 #!/usr/bin/env python 2 3 from ImprovedTableParser import parse 4 5 table = """<tablestyle="border: 2px solid red; border-collapse: collapse;" rowstyle="background-color: #f77;"> 6 Test||Outcome||Comments 7 == 8 Colspan 9 ||<colspan="2"> Test a column with attributes 10 == 11 Normal || <style=" 12 text-align: center" colspan=1> Three columns || Adjacent column 13 == 14 Split 15 || Three columns 16 || Separate lines 17 == 18 * Item #1 19 * Item #2 20 || 21 * Item #A 22 || Not a list 23 == 24 \\{\\{\\{ 25 Some preformatted text. 26 \\}\\}\\} 27 ||<colspan="2"> Preformatted text in a separate section 28 == 29 == Heading 2 == 30 This is in the first column. 31 || And this is in the second. 32 == This, despite the == is in a new row. 33 || 34 And this is the second column. 35 == 36 Some \\{\\{\\{preformatted text\\}\\}\\} || Some `preformatted text` || Observe the region notation inline. 37 """ 38 39 attrs, rows = parse(table) 40 expected = 9 41 42 print table 43 print attrs 44 print rows 45 print len(rows) == expected, ": length is", len(rows), "==", expected 46 print 47 for (row_attrs, columns), expected in zip(rows, [3, 2, 3, 3, 3, 2, 2, 2, 3]): 48 print row_attrs 49 print columns 50 non_continuation_columns = [ 51 (column_attrs, content) 52 for (column_attrs, content) in columns 53 if not column_attrs.has_key("colcontinuation") 54 and not column_attrs.has_key("rowcontinuation") 55 and not content is None 56 ] 57 print len(non_continuation_columns) == expected, ": length is", len(non_continuation_columns), "==", expected 58 print 59 60 # vim: tabstop=4 expandtab shiftwidth=4