def test_theme_config_missing_name(self): config = { 'custom_dir': 'custom', } option = config_options.Theme() self.assertRaises(config_options.ValidationError, option.validate, config)
def test_uninstalled_theme_as_config(self): config = { 'name': 'mkdocs2' } option = config_options.Theme() self.assertRaises(config_options.ValidationError, option.validate, config)
def test_theme_as_simple_config(self): config = { 'name': 'mkdocs' } option = config_options.Theme() value = option.validate(config) self.assertEqual(config, value)
def test_theme_name_is_none(self): config = { 'name': None } option = config_options.Theme() value = option.validate(config) self.assertEqual(config, value)
def test_theme_as_complex_config(self): config = { 'name': 'mkdocs', 'custom_dir': 'custom', 'static_templates': ['sitemap.html'], 'show_sidebar': False } option = config_options.Theme() value = option.validate(config) self.assertEqual(config, value)
# Defines the structure of the navigation. ('nav', config_options.Nav()), # TODO: remove this when the `pages` config setting is fully deprecated. ('pages', config_options.Nav()), # The full URL to where the documentation will be hosted ('site_url', config_options.URL()), # A description for the documentation project that will be added to the # HTML meta tags. ('site_description', config_options.Type(str)), # The name of the author to add to the HTML meta tags ('site_author', config_options.Type(str)), # The MkDocs theme for the documentation. ('theme', config_options.Theme(default='mkdocs')), # The directory containing the documentation markdown. ('docs_dir', config_options.Dir(default='docs', exists=True)), # The directory where the site will be built to ('site_dir', config_options.SiteDir(default='site')), # A copyright notice to add to the footer of documentation. ('copyright', config_options.Type(str)), # set of values for Google analytics containing the account IO and domain, # this should look like, ['UA-27795084-5', 'mkdocs.org'] ('google_analytics', config_options.Type(list, length=2)), # The address on which to serve the live reloading docs server.
def test_theme_invalid_type(self): config = ['mkdocs2'] option = config_options.Theme() self.assertRaises(config_options.ValidationError, option.validate, config)
def test_theme_default(self): option = config_options.Theme(default='mkdocs') value = option.validate(None) self.assertEqual({'name': 'mkdocs'}, value)
def test_uninstalled_theme_as_string(self): option = config_options.Theme() self.assertRaises(config_options.ValidationError, option.validate, "mkdocs2")
def test_theme_as_string(self): option = config_options.Theme() value = option.validate("mkdocs") self.assertEqual({'name': 'mkdocs'}, value)
def test_theme(self): with TemporaryDirectory() as mytheme, TemporaryDirectory() as custom: configs = [ dict(), # default theme { "theme": "readthedocs" }, # builtin theme { "theme": { 'name': 'readthedocs' } }, # builtin as complex { "theme": { 'name': None, 'custom_dir': mytheme } }, # custom only as complex { "theme": { 'name': 'readthedocs', 'custom_dir': custom } }, # builtin and custom as complex { # user defined variables 'theme': { 'name': 'mkdocs', 'static_templates': ['foo.html'], 'show_sidebar': False, 'some_var': 'bar' } } ] mkdocs_dir = os.path.abspath(os.path.dirname(mkdocutils.__file__)) mkdocs_templates_dir = os.path.join(mkdocs_dir, 'templates') theme_dir = os.path.abspath(os.path.join(mkdocs_dir, 'themes')) results = ({ 'dirs': [os.path.join(theme_dir, 'mkdocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': False, 'search_index_only': False, 'highlightjs': True, 'hljs_style': 'github', 'hljs_languages': [], 'navigation_depth': 2, 'nav_style': 'primary', 'shortcuts': { 'help': 191, 'next': 78, 'previous': 80, 'search': 83 } } }, { 'dirs': [os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False, 'highlightjs': True, 'hljs_languages': [], 'include_homepage_in_sidebar': True, 'prev_next_buttons_location': 'bottom', 'navigation_depth': 4, 'sticky_navigation': True, 'titles_only': False, 'collapse_navigation': True } }, { 'dirs': [os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False, 'highlightjs': True, 'hljs_languages': [], 'include_homepage_in_sidebar': True, 'prev_next_buttons_location': 'bottom', 'navigation_depth': 4, 'sticky_navigation': True, 'titles_only': False, 'collapse_navigation': True } }, { 'dirs': [mytheme, mkdocs_templates_dir], 'static_templates': ['sitemap.xml'], 'vars': {} }, { 'dirs': [ custom, os.path.join(theme_dir, 'readthedocs'), mkdocs_templates_dir ], 'static_templates': ['404.html', 'sitemap.xml'], 'vars': { 'include_search_page': True, 'search_index_only': False, 'highlightjs': True, 'hljs_languages': [], 'include_homepage_in_sidebar': True, 'prev_next_buttons_location': 'bottom', 'navigation_depth': 4, 'sticky_navigation': True, 'titles_only': False, 'collapse_navigation': True } }, { 'dirs': [os.path.join(theme_dir, 'mkdocs'), mkdocs_templates_dir], 'static_templates': ['404.html', 'sitemap.xml', 'foo.html'], 'vars': { 'show_sidebar': False, 'some_var': 'bar', 'include_search_page': False, 'search_index_only': False, 'highlightjs': True, 'hljs_style': 'github', 'hljs_languages': [], 'navigation_depth': 2, 'nav_style': 'primary', 'shortcuts': { 'help': 191, 'next': 78, 'previous': 80, 'search': 83 } } }) for config_contents, result in zip(configs, results): c = config.Config(schema=(('theme', config_options.Theme( default='mkdocs')), )) c.load_dict(config_contents) errors, warnings = c.validate() self.assertEqual(len(errors), 0) self.assertEqual(c['theme'].dirs, result['dirs']) self.assertEqual(c['theme'].static_templates, set(result['static_templates'])) self.assertEqual({k: c['theme'][k] for k in iter(c['theme'])}, result['vars'])