Repository navigation
Expand file tree
/
Copy pathlist_video_test.py
More file actions
72 lines (52 loc) · 2.15 KB
/
Copy pathlist_video_test.py
File metadata and controls
72 lines (52 loc) · 2.15 KB
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
from lxml import html
from html_convert import convert_to_outline_json
def convert(fragment: str):
tree = html.fromstring(f"<div>{fragment}</div>")
doc, _icon = convert_to_outline_json(tree)
return doc["content"]
def find_nodes(nodes, node_type):
found = []
for node in nodes:
if isinstance(node, dict):
if node.get("type") == node_type:
found.append(node)
found.extend(find_nodes(node.get("content", []), node_type))
return found
def test_plain_ordered_list():
(ol,) = find_nodes(convert("<ol><li>a</li><li>b</li></ol>"), "ordered_list")
assert ol["attrs"] == {"order": 1, "listStyle": "number"}
assert len(ol["content"]) == 2
def test_ordered_list_start_offset():
(ol,) = find_nodes(convert('<ol start="5"><li>a</li></ol>'), "ordered_list")
assert ol["attrs"]["order"] == 5
def test_ordered_list_lower_alpha_type():
(ol,) = find_nodes(convert('<ol type="a"><li>a</li></ol>'), "ordered_list")
assert ol["attrs"]["listStyle"] == "lower-alpha"
def test_ordered_list_upper_alpha_style():
(ol,) = find_nodes(
convert('<ol style="list-style-type: upper-alpha"><li>a</li></ol>'),
"ordered_list",
)
assert ol["attrs"]["listStyle"] == "upper-alpha"
def test_ordered_list_roman_falls_back_to_number():
(ol,) = find_nodes(convert('<ol type="i"><li>a</li></ol>'), "ordered_list")
assert ol["attrs"]["listStyle"] == "number"
def test_video_with_direct_src():
(video,) = find_nodes(
convert('<video src="/uploads/demo.mp4" width="640" height="480"></video>'),
"video",
)
assert video["attrs"]["src"] == "/uploads/demo.mp4"
assert video["attrs"]["width"] == 640
assert video["attrs"]["height"] == 480
assert video["attrs"]["title"] == "demo.mp4"
def test_video_with_source_child():
(video,) = find_nodes(
convert(
'<video><source src="/uploads/clip.webm" type="video/webm"/></video>'
),
"video",
)
assert video["attrs"]["src"] == "/uploads/clip.webm"
def test_video_without_src_is_flattened():
assert find_nodes(convert("<video>fallback text</video>"), "video") == []