Skip to content

Commit 9e140c7

Browse files
committed
add mkdocs tests
1 parent c610ce1 commit 9e140c7

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from somesy.julia import Julia
1313
from somesy.fortran import Fortran
1414
from somesy.pom_xml.writer import POM
15+
from somesy.mkdocs import MkDocs
1516

1617
TEST_DIR = Path(__file__).resolve().parent
1718

@@ -28,6 +29,7 @@ class FileTypes(Enum):
2829
JULIA = "julia"
2930
FORTRAN = "fortran"
3031
POM_XML = "pom_xml"
32+
MKDOCS = "mkdocs"
3133

3234

3335
@pytest.fixture(scope="session", autouse=True)
@@ -85,6 +87,8 @@ def _create_files(files: Set[Tuple[FileTypes, str]]):
8587
read_file_name = read_file_path / Path("fpm.toml")
8688
elif file_type == FileTypes.POM_XML:
8789
read_file_name = read_file_path / Path("pom.xml")
90+
elif file_type == FileTypes.MKDOCS:
91+
read_file_name = read_file_path / Path("mkdocs.yml")
8892

8993
with open(read_file_name, "r") as f:
9094
content = f.read()
@@ -139,6 +143,9 @@ def _load_files(files: Set[FileTypes]):
139143
elif file_type == FileTypes.POM_XML:
140144
read_file_name = read_file_name / Path("pom.xml")
141145
file_instances[file_type] = POM(read_file_name)
146+
elif file_type == FileTypes.MKDOCS:
147+
read_file_name = read_file_name / Path("mkdocs.yml")
148+
file_instances[file_type] = MkDocs(read_file_name)
142149

143150
return file_instances
144151

tests/data/mkdocs.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# basic configuration:
2+
site_name: "test-package"
3+
site_description: "This is a test package for demonstration purposes."
4+
site_url: "https://example.com/test-package"
5+
repo_url: "https://github.com/example/test-package"
6+
edit_uri: "blob/main/docs/"
7+
repo_name: "/example/test-package"
8+
site_author: "John Doe"
9+
10+
nav:
11+
- Home:
12+
- Overview: index.md
13+
- Changelog: changelog.md
14+
- Credits: credits.md
15+
- License: license.md
16+
- Usage:
17+
- Quickstart: quickstart.md
18+
- User Manual: manual.md
19+
- API: reference/
20+
- Development:
21+
- How To Contribute: contributing.md
22+
- Developer Guide: dev_guide.md
23+
- Code of Conduct: code_of_conduct.md
24+
- Coverage Report: coverage.md
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
from ruamel.yaml import YAML
3+
4+
from somesy.mkdocs.writer import MkDocs
5+
6+
7+
def test_mkdocs_validate_accept(load_files, file_types):
8+
"""Validate by loading the data file using the fixture."""
9+
load_files([file_types.MKDOCS])
10+
11+
12+
def test_mkdocs_validate_reject(tmp_path):
13+
"""Test validating a mkdocs file."""
14+
mkdocs_path = tmp_path / "mkdocs.yml"
15+
16+
# create a mkdocs file with a invalid version
17+
reject_mkdocs_object = {"site_description": "A project"}
18+
yaml = YAML()
19+
yaml.dump(reject_mkdocs_object, mkdocs_path)
20+
21+
# try to load the mkdocs file
22+
with pytest.raises(ValueError):
23+
MkDocs(mkdocs_path)

tests/output/test_mkdocs_writer.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
from somesy.mkdocs import MkDocs
4+
from somesy.core.models import Person
5+
6+
7+
@pytest.fixture
8+
def mkdocs(load_files, file_types):
9+
files = load_files([file_types.MKDOCS])
10+
return files[file_types.MKDOCS]
11+
12+
13+
def test_content_match(mkdocs: MkDocs):
14+
assert mkdocs.name == "test-package"
15+
assert mkdocs.description == "This is a test package for demonstration purposes."
16+
assert len(mkdocs.authors) == 0
17+
18+
19+
def test_sync(mkdocs: MkDocs, somesy_input: dict):
20+
mkdocs.sync(somesy_input.project)
21+
assert mkdocs.name == "testproject"
22+
assert mkdocs.authors[0] == "John Doe <john.doe@example.com>"
23+
assert mkdocs.repo_name == "/example/testproject"
24+
25+
26+
def test_save(tmp_path):
27+
# test save with default path
28+
file_path = tmp_path / "mkdocs.yml"
29+
mkdocs = MkDocs(file_path, create_if_not_exists=True)
30+
mkdocs.save()
31+
assert file_path.is_file()
32+
33+
# test save with custom path
34+
custom_path = tmp_path / "mkdocs2.yml"
35+
mkdocs.save(custom_path)
36+
assert custom_path.is_file()
37+
38+
39+
def test_from_person(person: Person):
40+
p = MkDocs._to_person(MkDocs._from_person(person))
41+
assert p.to_name_email_string() == person.to_name_email_string()

0 commit comments

Comments
 (0)