-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtmlParseUT.py
118 lines (108 loc) · 2.73 KB
/
htmlParseUT.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
# -*- coding: utf-8 -*-
import unittest
import htmlParse
class HtmlParseUT(unittest.TestCase):
"""
Unit Test - HtmlParse
"""
def test_get_list_1(self):
"""
Simple case
"""
html = """
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
</tr>
</table>
"""
list_2d = htmlParse.table_to_list(html)
expected_list = [['1', '2'], ['a', 'b']]
self.assertEqual(expected_list, list_2d)
def test_get_list_2(self):
"""
Colspan
"""
html = """
<table>
<tr>
<td colspan=2>1</td>
<td>2</td>
</tr>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
</table>
"""
list_2d = htmlParse.table_to_list(html)
expected_list = [['1', '1', '2'], ['a', 'b', 'c']]
self.assertEqual(expected_list, list_2d)
def test_get_list_3(self):
"""
Rowspan
"""
html = """
<table>
<tr>
<td rowspan=2>1</td>
<td>2</td>
</tr>
<tr>
<td>a</td>
</tr>
</table>
"""
list_2d = htmlParse.table_to_list(html)
expected_list = [['1', '2'], ['1', 'a']]
self.assertEqual(expected_list, list_2d)
def test_get_list_4(self):
"""
Colspan + Rowspan
"""
html = """
<table>
<tr>
<td rowspan=2 colspan=2>1</td>
<td>2</td>
</tr>
<tr>
<td>a</td>
</tr>
</table>
"""
list_2d = htmlParse.table_to_list(html)
expected_list = [['1', '1', '2'], ['1', '1', 'a']]
self.assertEqual(expected_list, list_2d)
def test_get_list_5(self):
"""
Colspan + Rowspan complex
"""
html = """
<table>
<tr>
<td>1</td>
<td rowspan=3 colspan=2>2</td>
<td rowspan=3 colspan=2>3</td>
<td>4</td>
</tr>
<tr>
<td rowspan=2>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
</tr>
</table>
"""
list_2d = htmlParse.table_to_list(html)
expected_list = [['1', '2', '2', '3', '3', '4'], ['a', '2', '2', '3', '3', 'b'], ['a', '2', '2', '3', '3', 'c']]
self.assertEqual(expected_list, list_2d)
if __name__ == '__main__':
unittest.main()