File: test_theme.py

package info (click to toggle)
quark-sphinx-theme 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 308 kB
  • sloc: python: 962; makefile: 3
file content (154 lines) | stat: -rw-r--r-- 4,314 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-
# This file is part of quark-sphinx-theme.
# Copyright (c) 2016 Felix Krull <f_krull@gmx.de>
# Released under the terms of the BSD license; see LICENSE.

import os
import sys
import unittest

DIR = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, DIR)
from util import SphinxBuildFixture, with_document  # noqa


testdoc_theme = os.path.join(DIR, 'testdoc-theme')


class TestThemeDefaults(SphinxBuildFixture, unittest.TestCase):
    source_dir = testdoc_theme

    def test_quark_css(self):
        self.assertSphinxCSSValid('quark.css')

    def _nav_elems(self, doc):
        self.assertHasElement(doc, './/table[@class="nav-sidebar"]')
        self.assertHasElement(doc, './/table[@class="navbar navbar-top"]')
        self.assertHasElement(doc, './/table[@class="navbar navbar-bottom"]')

    @with_document('contents')
    def test_contents_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex')
    def test_genindex_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex-A')
    def test_genindex_a_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex-all')
    def test_genindex_all_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('py-modindex')
    def test_domainindex_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('search')
    def test_search_nav_elements(self, doc):
        self._nav_elems(doc)


class TestThemeExtraCss(SphinxBuildFixture, unittest.TestCase):
    source_dir = testdoc_theme
    config = {
        'html_theme_options.extra_css_files': '_static/extra1.css, '
                                              '_static/extra2.css'
    }

    def test_quark_css(self):
        self.assertSphinxCSSValid('quark.css')

    @with_document('contents')
    def test_contents_css_files(self, doc):
        extra_css = {
            s.strip() for s in
            self.config['html_theme_options.extra_css_files'].split(',')
        }
        for css in doc.findall('head/link[@rel="stylesheet"]'):
            extra_css.discard(css.get('href').strip())
        self.assertSetEqual(extra_css, set())


class TestThemeNoSidebar(SphinxBuildFixture, unittest.TestCase):
    source_dir = testdoc_theme
    config = {
        'html_theme_options.nosidebar': True,
    }

    def test_quark_css(self):
        self.assertSphinxCSSValid('quark.css')

    def _nav_elems(self, doc):
        self.assertNotElement(doc, './/table[@class="nav-sidebar"]')
        self.assertHasElement(doc, './/table[@class="navbar navbar-top"]')
        self.assertHasElement(doc, './/table[@class="navbar navbar-bottom"]')

    @with_document('contents')
    def test_contents_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex')
    def test_genindex_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex-A')
    def test_genindex_a_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('genindex-all')
    def test_genindex_all_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('py-modindex')
    def test_domainindex_nav_elements(self, doc):
        self._nav_elems(doc)

    @with_document('search')
    def test_search_nav_elements(self, doc):
        self._nav_elems(doc)


class TestThemeAllSettingsUnset(SphinxBuildFixture, unittest.TestCase):
    source_dir = testdoc_theme
    _SETTINGS = [
        'text_color',
        'body_font',
        'code_font',
        'body_font_size',
        'code_font_size',
        'li_extra_indent',

        'full_browser_extras',
        'extra_css_files',

        'sidebar_bgcolor',
        'sidebar_border',
        'navbar_color',
        'navbar_bgcolor',

        'link_color',
        'xref_color',
        'headerlink_color',
        'underline_links',
        'underline_navbar_links',

        'code_bgcolor',
        'pre_bgcolor',

        'admonition_border',
        'admonition_fgcolor',
        'admonition_bgcolor',
        'warning_fgcolor',
        'warning_bgcolor',
    ]
    config = {'html_theme_options.%s' % s: '' for s in _SETTINGS}

    def test_quark_css(self):
        self.assertSphinxCSSValid('quark.css')


if __name__ == '__main__':
    unittest.main()