-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_markdown_to_respec.py
116 lines (88 loc) · 3.21 KB
/
test_markdown_to_respec.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
import io
import os
import pytest
import shutil
import pathlib
import markdown_to_respec
@pytest.fixture
def setup_data():
if os.path.isdir('test'):
shutil.rmtree('test')
shutil.copytree('test-data', 'test')
def test_run(setup_data):
# source files are present (from setup_data)
assert pathlib.Path('test/embedded/index.md').is_file(), 'embedded file is there'
assert pathlib.Path('test/external/index.md').is_file(), 'external file is there'
assert pathlib.Path('test/external/index.json').is_file(), 'external config is there'
assert pathlib.Path('test/ignore/index.md').is_file(), 'ignored markdown is present'
# generate the respec using the test directory!
markdown_to_respec.run('test', publish=False, ignore='test/ignore/index.md')
# html file was created using embedded config
html_file = pathlib.Path('test/embedded/index.html')
assert html_file.is_file()
html = html_file.open().read()
assert '<title>Test Specification</title>' in html, 'found title'
assert '<section id="abstract">' in html, 'found abstract'
assert '<section id="sotd">' in html, 'found sotd'
assert '<section id="conformance">' in html, 'found conformance'
assert '"name": "Git Hub Jr"' in html, 'found editor from embedded yaml'
# html file was created using external config
html_file = pathlib.Path('test/external/index.html')
assert html_file.is_file()
html = html_file.open().read()
assert '<title>Test External Specification</title>' in html
assert '<section id="abstract">' in html
assert '<section id="sotd">' in html
assert '<section id="conformance">' in html
assert '"name": "Git Hub Jr"' in html
# ignored markdown was not processed
assert not pathlib.Path('test/ignore/index.html').is_file()
def test_parse():
markdown = \
"""
---
editors:
- name: Git Hub Jr.
---
# This is a title
## Status of this Document
A custom document status.
## Abstract
This is the abstract.
It can have multiple lines.
## Conformance
This is some conformance text.
## Overview
This is the overview
"""
doc = markdown_to_respec.parse_markdown(io.StringIO(markdown))
assert 'title' in doc.metadata
assert doc.metadata['title'] == 'This is a title'
assert '# This is a title' not in doc.content
assert 'abstract' in doc.metadata
assert doc.metadata['abstract'] == 'This is the abstract.\n\nIt can have multiple lines.'
assert '## Abstract' not in doc.content
assert 'sotd' in doc.metadata
assert doc.metadata['conformance'] == 'This is some conformance text.'
assert '## Conformance' not in doc.content
assert doc.metadata['sotd'] == 'A custom document status.'
assert doc.metadata['sotd'] == 'A custom document status.'
assert '## Status of this Document' not in doc.content
def test_missing():
markdown = \
"""
---
editors:
- name: Git Hub Jr.
---
# This is a title
Everything else is missing!
"""
doc = markdown_to_respec.parse_markdown(io.StringIO(markdown))
assert 'abstract' in doc.metadata
assert 'sotd' in doc.metadata
assert 'conformance' in doc.metadata
class MockDoc:
def __init__(self, content, metadata={}):
self.content = content
self.metadata = metadata