|
3 | 3 |
|
4 | 4 | import pytest |
5 | 5 |
|
6 | | -from openkb.tree_renderer import render_source_md, render_summary_md |
7 | | - |
8 | | - |
9 | | -# --------------------------------------------------------------------------- |
10 | | -# render_source_md |
11 | | -# --------------------------------------------------------------------------- |
12 | | - |
13 | | - |
14 | | -class TestRenderSourceMd: |
15 | | - def test_has_yaml_frontmatter(self, sample_tree): |
16 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
17 | | - assert output.startswith("---\n") |
18 | | - assert "source: Sample Document" in output |
19 | | - assert "type: pageindex" in output |
20 | | - assert "doc_id: doc-abc" in output |
21 | | - assert "---\n" in output |
22 | | - |
23 | | - def test_top_level_nodes_are_h1(self, sample_tree): |
24 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
25 | | - assert "# Introduction" in output |
26 | | - assert "# Conclusion" in output |
27 | | - |
28 | | - def test_nested_nodes_are_h2(self, sample_tree): |
29 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
30 | | - assert "## Background" in output |
31 | | - assert "## Motivation" in output |
32 | | - |
33 | | - def test_page_range_included(self, sample_tree): |
34 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
35 | | - assert "(pages 0–120)" in output # Introduction |
36 | | - assert "(pages 0–60)" in output # Background |
37 | | - assert "(pages 61–120)" in output # Motivation |
38 | | - assert "(pages 121–200)" in output # Conclusion |
39 | | - |
40 | | - def test_node_text_included(self, sample_tree): |
41 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
42 | | - assert "This document introduces the core concepts of the system." in output |
43 | | - assert "Background information on the subject." in output |
44 | | - |
45 | | - def test_no_summary_in_source(self, sample_tree): |
46 | | - output = render_source_md(sample_tree, "Sample Document", "doc-abc") |
47 | | - # Source pages show text, not summaries |
48 | | - assert "Summary:" not in output |
49 | | - |
50 | | - def test_heading_depth_capped_at_6(self): |
51 | | - """Deeply nested nodes must not exceed h6.""" |
52 | | - deep_tree = { |
53 | | - "doc_name": "Deep", |
54 | | - "doc_description": "A deeply nested doc.", |
55 | | - "structure": [ |
56 | | - { |
57 | | - "title": "L1", |
58 | | - "start_index": 0, |
59 | | - "end_index": 10, |
60 | | - "text": "L1 text", |
61 | | - "summary": "L1 summary", |
62 | | - "nodes": [ |
63 | | - { |
64 | | - "title": "L2", |
65 | | - "start_index": 0, |
66 | | - "end_index": 5, |
67 | | - "text": "L2 text", |
68 | | - "summary": "L2 summary", |
69 | | - "nodes": [ |
70 | | - { |
71 | | - "title": "L3", |
72 | | - "start_index": 0, |
73 | | - "end_index": 3, |
74 | | - "text": "L3 text", |
75 | | - "summary": "L3 summary", |
76 | | - "nodes": [ |
77 | | - { |
78 | | - "title": "L4", |
79 | | - "start_index": 0, |
80 | | - "end_index": 1, |
81 | | - "text": "L4 text", |
82 | | - "summary": "L4 summary", |
83 | | - "nodes": [ |
84 | | - { |
85 | | - "title": "L5", |
86 | | - "start_index": 0, |
87 | | - "end_index": 1, |
88 | | - "text": "L5 text", |
89 | | - "summary": "L5 summary", |
90 | | - "nodes": [ |
91 | | - { |
92 | | - "title": "L6", |
93 | | - "start_index": 0, |
94 | | - "end_index": 1, |
95 | | - "text": "L6 text", |
96 | | - "summary": "L6 summary", |
97 | | - "nodes": [ |
98 | | - { |
99 | | - "title": "L7", |
100 | | - "start_index": 0, |
101 | | - "end_index": 1, |
102 | | - "text": "L7 text", |
103 | | - "summary": "L7 summary", |
104 | | - "nodes": [], |
105 | | - } |
106 | | - ], |
107 | | - } |
108 | | - ], |
109 | | - } |
110 | | - ], |
111 | | - } |
112 | | - ], |
113 | | - } |
114 | | - ], |
115 | | - } |
116 | | - ], |
117 | | - } |
118 | | - ], |
119 | | - } |
120 | | - output = render_source_md(deep_tree, "Deep", "doc-deep") |
121 | | - # L7 is at depth 7 — must render as h6, not h7 |
122 | | - assert "#######" not in output |
123 | | - assert "L7 text" in output |
| 6 | +from openkb.tree_renderer import render_summary_md |
124 | 7 |
|
125 | 8 |
|
126 | 9 | # --------------------------------------------------------------------------- |
|
0 commit comments