Skip to content

Commit 7870c6f

Browse files
committed
Turn examples into unit tests. Add TODO and skip test for now.
1 parent 2181eaf commit 7870c6f

File tree

8 files changed

+56
-2
lines changed

8 files changed

+56
-2
lines changed
File renamed without changes.

mkdocstrings_handlers/vba/collector.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class VbaCollector(BaseCollector):
1818
Collect data from a VBA file.
1919
"""
2020

21+
base_dir: Path
22+
23+
def __init__(self, base_dir: Path) -> None:
24+
super().__init__()
25+
self.base_dir = base_dir
26+
2127
def collect(
2228
self,
2329
identifier: str,
@@ -35,7 +41,7 @@ def collect(
3541
Returns:
3642
The collected object tree.
3743
"""
38-
p = Path(identifier)
44+
p = Path(self.base_dir, identifier)
3945
with p.open("r") as f:
4046
code = f.read()
4147

mkdocstrings_handlers/vba/handler.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module implements a handler for the VBA language."""
22

33
import posixpath
4+
from pathlib import Path
45
from typing import Any, BinaryIO, Iterator, Optional, Tuple
56

67
from griffe.logger import patch_loggers
@@ -67,6 +68,8 @@ def get_handler(
6768
An instance of `VbaHandler`.
6869
"""
6970
return VbaHandler(
70-
collector=VbaCollector(),
71+
# TODO How do we get the path of the directory containing mkdocs.yml here?
72+
# Indentifiers for .bas files need to be found relative to that.
73+
collector=VbaCollector(base_dir=Path(".")),
7174
renderer=VbaRenderer("vba", theme, custom_templates),
7275
)

test/test_examples.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
from contextlib import contextmanager
3+
from pathlib import Path
4+
from tempfile import TemporaryDirectory
5+
6+
from locate import this_dir
7+
from mkdocs.commands.build import build
8+
from mkdocs.config import load_config
9+
10+
repo_dir = this_dir().parent
11+
examples_dir = repo_dir.joinpath("examples")
12+
13+
14+
@contextmanager
15+
def tmp_build(config_file_path: Path):
16+
with TemporaryDirectory() as tmp_dir:
17+
tmp_dir = Path(tmp_dir)
18+
19+
with config_file_path.open(mode="rb") as f:
20+
config = load_config(config_file=f)
21+
config["site_dir"] = tmp_dir
22+
build(
23+
config=config,
24+
dirty=False,
25+
live_server=False,
26+
)
27+
28+
try:
29+
yield tmp_dir
30+
finally:
31+
pass
32+
33+
34+
class TestExamples(unittest.TestCase):
35+
def test_example1(self):
36+
raise unittest.SkipTest
37+
38+
with tmp_build(examples_dir.joinpath("example1", "mkdocs.yml")) as tmp_dir:
39+
pass
40+
41+
42+
if __name__ == "__main__":
43+
unittest.main(
44+
failfast=True,
45+
)

0 commit comments

Comments
 (0)