-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_linkedheaders.py
64 lines (51 loc) · 2.17 KB
/
test_linkedheaders.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
"""
These tests verify how the n2y block classes convert notion data into Pandoc
abstract syntax tree (AST) objects, and then into markdown.
"""
from pandoc.types import Header, Link, Space, Str
from n2y.notion_mocks import mock_block, mock_rich_text
from n2y.utils import header_id_from_text, strip_hyphens
from tests.test_blocks import process_block
linked_headers = ["n2y.plugins.linkedheaders"]
def mock_header_ast(level, suffix, notion_block):
rich_text = notion_block[notion_block["type"]]["rich_text"][0]["plain_text"]
section_id = header_id_from_text(rich_text)
return Header(
level,
(section_id, [], []),
[
Link(
("", [], []),
[Str("Heading"), Space(), Str(suffix)],
(f'#{strip_hyphens(notion_block["id"])}', ""),
)
],
)
def test_heading_1():
notion_block = mock_block(
"heading_1", {"rich_text": [mock_rich_text("Heading One")]}
)
pandoc_ast, markdown = process_block(notion_block, linked_headers)
assert pandoc_ast == mock_header_ast(1, "One", notion_block)
assert markdown == f'# [Heading One]({notion_block["url"]})\n'
def test_heading_1_bolding_stripped():
notion_block = mock_block(
"heading_1", {"rich_text": [mock_rich_text("Heading One", ["bold"])]}
)
pandoc_ast, markdown = process_block(notion_block, linked_headers)
assert pandoc_ast == mock_header_ast(1, "One", notion_block)
assert markdown == f'# [Heading One]({notion_block["url"]})\n'
def test_heading_2():
notion_block = mock_block(
"heading_2", {"rich_text": [mock_rich_text("Heading Two")]}
)
pandoc_ast, markdown = process_block(notion_block, linked_headers)
assert pandoc_ast == mock_header_ast(2, "Two", notion_block)
assert markdown == f'## [Heading Two]({notion_block["url"]})\n'
def test_heading_3():
notion_block = mock_block(
"heading_3", {"rich_text": [mock_rich_text("Heading Three")]}
)
pandoc_ast, markdown = process_block(notion_block, linked_headers)
assert pandoc_ast == mock_header_ast(3, "Three", notion_block)
assert markdown == f'### [Heading Three]({notion_block["url"]})\n'