Beispiel #1
0
    def test_html_and_raw_builders_in_different_dirs(self):
        prj = self._prj()
        base_yaml_conf_two_builders = """
docs:
    docs:
        builder: html
        html_short_title: testsub
        dir: html_docs
        html_theme: default
    pages:
        builder: raw
        dir: pages
"""
        self._add(prj, "code_config.yaml", base_yaml_conf_two_builders)
        self._add(prj, "html_docs/index.rst", base_index_rst)
        self._add(prj, "html_docs/doc1.rst", base_document1_rst)
        self._add(prj, "pages/index.html", self.html1)
        sd = SphinxDocs(prj.name)
        sd.build_all()
        assert sd.builders == ["docs", "pages"]
        raw_builder = sd.get_builder("pages")
        doc = raw_builder.raw_content("index.html", {})
        assert doc == self.html1
        html_builder = sd.get_builder("docs")
        assert not html_builder.template
        raw = html_builder.raw_content("index.html", {})
        assert "<h1>Unit testing sphinx docs" in raw
Beispiel #2
0
 def test_html_and_raw_builders(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         html:
             dir: docs
             builder: html
         raw:
             dir: docs
             builder: raw
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'docs/index.rst', base_index_rst)
     self._add(prj, 'docs/index.html', self.html1)
     self._add(prj, 'docs/doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['html', 'raw']
     raw_builder = sd.get_builder('raw')
     doc = raw_builder.raw_content('index.html', {})
     assert doc == self.html1
     html_builder = sd.get_builder('html')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #3
0
 def test_two_builders_with_other_config_fmt(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     #sphinx_docs:
     #    dir: "docs"
     #    builders:
     #        - html:
     #            html_theme: default
     #            html_short_title: testsub
     #            dir: html_docs
     #        - raw:
     #            dir: pages
     docs:
         docs:
             builder: html
             html_theme: default
             html_short_title: testsub
             dir: html_docs
         pages:
             builder: raw
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'html_docs/index.rst', base_index_rst)
     self._add(prj, 'html_docs/doc1.rst', base_document1_rst)
     self._add(prj, 'pages/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['docs', 'pages']  # noqa Sorted alphabetically by default
     raw_builder = sd.get_builder('pages')
     doc = raw_builder.raw_content('index.html', {})
     assert doc == self.html1
     html_builder = sd.get_builder('docs')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #4
0
 def test_two_builders_with_other_config_fmt(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         docs:
             builder: html
             html_theme: default
             html_short_title: testsub
             dir: html_docs
         pages:
             builder: raw
     """
     self._add(prj, "code_config.yaml", base_yaml_conf_two_builders)
     self._add(prj, "html_docs/index.rst", base_index_rst)
     self._add(prj, "html_docs/doc1.rst", base_document1_rst)
     self._add(prj, "pages/index.html", self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ["docs", "pages"]  # noqa Sorted alphabetically by default
     raw_builder = sd.get_builder("pages")
     doc = raw_builder.raw_content("index.html", {})
     assert doc == self.html1
     html_builder = sd.get_builder("docs")
     assert not html_builder.template
     raw = html_builder.raw_content("index.html", {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #5
0
 def test_create_with_index_and_doc_and_two_builders(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         docs:
             builder: html
             dir: ""
             html_theme: default
             html_short_title: testsub
         docs2:
             dir: ""
             builder: pickle
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'index.rst', base_index_rst)
     self._add(prj, 'doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['docs', 'docs2']
     pickle_builder = sd.get_builder('docs2')
     assert pickle_builder.template
     doc = pickle_builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
     html_builder = sd.get_builder('docs')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #6
0
 def test_html_and_raw_builders_in_different_dirs(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         html:
             dir: html_docs
             builder: html
         raw:
             builder: raw
             dir: pages
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'html_docs/index.rst', base_index_rst)
     self._add(prj, 'html_docs/doc1.rst', base_document1_rst)
     self._add(prj, 'pages/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['html', 'raw']
     raw_builder = sd.get_builder('raw')
     doc = raw_builder.raw_content('index.html', {})
     assert doc == self.html1
     html_builder = sd.get_builder('html')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #7
0
    def test_html_and_raw_builders_in_different_dirs(self):
        prj = self._prj()
        base_yaml_conf_two_builders = """
docs:
    docs:
        builder: html
        html_short_title: testsub
        dir: html_docs
        html_theme: default
    pages:
        builder: raw
        dir: pages
"""
        self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
        self._add(prj, 'html_docs/index.rst', base_index_rst)
        self._add(prj, 'html_docs/doc1.rst', base_document1_rst)
        self._add(prj, 'pages/index.html', self.html1)
        sd = SphinxDocs(prj.name)
        sd.build_all()
        assert sd.builders == ['docs', 'pages']
        raw_builder = sd.get_builder('pages')
        doc = raw_builder.raw_content('index.html', {})
        assert doc == self.html1
        html_builder = sd.get_builder('docs')
        assert not html_builder.template
        raw = html_builder.raw_content('index.html', {})
        assert "<h1>Unit testing sphinx docs" in raw
Beispiel #8
0
 def test_create_with_index_and_doc_and_two_builders(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         html:
             dir: ''
             builder: html
         pickle:
             dir: ''
             builder: pickle
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'index.rst', base_index_rst)
     self._add(prj, 'doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['html', 'pickle']
     pickle_builder = sd.get_builder('pickle')
     assert pickle_builder.template
     doc = pickle_builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
     html_builder = sd.get_builder('html')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #9
0
 def test_create_with_index_and_doc_and_two_builders(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         docs:
             builder: html
             dir: ""
             html_theme: default
             html_short_title: testsub
         docs2:
             dir: ""
             builder: pickle
     """
     self._add(prj, "code_config.yaml", base_yaml_conf_two_builders)
     self._add(prj, "index.rst", base_index_rst)
     self._add(prj, "doc1.rst", base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ["docs", "docs2"]
     pickle_builder = sd.get_builder("docs2")
     assert pickle_builder.template
     doc = pickle_builder.template_data("", {})
     assert doc["title"] == "Unit testing sphinx docs"
     html_builder = sd.get_builder("docs")
     assert not html_builder.template
     raw = html_builder.raw_content("index.html", {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #10
0
 def test_two_builders_with_other_config_fmt(self):
     prj = self._prj()
     base_yaml_conf_two_builders = """
     docs:
         docs:
             builder: html
             html_theme: default
             html_short_title: testsub
             dir: html_docs
         pages:
             builder: raw
     """
     self._add(prj, 'code_config.yaml', base_yaml_conf_two_builders)
     self._add(prj, 'html_docs/index.rst', base_index_rst)
     self._add(prj, 'html_docs/doc1.rst', base_document1_rst)
     self._add(prj, 'pages/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.builders == ['docs', 'pages']  # noqa Sorted alphabetically by default
     raw_builder = sd.get_builder('pages')
     doc = raw_builder.raw_content('index.html', {})
     assert doc == self.html1
     html_builder = sd.get_builder('docs')
     assert not html_builder.template
     raw = html_builder.raw_content('index.html', {})
     assert "<h1>Unit testing sphinx docs" in raw
Beispiel #11
0
 def test_create_with_index_and_doc(self):
     prj = self._prj()
     self._add(prj, 'docs/index.rst', base_index_rst)
     self._add(prj, 'docs/doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
Beispiel #12
0
 def test_create_with_index_and_doc(self):
     prj = self._prj()
     self._add(prj, 'docs/index.rst', base_index_rst)
     self._add(prj, 'docs/doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
Beispiel #13
0
 def test_pages_no_docsdir(self):
     prj = self._prj()
     self._add(prj, "code_config.yaml", self.conf)
     self._add(prj, "pagesNOT_THE_SAME/index.html", self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.last_build_info()["status"] == "no_doc_dir_found"
     builder = sd.get_builder(sd.builders[0])
     assert builder.raw_content("index.html", {}) is False
Beispiel #14
0
 def test_pages_no_docsdir(self):
     prj = self._prj()
     self._add(prj, 'code_config.yaml', self.conf)
     self._add(prj, 'pagesNOT_THE_SAME/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     assert sd.last_build_info()['status'] == 'no_doc_dir_found'
     builder = sd.get_builder(sd.builders[0])
     assert builder.raw_content('index.html', {}) is False
Beispiel #15
0
 def test_use_autodoc_not_configured(self):
     prj = self._prj()
     self._add(prj, 'docs/conf.py', self.conf_py)
     self._add(prj, 'docs/index.rst', self.index_rst)
     self._add(prj, 'testapi.py', self.api_py)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert "Test C docstring" not in doc['body']
Beispiel #16
0
 def test_create_with_index_and_doc(self):
     prj = self._prj()
     self._add(prj, "code_config.yaml", base_yaml_conf)
     self._add(prj, "index.rst", base_index_rst)
     self._add(prj, "doc1.rst", base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder("docs")
     doc = builder.template_data("", {})
     assert doc["title"] == "Unit testing sphinx docs"
Beispiel #17
0
 def test_use_autodoc_not_configured(self):
     prj = self._prj()
     self._add(prj, 'docs/conf.py', self.conf_py)
     self._add(prj, 'docs/index.rst', self.index_rst)
     self._add(prj, 'testapi.py', self.api_py)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert "Test C docstring" not in doc['body']
Beispiel #18
0
 def test_create_with_index_and_doc_and_conf_py(self):
     conf_content = """rst_epilog = 'Ahhhhhhhhhhhhhhhh la fin' """
     prj = self._prj()
     self._add(prj, 'docs/index.rst', base_index_rst)
     self._add(prj, 'docs/doc1.rst', base_document1_rst)
     self._add(prj, 'docs/conf.py', conf_content)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert 'Ahhhhhhhhhhhhhhhh' in doc['body']
Beispiel #19
0
 def test_pages_mode(self):
     prj = self._prj()
     self._add(prj, 'code_config.yaml', self.conf)
     self._add(prj, 'pages/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     assert sd.builders == [self.builder]
     assert sd.last_build_info() is None
     sd.build_all()
     assert sd.last_build_info()['status'] == 'success'
     builder = sd.get_builder(sd.builders[0])
     assert builder.raw_content('index.html', {}) == self.html1
Beispiel #20
0
 def test_pages_mode(self):
     prj = self._prj()
     self._add(prj, 'code_config.yaml', self.conf)
     self._add(prj, 'pages/index.html', self.html1)
     sd = SphinxDocs(prj.name)
     assert sd.builders == ['pages']
     assert sd.last_build_info() is None
     sd.build_all()
     assert sd.last_build_info()['status'] == 'success'
     builder = sd.get_builder(sd.builders[0])
     assert builder.raw_content('index.html', {}) == self.html1
Beispiel #21
0
 def test_create_with_index_and_doc_and_conf_py(self):
     conf_content = """rst_epilog = 'Ahhhhhhhhhhhhhhhh la fin' """
     prj = self._prj()
     self._add(prj, 'docs/index.rst', base_index_rst)
     self._add(prj, 'docs/doc1.rst', base_document1_rst)
     self._add(prj, 'docs/conf.py', conf_content)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     builder = sd.get_builder()
     doc = builder.template_data('', {})
     assert 'Ahhhhhhhhhhhhhhhh' in doc['body']
Beispiel #22
0
 def test_pages_mode(self):
     prj = self._prj()
     self._add(prj, "code_config.yaml", self.conf)
     self._add(prj, "pages/index.html", self.html1)
     sd = SphinxDocs(prj.name)
     assert sd.builders == ["pages"]
     assert sd.last_build_info() is None
     sd.build_all()
     assert sd.last_build_info()["status"] == "success"
     builder = sd.get_builder(sd.builders[0])
     assert builder.raw_content("index.html", {}) == self.html1
Beispiel #23
0
 def test_create_with_index_and_doc_and_get_again(self):
     prj = self._prj()
     self._add(prj, 'code_config.yaml', base_yaml_conf)
     self._add(prj, 'index.rst', base_index_rst)
     self._add(prj, 'doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     sd2 = SphinxDocs(prj.name)
     builder = sd2.get_builder('docs')
     assert builder.template
     doc = builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
Beispiel #24
0
 def test_create_with_index_and_doc_and_get_again(self):
     prj = self._prj()
     self._add(prj, 'code_config.yaml', base_yaml_conf)
     self._add(prj, 'index.rst', base_index_rst)
     self._add(prj, 'doc1.rst', base_document1_rst)
     sd = SphinxDocs(prj.name)
     sd.build_all()
     sd2 = SphinxDocs(prj.name)
     builder = sd2.get_builder()
     assert builder.template
     doc = builder.template_data('', {})
     assert doc['title'] == 'Unit testing sphinx docs'
Beispiel #25
0
class SphinxDocsUI:
    _q_exports = []

    def __init__(self, proj_name):
        self.proj = proj_name

    def _q_access(self, request):
        self.docs = SphinxDocs(self.proj)
        if not self.docs.enabled:
            raise TraversalError(
                "docs not enabled: %s" % self.docs.disabled_reason)
        self.builder_name, self.explicit_builder = guess_builder_from_path(
            self.docs.builders, self.proj, request.get_path())
        if self.explicit_builder:
            self.base_path = "/%s/docs/%s/" % (self.proj, self.builder_name)
        else:
            self.base_path = "/%s/docs/" % (self.proj)
        self.builder = self.docs.get_builder(self.builder_name)
        if not self.builder:
            raise TraversalError("Unknown builder")

    def _q_index(self, request):
        return self.get_content(request, '')

    def get_content(self, request, path):
        tdt = _tmpl_common_data(None, path, self.proj, request)
        if not self.builder.has_content():
            tdt['docsdir'] = self.builder.dir
            return st('sphinx_docs_start.html', **tdt)
        if path in self.builder.redirects:
            return request.redirect("%s%s" % (
                self.base_path, self.builder.redirects[path]))
        if self.builder.file_is_static(path):
            # Serve static files, cannot use nginx rerouting because
            # code permdir is not on MFS
            content = self.builder.file_content(path)
            if content is False:
                raise TraversalError(
                    "Static content not found in %s" % path)
            ct = mimetypes.guess_type(path)
            request.response.set_content_type(
                ct[0] if ct else 'application/octet-stream')
            return content
        fvars = dict((_, request.get_form_var(
            _)) for _ in self.builder.needed_form_vars)
        if self.builder.template:
            tdt['doc'] = {
                'with_comment': self.builder.with_comment(),
                'docsdir': self.builder.dir,
                'base_path': self.base_path,
            }
            tdt['doc'].update(self.builder.template_data(path, fvars))
            return st(self.builder.template, **tdt)
        else:
            content = self.builder.raw_content(path, fvars)
            if content is False:
                raise TraversalError(
                    "Builder %s did not find content file for %s" % (
                        self.builder_name, path))
            return content

    def _q_lookup(self, request, piece):
        if self.explicit_builder:
            assert piece == self.builder_name, \
                "Explicit builder means it is in url: proj/docs/builder_name/..."  # noqa
            piece = ''
        if self.builder.slash_urls:
            return DocsRecursorUI(self.proj, piece, self.get_content)
        else:
            return DocsRecursorUICallable(self.proj, piece, self.get_content)