-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_docs.py
More file actions
41 lines (33 loc) · 1.37 KB
/
test_docs.py
File metadata and controls
41 lines (33 loc) · 1.37 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
from pathlib import Path
import pytest
from sybil import Sybil
from sybil.parsers.codeblock import PythonCodeBlockParser
from sybil.parsers.doctest import DocTestParser
def collect_examples(folder_name):
docs_folder_path = Path(__file__).parent.parent.parent / "docs" / "source"
models_folder_path = docs_folder_path / folder_name
assert docs_folder_path.exists(), f"Docs path doesn't exist: {docs_folder_path.resolve()}"
all_rst_files = list(docs_folder_path.glob("*.rst"))
all_rst_files.extend(list(models_folder_path.glob("*.rst")))
print(f"Found {len(all_rst_files)} .rst files in docs folder.")
# Configure Sybil
sybil = Sybil(
parsers=[
DocTestParser(),
PythonCodeBlockParser(),
],
pattern="*.rst",
path=docs_folder_path.as_posix(),
)
examples_list = []
for f_path in all_rst_files:
document_ = sybil.parse(f_path)
examples_ = list(document_)
examples_files = [e.path for e in examples_]
examples_start_lines = [e.start for e in examples_]
examples_list.extend(zip(examples_files, examples_start_lines, examples_))
# examples_list=[example for example in examples_]
return examples_list
@pytest.mark.parametrize("file_path, line, example", collect_examples(""))
def test_doc_examples(file_path, line, example):
example.evaluate()