codeplain 0.3.13.dev47__py3-none-any.whl → 0.3.13.dev48__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codeplain-0.3.13.dev47.dist-info → codeplain-0.3.13.dev48.dist-info}/METADATA +2 -2
- {codeplain-0.3.13.dev47.dist-info → codeplain-0.3.13.dev48.dist-info}/RECORD +16 -19
- concept_utils.py +2 -220
- file_utils.py +6 -106
- plain2code.py +38 -5
- plain2code_exceptions.py +12 -42
- plain2code_nodes.py +2 -118
- plain2code_utils.py +1 -16
- plain_file.py +2 -870
- plain_spec.py +9 -413
- tests/test_file_utils.py +1 -70
- tests/test_render_range.py +42 -0
- tests/test_user_error_message.py +36 -0
- tests/test_imports.py +0 -53
- tests/test_plainfile.py +0 -271
- tests/test_plainfileparser.py +0 -775
- tests/test_plainspec.py +0 -103
- tests/test_requires.py +0 -28
- {codeplain-0.3.13.dev47.dist-info → codeplain-0.3.13.dev48.dist-info}/WHEEL +0 -0
- {codeplain-0.3.13.dev47.dist-info → codeplain-0.3.13.dev48.dist-info}/entry_points.txt +0 -0
- {codeplain-0.3.13.dev47.dist-info → codeplain-0.3.13.dev48.dist-info}/licenses/LICENSE +0 -0
tests/test_plainfileparser.py
DELETED
|
@@ -1,775 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import re
|
|
3
|
-
from unittest.mock import patch
|
|
4
|
-
from urllib.parse import urlparse
|
|
5
|
-
|
|
6
|
-
import pytest
|
|
7
|
-
from liquid2 import Environment, RenderContext, TemplateSource
|
|
8
|
-
|
|
9
|
-
import file_utils
|
|
10
|
-
import plain_file
|
|
11
|
-
import plain_spec
|
|
12
|
-
from plain2code_exceptions import MissingFunctionalitiesError, PlainSyntaxError
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def test_regular_plain_source(get_test_data_path):
|
|
16
|
-
_, plain_sections, _ = plain_file.plain_file_parser(
|
|
17
|
-
"regular_plain_source.plain",
|
|
18
|
-
[get_test_data_path("data/plainfileparser")],
|
|
19
|
-
)
|
|
20
|
-
assert plain_sections == {
|
|
21
|
-
"definitions": [],
|
|
22
|
-
"implementation reqs": [
|
|
23
|
-
{"markdown": "- First implementation requirement."},
|
|
24
|
-
{"markdown": "- Second implementation requirement."},
|
|
25
|
-
],
|
|
26
|
-
"functional specs": [{"markdown": '- Display "hello, world"'}],
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_unknown_section():
|
|
31
|
-
plain_source = """
|
|
32
|
-
***definitions***
|
|
33
|
-
|
|
34
|
-
***Unknown Section:***
|
|
35
|
-
"""
|
|
36
|
-
with pytest.raises(
|
|
37
|
-
Exception,
|
|
38
|
-
match=re.escape(
|
|
39
|
-
"Syntax error at line 4: Invalid specification heading (`Unknown Section:`). Allowed headings: definitions, implementation reqs, test reqs, functional specs, acceptance tests"
|
|
40
|
-
),
|
|
41
|
-
):
|
|
42
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def test_duplicate_section():
|
|
46
|
-
plain_source = """
|
|
47
|
-
***definitions***
|
|
48
|
-
|
|
49
|
-
***definitions***
|
|
50
|
-
"""
|
|
51
|
-
with pytest.raises(
|
|
52
|
-
Exception,
|
|
53
|
-
match=re.escape("Syntax error at line 4: Duplicate specification heading (`definitions`)"),
|
|
54
|
-
):
|
|
55
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def test_invalid_top_level_element():
|
|
59
|
-
plain_source = """
|
|
60
|
-
***definitions***
|
|
61
|
-
```
|
|
62
|
-
code block
|
|
63
|
-
```
|
|
64
|
-
"""
|
|
65
|
-
with pytest.raises(
|
|
66
|
-
Exception,
|
|
67
|
-
match=re.escape("Syntax error at line 3: Invalid source structure (`code block`)"),
|
|
68
|
-
):
|
|
69
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def test_syntax_error_line_number_accounts_for_frontmatter():
|
|
73
|
-
plain_source = """---
|
|
74
|
-
description: 'Plain file with frontmatter'
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
***definitions***
|
|
78
|
-
|
|
79
|
-
***Unknown Section:***
|
|
80
|
-
"""
|
|
81
|
-
with pytest.raises(
|
|
82
|
-
Exception,
|
|
83
|
-
match=re.escape("Syntax error at line 7: Invalid specification heading (`Unknown Section:`)"),
|
|
84
|
-
):
|
|
85
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_syntax_error_line_number_with_windows_line_endings():
|
|
89
|
-
plain_source = (
|
|
90
|
-
"---\r\n"
|
|
91
|
-
"description: 'Plain file with frontmatter'\r\n"
|
|
92
|
-
"---\r\n"
|
|
93
|
-
"\r\n"
|
|
94
|
-
"***definitions***\r\n"
|
|
95
|
-
"\r\n"
|
|
96
|
-
"***Unknown Section:***\r\n"
|
|
97
|
-
)
|
|
98
|
-
with pytest.raises(
|
|
99
|
-
Exception,
|
|
100
|
-
match=re.escape("Syntax error at line 7: Invalid specification heading (`Unknown Section:`)"),
|
|
101
|
-
):
|
|
102
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def test_normalize_line_endings_does_not_duplicate_newlines():
|
|
106
|
-
assert plain_file.normalize_line_endings("a\r\nb\rc\nd") == "a\nb\nc\nd"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def test_plain_file_parser_with_comments(get_test_data_path):
|
|
110
|
-
_, plain_sections, _ = plain_file.plain_file_parser(
|
|
111
|
-
"plain_file_parser_with_comments.plain",
|
|
112
|
-
[get_test_data_path("data/plainfileparser")],
|
|
113
|
-
)
|
|
114
|
-
assert plain_sections == {
|
|
115
|
-
"definitions": [],
|
|
116
|
-
"implementation reqs": [{"markdown": "- Second implementation requirement."}],
|
|
117
|
-
"functional specs": [{"markdown": '- Display "hello, world"'}],
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def test_plain_file_parser_with_comments_indented(get_test_data_path):
|
|
122
|
-
_, plain_sections, _ = plain_file.plain_file_parser(
|
|
123
|
-
"plain_file_with_comments_indented.plain",
|
|
124
|
-
[get_test_data_path("data/plainfileparser")],
|
|
125
|
-
)
|
|
126
|
-
assert plain_sections == {
|
|
127
|
-
"definitions": [],
|
|
128
|
-
"implementation reqs": [
|
|
129
|
-
{"markdown": "- First implementation requirement."},
|
|
130
|
-
{"markdown": "- Second implementation requirement."},
|
|
131
|
-
],
|
|
132
|
-
"functional specs": [{"markdown": '- Display "hello, world"'}],
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def test_invalid_url_link(get_test_data_path):
|
|
137
|
-
with pytest.raises(Exception, match="Only relative links are allowed."):
|
|
138
|
-
plain_file.plain_file_parser("plain_source_with_url_link.plain", [get_test_data_path("data/plainfile")])
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
def test_invalid_absolute_link(get_test_data_path):
|
|
142
|
-
with pytest.raises(Exception, match="Only relative links are allowed."):
|
|
143
|
-
plain_file.plain_file_parser(
|
|
144
|
-
"plain_source_with_absolute_link.plain",
|
|
145
|
-
[get_test_data_path("data/plainfile")],
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def test_missing_link_error_lists_searched_directories(get_test_data_path):
|
|
150
|
-
"""The error tells the user which directories were searched for the linked resource."""
|
|
151
|
-
plain_file_dir = get_test_data_path("data/plainfile")
|
|
152
|
-
|
|
153
|
-
with pytest.raises(PlainSyntaxError) as exception_info:
|
|
154
|
-
plain_file.plain_file_parser(
|
|
155
|
-
"plain_source_with_missing_link.plain",
|
|
156
|
-
[plain_file_dir],
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
message = str(exception_info.value)
|
|
160
|
-
assert "resources/missing_resource.yaml does not exist" in message
|
|
161
|
-
assert "highest to lowest precedence" in message
|
|
162
|
-
assert plain_file_dir in message
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def test_reference_link_parsing(get_test_data_path):
|
|
166
|
-
_, plain_sections, _ = plain_file.plain_file_parser(
|
|
167
|
-
"task_manager_with_reference_links.plain",
|
|
168
|
-
[get_test_data_path("data/plainfile")],
|
|
169
|
-
)
|
|
170
|
-
asserted_resources = [
|
|
171
|
-
"task_list_ui_specification.yaml",
|
|
172
|
-
"add_new_task_modal_specification.yaml",
|
|
173
|
-
]
|
|
174
|
-
for functional_requirement in plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS]:
|
|
175
|
-
if "linked_resources" not in functional_requirement:
|
|
176
|
-
continue
|
|
177
|
-
|
|
178
|
-
for resource in functional_requirement["linked_resources"]:
|
|
179
|
-
assert resource["target"] in asserted_resources
|
|
180
|
-
del asserted_resources[asserted_resources.index(resource["target"])]
|
|
181
|
-
|
|
182
|
-
parsed_url = urlparse(resource["target"])
|
|
183
|
-
assert parsed_url.scheme == ""
|
|
184
|
-
|
|
185
|
-
assert not os.path.isabs(resource["target"])
|
|
186
|
-
|
|
187
|
-
assert asserted_resources == []
|
|
188
|
-
|
|
189
|
-
assert "`[resource]task_list_ui_specification.yaml`" in "\n".join(
|
|
190
|
-
[item["markdown"] for item in plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS]]
|
|
191
|
-
)
|
|
192
|
-
assert "`[resource]add_new_task_modal_specification.yaml`" in "\n".join(
|
|
193
|
-
[item["markdown"] for item in plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS]]
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
assert plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS][1]["linked_resources"] == [
|
|
197
|
-
{
|
|
198
|
-
"text": "task_list_ui_specification.yaml",
|
|
199
|
-
"target": "task_list_ui_specification.yaml",
|
|
200
|
-
}
|
|
201
|
-
]
|
|
202
|
-
assert plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS][2]["linked_resources"] == [
|
|
203
|
-
{
|
|
204
|
-
"text": "add_new_task_modal_specification.yaml",
|
|
205
|
-
"target": "add_new_task_modal_specification.yaml",
|
|
206
|
-
}
|
|
207
|
-
]
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
def test_reference_link_parsing_independent_of_working_directory(get_test_data_path, monkeypatch, tmp_path):
|
|
211
|
-
"""Linked resources resolve against the plain file's directory, not the invocation cwd."""
|
|
212
|
-
monkeypatch.chdir(tmp_path)
|
|
213
|
-
|
|
214
|
-
_, plain_sections, _ = plain_file.plain_file_parser(
|
|
215
|
-
"task_manager_with_reference_links.plain",
|
|
216
|
-
[get_test_data_path("data/plainfile")],
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
assert plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS][1]["linked_resources"] == [
|
|
220
|
-
{
|
|
221
|
-
"text": "task_list_ui_specification.yaml",
|
|
222
|
-
"target": "task_list_ui_specification.yaml",
|
|
223
|
-
}
|
|
224
|
-
]
|
|
225
|
-
assert plain_sections[plain_spec.FUNCTIONAL_REQUIREMENTS][2]["linked_resources"] == [
|
|
226
|
-
{
|
|
227
|
-
"text": "add_new_task_modal_specification.yaml",
|
|
228
|
-
"target": "add_new_task_modal_specification.yaml",
|
|
229
|
-
}
|
|
230
|
-
]
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def test_invalid_specification_order(get_test_data_path):
|
|
234
|
-
with pytest.raises(
|
|
235
|
-
Exception,
|
|
236
|
-
match="Syntax error at line 6: Definitions specification must be the first specification in the section.",
|
|
237
|
-
):
|
|
238
|
-
plain_file.plain_file_parser("invalid_specification_order.plain", [get_test_data_path("data/plainfile")])
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def test_duplicate_specification_heading(get_test_data_path):
|
|
242
|
-
with pytest.raises(
|
|
243
|
-
Exception,
|
|
244
|
-
match=re.escape("Syntax error at line 6: Duplicate specification heading (`definitions`)"),
|
|
245
|
-
):
|
|
246
|
-
plain_file.plain_file_parser(
|
|
247
|
-
"duplicate_specification_heading.plain",
|
|
248
|
-
[get_test_data_path("data/plainfile")],
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
def test_missing_non_functional_requirements(get_test_data_path):
|
|
253
|
-
with pytest.raises(
|
|
254
|
-
Exception,
|
|
255
|
-
match="defines functionalities but specifies no implementation reqs",
|
|
256
|
-
):
|
|
257
|
-
plain_file.plain_file_parser(
|
|
258
|
-
"missing_non_functional_requirements.plain",
|
|
259
|
-
[get_test_data_path("data/plainfile")],
|
|
260
|
-
)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
def test_without_non_functional_requirement(get_test_data_path):
|
|
264
|
-
with pytest.raises(
|
|
265
|
-
Exception,
|
|
266
|
-
match="defines functionalities but specifies no implementation reqs",
|
|
267
|
-
):
|
|
268
|
-
plain_file.plain_file_parser(
|
|
269
|
-
"without_non_functional_requirement.plain",
|
|
270
|
-
[get_test_data_path("data/plainfile")],
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
def test_missing_impl_reqs_with_requires_adds_hint():
|
|
275
|
-
plain_source = {plain_spec.NON_FUNCTIONAL_REQUIREMENTS: None}
|
|
276
|
-
with pytest.raises(
|
|
277
|
-
PlainSyntaxError,
|
|
278
|
-
match="not inherited through 'requires'",
|
|
279
|
-
):
|
|
280
|
-
plain_file.validate_functionalities_have_implementation_reqs(plain_source, "my_app", has_requires=True)
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
def test_missing_impl_reqs_without_requires_has_no_hint():
|
|
284
|
-
plain_source = {plain_spec.NON_FUNCTIONAL_REQUIREMENTS: None}
|
|
285
|
-
with pytest.raises(PlainSyntaxError) as exc_info:
|
|
286
|
-
plain_file.validate_functionalities_have_implementation_reqs(plain_source, "my_app", has_requires=False)
|
|
287
|
-
assert "requires" not in str(exc_info.value)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
def test_no_functional_specs_section(get_test_data_path):
|
|
291
|
-
with pytest.raises(
|
|
292
|
-
MissingFunctionalitiesError,
|
|
293
|
-
match="does not have any functionality specified",
|
|
294
|
-
):
|
|
295
|
-
plain_file.plain_file_parser(
|
|
296
|
-
"no_functional_specs_section.plain",
|
|
297
|
-
[get_test_data_path("data/plainfile")],
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
def test_empty_functional_specs_section(get_test_data_path):
|
|
302
|
-
with pytest.raises(
|
|
303
|
-
PlainSyntaxError,
|
|
304
|
-
match=re.escape("has an empty 'functional specs' section"),
|
|
305
|
-
):
|
|
306
|
-
plain_file.plain_file_parser(
|
|
307
|
-
"empty_functional_specs_section.plain",
|
|
308
|
-
[get_test_data_path("data/plainfile")],
|
|
309
|
-
)
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
def test_indented_include_tags():
|
|
313
|
-
plain_source = """# Main
|
|
314
|
-
|
|
315
|
-
***definitions***
|
|
316
|
-
|
|
317
|
-
- This is a definition.
|
|
318
|
-
|
|
319
|
-
***implementation reqs***
|
|
320
|
-
- First implementation requirement.
|
|
321
|
-
- Second implementation requirement.
|
|
322
|
-
|
|
323
|
-
> This is a comment
|
|
324
|
-
> This is a with an include tag {% include "template.plain" %}
|
|
325
|
-
|
|
326
|
-
***functional specs***
|
|
327
|
-
- Implement {% include "implement.plain" %}
|
|
328
|
-
{% include "template.plain" %}
|
|
329
|
-
- Display "hello, world"
|
|
330
|
-
{% include "template.plain" %}
|
|
331
|
-
{% include "template.plain" %}
|
|
332
|
-
- Implement {% include "implement.plain" %}
|
|
333
|
-
"""
|
|
334
|
-
loaded_templates = {
|
|
335
|
-
"template.plain": "- This is a functionality inside a template.",
|
|
336
|
-
"implement.plain": """something nice and useful
|
|
337
|
-
- the nice thing should be really nice
|
|
338
|
-
- the useful thing should be really useful""",
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
expected_rendered_plain_source = """# Main
|
|
342
|
-
|
|
343
|
-
***definitions***
|
|
344
|
-
|
|
345
|
-
- This is a definition.
|
|
346
|
-
|
|
347
|
-
***implementation reqs***
|
|
348
|
-
- First implementation requirement.
|
|
349
|
-
- Second implementation requirement.
|
|
350
|
-
|
|
351
|
-
> This is a comment
|
|
352
|
-
> This is a with an include tag {% include 'template.plain' %}
|
|
353
|
-
|
|
354
|
-
***functional specs***
|
|
355
|
-
- Implement something nice and useful
|
|
356
|
-
- the nice thing should be really nice
|
|
357
|
-
- the useful thing should be really useful
|
|
358
|
-
- This is a functionality inside a template.
|
|
359
|
-
- Display "hello, world"
|
|
360
|
-
- This is a functionality inside a template.
|
|
361
|
-
- This is a functionality inside a template.
|
|
362
|
-
- Implement something nice and useful
|
|
363
|
-
- the nice thing should be really nice
|
|
364
|
-
- the useful thing should be really useful
|
|
365
|
-
"""
|
|
366
|
-
rendered_plain_source = plain_file.render_plain_source(plain_source, loaded_templates, {})
|
|
367
|
-
assert rendered_plain_source == expected_rendered_plain_source
|
|
368
|
-
|
|
369
|
-
def mock_get_source(
|
|
370
|
-
env: Environment,
|
|
371
|
-
template_name: str,
|
|
372
|
-
*,
|
|
373
|
-
context: RenderContext | None = None,
|
|
374
|
-
**kwargs: object,
|
|
375
|
-
):
|
|
376
|
-
return TemplateSource(
|
|
377
|
-
loaded_templates[template_name],
|
|
378
|
-
template_name,
|
|
379
|
-
lambda: True,
|
|
380
|
-
)
|
|
381
|
-
|
|
382
|
-
with patch(
|
|
383
|
-
"liquid2.builtin.loaders.file_system_loader.FileSystemLoader.get_source",
|
|
384
|
-
side_effect=mock_get_source,
|
|
385
|
-
):
|
|
386
|
-
plain_source_result, loaded_templates_result = file_utils.get_loaded_templates(["."], plain_source)
|
|
387
|
-
assert plain_source_result == expected_rendered_plain_source
|
|
388
|
-
assert loaded_templates_result == loaded_templates
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
def test_code_variables(load_test_data, get_test_data_path):
|
|
392
|
-
plain_source = load_test_data("data/templates/code_variables.plain")
|
|
393
|
-
loaded_templates = {
|
|
394
|
-
"implement.plain": load_test_data("data/templates/implement.plain"),
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
code_variables = {}
|
|
398
|
-
rendered_plain_source = plain_file.render_plain_source(plain_source, loaded_templates, code_variables)
|
|
399
|
-
keys = list(code_variables.keys())
|
|
400
|
-
|
|
401
|
-
expected_rendered_plain_source = f"""***definitions***
|
|
402
|
-
|
|
403
|
-
- :concept: is a concept.
|
|
404
|
-
|
|
405
|
-
***implementation reqs***
|
|
406
|
-
- First implementation requirement.
|
|
407
|
-
- Second implementation requirement.
|
|
408
|
-
|
|
409
|
-
***functional specs***
|
|
410
|
-
- Implement something nice and useful
|
|
411
|
-
- the nice thing should be really {keys[0]}
|
|
412
|
-
- the useful thing should be really useful
|
|
413
|
-
"""
|
|
414
|
-
|
|
415
|
-
assert rendered_plain_source == expected_rendered_plain_source
|
|
416
|
-
|
|
417
|
-
_, plain_source, _ = plain_file.plain_file_parser("code_variables.plain", [get_test_data_path("data/templates")])
|
|
418
|
-
expected_plain_source = {
|
|
419
|
-
"definitions": [{"markdown": "- :concept: is a concept."}],
|
|
420
|
-
"implementation reqs": [
|
|
421
|
-
{"markdown": "- First implementation requirement."},
|
|
422
|
-
{"markdown": "- Second implementation requirement."},
|
|
423
|
-
],
|
|
424
|
-
"functional specs": [
|
|
425
|
-
{
|
|
426
|
-
"markdown": "- Implement something nice and useful\n - the nice thing should be really {{ variable_name }}\n - the useful thing should be really useful",
|
|
427
|
-
"code_variables": [{"name": "variable_name", "value": "nice"}],
|
|
428
|
-
}
|
|
429
|
-
],
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
assert plain_source == expected_plain_source
|
|
433
|
-
|
|
434
|
-
plain_source = load_test_data("data/templates/template_include.plain")
|
|
435
|
-
loaded_templates = {
|
|
436
|
-
"header.plain": load_test_data("data/templates/header.plain"),
|
|
437
|
-
"implement_2.plain": load_test_data("data/templates/implement_2.plain"),
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
code_variables = {}
|
|
441
|
-
rendered_plain_source = plain_file.render_plain_source(plain_source, loaded_templates, code_variables)
|
|
442
|
-
keys = list(code_variables.keys())
|
|
443
|
-
expected_rendered_plain_source = f"""***definitions***
|
|
444
|
-
|
|
445
|
-
- :concept: is a concept.
|
|
446
|
-
|
|
447
|
-
***implementation reqs***
|
|
448
|
-
- First implementation requirement {keys[0]}.
|
|
449
|
-
- Second implementation requirement {keys[1]}.
|
|
450
|
-
|
|
451
|
-
***functional specs***
|
|
452
|
-
- Implement something nice and useful
|
|
453
|
-
- the nice thing should be really {keys[2]}
|
|
454
|
-
- the useful thing should be really useful
|
|
455
|
-
"""
|
|
456
|
-
|
|
457
|
-
assert rendered_plain_source == expected_rendered_plain_source
|
|
458
|
-
|
|
459
|
-
_, plain_source, _ = plain_file.plain_file_parser("template_include.plain", [get_test_data_path("data/templates")])
|
|
460
|
-
expected_plain_source = {
|
|
461
|
-
"definitions": [{"markdown": "- :concept: is a concept."}],
|
|
462
|
-
"implementation reqs": [
|
|
463
|
-
{
|
|
464
|
-
"markdown": "- First implementation requirement {{ variable_name_1 }}.",
|
|
465
|
-
"code_variables": [{"name": "variable_name_1", "value": "nice_1"}],
|
|
466
|
-
},
|
|
467
|
-
{
|
|
468
|
-
"markdown": "- Second implementation requirement {{ variable_name_1 }}.",
|
|
469
|
-
"code_variables": [{"name": "variable_name_1", "value": "nice_2"}],
|
|
470
|
-
},
|
|
471
|
-
],
|
|
472
|
-
"functional specs": [
|
|
473
|
-
{
|
|
474
|
-
"markdown": "- Implement something nice and useful\n - the nice thing should be really {{ variable_name_1 }}\n - the useful thing should be really useful",
|
|
475
|
-
"code_variables": [{"name": "variable_name_1", "value": "nice"}],
|
|
476
|
-
}
|
|
477
|
-
],
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
assert plain_source == expected_plain_source
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
def test_acceptance_tests_block_include_with_trailing_newline_keeps_structure_and_ignores_quote(get_test_data_path):
|
|
484
|
-
"""
|
|
485
|
-
Ensures that a block-level include inside ***acceptance tests*** whose template ends
|
|
486
|
-
with a trailing newline does not terminate the list, and that a following '> ...' line
|
|
487
|
-
is treated as a comment and ignored. The parser should not raise a syntax error.
|
|
488
|
-
It's an error we encountered while implementing custom rendering and should break in case of regression.
|
|
489
|
-
"""
|
|
490
|
-
plain_file.plain_file_parser("block_level_include.plain", [get_test_data_path("data/templates")])
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
def test_acceptance_tests_top_level_rejected():
|
|
494
|
-
plain_source = """
|
|
495
|
-
***acceptance tests***
|
|
496
|
-
|
|
497
|
-
- Test something.
|
|
498
|
-
"""
|
|
499
|
-
with pytest.raises(
|
|
500
|
-
PlainSyntaxError,
|
|
501
|
-
match=re.escape(
|
|
502
|
-
"Syntax error at line 2: acceptance tests heading should be nested under specific functional spec."
|
|
503
|
-
),
|
|
504
|
-
):
|
|
505
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
def test_acceptance_tests_top_level_after_other_headings_rejected():
|
|
509
|
-
plain_source = """***definitions***
|
|
510
|
-
|
|
511
|
-
- :concept: is a concept.
|
|
512
|
-
|
|
513
|
-
***acceptance tests***
|
|
514
|
-
|
|
515
|
-
- Test something.
|
|
516
|
-
"""
|
|
517
|
-
with pytest.raises(
|
|
518
|
-
PlainSyntaxError,
|
|
519
|
-
match=re.escape(
|
|
520
|
-
"Syntax error at line 5: acceptance tests heading should be nested under specific functional spec."
|
|
521
|
-
),
|
|
522
|
-
):
|
|
523
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
def test_acceptance_tests_nested_under_definitions_rejected():
|
|
527
|
-
plain_source = """***definitions***
|
|
528
|
-
|
|
529
|
-
- :concept: is a concept.
|
|
530
|
-
|
|
531
|
-
***acceptance tests***
|
|
532
|
-
|
|
533
|
-
- Test the :concept:.
|
|
534
|
-
|
|
535
|
-
***functional specs***
|
|
536
|
-
|
|
537
|
-
- Display "hello, world"
|
|
538
|
-
"""
|
|
539
|
-
with pytest.raises(
|
|
540
|
-
PlainSyntaxError,
|
|
541
|
-
match=re.escape(
|
|
542
|
-
"Syntax error at line 5: acceptance tests heading should be nested under specific functional spec."
|
|
543
|
-
),
|
|
544
|
-
):
|
|
545
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
def test_acceptance_tests_nested_under_implementation_reqs_rejected():
|
|
549
|
-
plain_source = """***implementation reqs***
|
|
550
|
-
|
|
551
|
-
- First implementation requirement.
|
|
552
|
-
|
|
553
|
-
***acceptance tests***
|
|
554
|
-
|
|
555
|
-
- Test something.
|
|
556
|
-
"""
|
|
557
|
-
with pytest.raises(
|
|
558
|
-
PlainSyntaxError,
|
|
559
|
-
match=re.escape(
|
|
560
|
-
"Syntax error at line 5: acceptance tests heading should be nested under specific functional spec."
|
|
561
|
-
),
|
|
562
|
-
):
|
|
563
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
def test_acceptance_tests_nested_under_test_reqs_rejected():
|
|
567
|
-
plain_source = """***test reqs***
|
|
568
|
-
|
|
569
|
-
- First test requirement.
|
|
570
|
-
|
|
571
|
-
***acceptance tests***
|
|
572
|
-
|
|
573
|
-
- Test something.
|
|
574
|
-
"""
|
|
575
|
-
with pytest.raises(
|
|
576
|
-
PlainSyntaxError,
|
|
577
|
-
match=re.escape(
|
|
578
|
-
"Syntax error at line 5: acceptance tests heading should be nested under specific functional spec."
|
|
579
|
-
),
|
|
580
|
-
):
|
|
581
|
-
plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
def test_acceptance_tests_nested_under_functional_spec_allowed():
|
|
585
|
-
plain_source = """***definitions***
|
|
586
|
-
|
|
587
|
-
- :concept: is a concept.
|
|
588
|
-
|
|
589
|
-
***functional specs***
|
|
590
|
-
|
|
591
|
-
- Display "hello, world"
|
|
592
|
-
|
|
593
|
-
***acceptance tests***
|
|
594
|
-
|
|
595
|
-
- Test the :concept:.
|
|
596
|
-
"""
|
|
597
|
-
result = plain_file.parse_plain_source(plain_source, {}, [], [], [])
|
|
598
|
-
assert plain_spec.FUNCTIONAL_REQUIREMENTS in result.plain_source
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
def test_concept_validation_definitions(get_test_data_path):
|
|
602
|
-
plain_file.plain_file_parser(
|
|
603
|
-
"concept_validation_definition.plain",
|
|
604
|
-
[get_test_data_path("data/plainfileparser")],
|
|
605
|
-
)
|
|
606
|
-
|
|
607
|
-
with pytest.raises(PlainSyntaxError):
|
|
608
|
-
plain_file.plain_file_parser(
|
|
609
|
-
"concept_validation_noconcepts.plain",
|
|
610
|
-
[get_test_data_path("data/plainfileparser")],
|
|
611
|
-
)
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
def test_concept_validation_usage(get_test_data_path):
|
|
615
|
-
plain_file.plain_file_parser(
|
|
616
|
-
"concept_validation_valid.plain",
|
|
617
|
-
[get_test_data_path("data/plainfileparser")],
|
|
618
|
-
)
|
|
619
|
-
|
|
620
|
-
with pytest.raises(PlainSyntaxError):
|
|
621
|
-
plain_file.plain_file_parser(
|
|
622
|
-
"concept_validation_nondefined.plain",
|
|
623
|
-
[get_test_data_path("data/plainfileparser")],
|
|
624
|
-
)
|
|
625
|
-
|
|
626
|
-
with pytest.raises(PlainSyntaxError):
|
|
627
|
-
plain_file.plain_file_parser(
|
|
628
|
-
"concept_validation_defined_nondefined.plain",
|
|
629
|
-
[get_test_data_path("data/plainfileparser")],
|
|
630
|
-
)
|
|
631
|
-
|
|
632
|
-
with pytest.raises(PlainSyntaxError):
|
|
633
|
-
plain_file.plain_file_parser(
|
|
634
|
-
"concept_validation_defined_nondefined_2.plain",
|
|
635
|
-
[get_test_data_path("data/plainfileparser")],
|
|
636
|
-
)
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
def test_concept_validation_redefinition(get_test_data_path):
|
|
640
|
-
with pytest.raises(PlainSyntaxError):
|
|
641
|
-
plain_file.plain_file_parser(
|
|
642
|
-
"concept_validation_redefinition.plain",
|
|
643
|
-
[get_test_data_path("data/plainfileparser")],
|
|
644
|
-
)
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
def test_concept_validation_non_concept_usage(get_test_data_path):
|
|
648
|
-
plain_file.plain_file_parser(
|
|
649
|
-
"concept_validation_nonconcept.plain",
|
|
650
|
-
[get_test_data_path("data/plainfileparser")],
|
|
651
|
-
)
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
def test_concept_validation_several_concepts(get_test_data_path):
|
|
655
|
-
plain_file.plain_file_parser(
|
|
656
|
-
"concept_validation_several_concepts.plain",
|
|
657
|
-
[get_test_data_path("data/plainfileparser")],
|
|
658
|
-
)
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
def test_concept_validation_acceptance_tests(get_test_data_path):
|
|
662
|
-
plain_file.plain_file_parser(
|
|
663
|
-
"concept_validation_acceptance_tests.plain",
|
|
664
|
-
[get_test_data_path("data/plainfileparser")],
|
|
665
|
-
)
|
|
666
|
-
|
|
667
|
-
with pytest.raises(PlainSyntaxError):
|
|
668
|
-
plain_file.plain_file_parser(
|
|
669
|
-
"concept_validation_acceptance_tests_nondefined.plain",
|
|
670
|
-
[get_test_data_path("data/plainfileparser")],
|
|
671
|
-
)
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
def test_concept_validation_cyclic_definitions(get_test_data_path):
|
|
675
|
-
with pytest.raises(PlainSyntaxError, match="cycles in the concept graph"):
|
|
676
|
-
plain_file.plain_file_parser("cyclic_definitions.plain", [get_test_data_path("data/plainfileparser")])
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
def test_required_concepts(get_test_data_path):
|
|
680
|
-
plain_file.plain_file_parser(
|
|
681
|
-
"required_concepts_example.plain",
|
|
682
|
-
[get_test_data_path("data/plainfileparser")],
|
|
683
|
-
)
|
|
684
|
-
|
|
685
|
-
plain_file.plain_file_parser(
|
|
686
|
-
"required_concepts_module.plain",
|
|
687
|
-
[get_test_data_path("data/plainfileparser")],
|
|
688
|
-
)
|
|
689
|
-
|
|
690
|
-
plain_file.plain_file_parser(
|
|
691
|
-
"required_concepts_partial.plain",
|
|
692
|
-
[get_test_data_path("data/plainfileparser")],
|
|
693
|
-
)
|
|
694
|
-
|
|
695
|
-
with pytest.raises(PlainSyntaxError):
|
|
696
|
-
plain_file.plain_file_parser(
|
|
697
|
-
"required_concepts_missing.plain",
|
|
698
|
-
[get_test_data_path("data/plainfileparser")],
|
|
699
|
-
)
|
|
700
|
-
|
|
701
|
-
with pytest.raises(PlainSyntaxError):
|
|
702
|
-
plain_file.plain_file_parser(
|
|
703
|
-
"required_concepts_partial_duplicate.plain",
|
|
704
|
-
[get_test_data_path("data/plainfileparser")],
|
|
705
|
-
)
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
@pytest.mark.parametrize(
|
|
709
|
-
"fixture",
|
|
710
|
-
[
|
|
711
|
-
"exported_concepts_example.plain",
|
|
712
|
-
"exported_concepts_imported_exported.plain",
|
|
713
|
-
"exported_concepts_multiple_per_bullet.plain",
|
|
714
|
-
"exported_concepts_nested_example.plain",
|
|
715
|
-
],
|
|
716
|
-
)
|
|
717
|
-
def test_exported_concepts_valid(get_test_data_path, fixture):
|
|
718
|
-
plain_file.plain_file_parser(fixture, [get_test_data_path("data/plainfileparser")])
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
@pytest.mark.parametrize(
|
|
722
|
-
("fixture", "expected_word"),
|
|
723
|
-
[
|
|
724
|
-
("exported_concepts_defaults_exported.plain", "cannot export default concept"),
|
|
725
|
-
("exported_concepts_inherited_reexported.plain", "cannot be re-exported"),
|
|
726
|
-
("exported_concepts_malformed.plain", "exports an invalid concept"),
|
|
727
|
-
("exported_concepts_missing_definition_example.plain", "'exported_concepts_missing_definition' exports"),
|
|
728
|
-
("exported_concepts_missing_definition.plain", "exports undefined concept"),
|
|
729
|
-
("exported_concepts_multiple_per_bullet_undefined.plain", "exports undefined concept"),
|
|
730
|
-
("exported_concepts_no_definitions.plain", "exports undefined concept"),
|
|
731
|
-
("exported_concepts_not_declared_example.plain", "not defined"),
|
|
732
|
-
("exported_concepts_transitive_example.plain", "not defined"),
|
|
733
|
-
],
|
|
734
|
-
)
|
|
735
|
-
def test_exported_concepts_invalid(get_test_data_path, fixture, expected_word):
|
|
736
|
-
with pytest.raises(PlainSyntaxError, match=expected_word):
|
|
737
|
-
plain_file.plain_file_parser(fixture, [get_test_data_path("data/plainfileparser")])
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
def test_requires_without_definitions(get_test_data_path):
|
|
741
|
-
_, plain_source, _ = plain_file.plain_file_parser(
|
|
742
|
-
"requires_without_definitions_example.plain",
|
|
743
|
-
[get_test_data_path("data/plainfileparser")],
|
|
744
|
-
)
|
|
745
|
-
assert plain_source[plain_spec.DEFINITIONS] == [{"markdown": "- :Concept: is a concept."}]
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
def test_topological_sort(get_test_data_path):
|
|
749
|
-
_, plain_source, _ = plain_file.plain_file_parser(
|
|
750
|
-
"topological_sort.plain", [get_test_data_path("data/plainfileparser")]
|
|
751
|
-
)
|
|
752
|
-
assert plain_spec.DEFINITIONS in plain_source
|
|
753
|
-
assert plain_source[plain_spec.DEFINITIONS] == [
|
|
754
|
-
{"markdown": "- :Concept1: is a concept."},
|
|
755
|
-
{"markdown": "- :Concept2: is a concept that depends on the :Concept1: concept."},
|
|
756
|
-
{"markdown": "- :Concept3: is a concept that depends on both the :Concept1: and :Concept2: concepts."},
|
|
757
|
-
]
|
|
758
|
-
|
|
759
|
-
_, plain_source, _ = plain_file.plain_file_parser(
|
|
760
|
-
"topological_sort_not_referenced.plain",
|
|
761
|
-
[get_test_data_path("data/plainfileparser")],
|
|
762
|
-
)
|
|
763
|
-
assert plain_spec.DEFINITIONS in plain_source
|
|
764
|
-
assert plain_source[plain_spec.DEFINITIONS] == [
|
|
765
|
-
{"markdown": "- :Concept1: is a concept."},
|
|
766
|
-
{"markdown": "- :NonReferencedConcept: is a concept."},
|
|
767
|
-
{"markdown": "- :Concept7: is a concept."},
|
|
768
|
-
{"markdown": "- :Concept2: is a concept that depends on the :Concept1: concept."},
|
|
769
|
-
{"markdown": "- :Concept8: is a concept that depends on the :Concept1: concept."},
|
|
770
|
-
{"markdown": "- :Concept5: is a concept that depends on the :Concept1: concept."},
|
|
771
|
-
{"markdown": "- :Concept3: is a concept that depends on both the :Concept1: and :Concept2: concepts."},
|
|
772
|
-
{"markdown": "- :Concept9: is a concept that depends on the :Concept8:."},
|
|
773
|
-
{"markdown": "- :Concept4: is a concept that depends on the :Concept3: concept."},
|
|
774
|
-
{"markdown": "- :Concept6: is a concept that depends on the :Concept1: and :Concept4: concepts."},
|
|
775
|
-
]
|