Skip to content

Commit 5e6db8e

Browse files
authored
Merge pull request rosscdh#10 from rosscdh/feature/tests
[REVIEW] added basic tests
2 parents d11ada0 + cb3c007 commit 5e6db8e

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

‎.gitignore‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
.idea/
2+
venv
3+
.vscode/
24
env/
35
dist/
46
build/
7+
test/site
58
__pycache__/
69
.pytest_cache/
710
*.egg-info/
811

9-
!.gitkeep
12+
!.gitkeep

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ The paths to these become their variable names, so if inside your data folder yo
5252
called `sections/captions.yml`, the data inside that file will be available in your
5353
templates as `sections.captions`.
5454

55-
<br/>
5655

5756
## Features
5857

@@ -75,7 +74,11 @@ and then in your `*.md` files
7574
<a href="{{ customer.web }}">{{ customer.web }}</a>
7675
```
7776

78-
<br/>
77+
## Testing
78+
79+
```
80+
pytest test
81+
```
7982
8083
## Contributing
8184

‎shell.nix‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# for NixOS: nix-shell for locally using the plugin
2+
3+
with import <nixpkgs> {};
4+
with pkgs.python3Packages;
5+
6+
buildPythonPackage rec {
7+
name = "mkdocs-markdownextradata-plugin";
8+
src = ./.;
9+
propagatedBuildInputs = [ ];
10+
}

‎test/docs/index.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hi there, {{ customer.name }}
2+
3+
Welcome to {{ customer.web_url }}

‎test/mkdocs.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
site_name: test markdownextradata_plugin
2+
use_directory_urls: true
3+
# theme:
4+
# name: null
5+
# custom_dir: 'theme/'
6+
plugins:
7+
- search
8+
- markdownextradata
9+
10+
extra:
11+
customer:
12+
name: Your name here
13+
web_url: www.example.com

‎test/test_basic.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import yaml
3+
import click
4+
import pytest
5+
import tempfile
6+
from pathlib import Path
7+
from click.testing import CliRunner
8+
from mkdocs.__main__ import build_command
9+
10+
config = yaml.load(open('test/mkdocs.yml', 'rb'), Loader=yaml.Loader)
11+
12+
def test_basic_working():
13+
runner = CliRunner()
14+
customer = config.get('extra', {}).get('customer', {})
15+
16+
with tempfile.TemporaryDirectory() as tmpdir:
17+
result = runner.invoke(build_command, ['--config-file', 'test/mkdocs.yml', '--site-dir', tmpdir])
18+
assert result.exit_code == 0
19+
20+
index_file = Path(tmpdir) / 'index.html'
21+
assert index_file.exists(), f"{index_file} does not exist, it should"
22+
contents = index_file.read_text()
23+
24+
assert f"Hi there, {customer.get('name')}" in contents, f"customer.name is not in index"
25+
assert f"Welcome to {customer.get('web_url')}" in contents, f"customer.web_url is not in index"

0 commit comments

Comments
 (0)