Skip to content

Commit

Permalink
test: add some function to validate theme overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
aladjadj committed May 23, 2022
1 parent b93b069 commit 42ef6d5
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import mkdocs.plugins as plugins
from mkdocs.theme import Theme
from .core import TechDocsCore
from .core import TechDocsCore, TECHDOCS_DEFAULT_THEME
from jinja2 import Environment, PackageLoader, select_autoescape
import json

Expand Down Expand Up @@ -51,17 +51,39 @@ def test_override_default_config_with_user_config(self):
self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])

def test_remove_theme_config_with_user_options(self):
def test_theme_overrides_removed_when_name_is_not_material(self):
## we want to force the theme mkdocs to this test
self.mkdocs_yaml_config["theme"] = Theme(name="mkdocs")
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertFalse("navigation.sections" in final_config["theme"]["features"])

def test_override_theme_config_with_user_config(self):
self.mkdocs_yaml_config["theme"] = Theme(name="material")
def test_theme_overrides_when_name_is_material(self):
self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertTrue("navigation.sections" in final_config["theme"]["features"])

def test_theme_overrides_techdocs_metadata(self):
self.mkdocs_yaml_config["theme"] = Theme(
name=TECHDOCS_DEFAULT_THEME, static_templates=["my_static_temples"]
)
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertTrue("my_static_temples" in final_config["theme"].static_templates)
self.assertTrue(
"techdocs_metadata.json" in final_config["theme"].static_templates
)

def test_theme_overrides_dirs(self):
custom_theme_dir = "/tmp/my_custom_theme_dir"
self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
self.mkdocs_yaml_config["theme"].dirs.append(custom_theme_dir)
final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
self.assertTrue(custom_theme_dir in final_config["theme"].dirs)
self.assertTrue(
self.techdocscore.tmp_dir_techdocs_theme.name in final_config["theme"].dirs
)

def test_template_renders__multiline_value_as_valid_json(self):
self.techdocscore.on_config(self.mkdocs_yaml_config)
env = Environment(
Expand Down

0 comments on commit 42ef6d5

Please sign in to comment.