def test(monkeypatch, tmpdir, expected, rst_title, option):
    """Test valid and invalid values."""
    tmpdir.join('conf.py').write(
        BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
    tmpdir.join('conf.py').write('', mode='a')
    tmpdir.join('index.rst').write(
        '{}.. toctree::\n    :maxdepth: 2\n.. disqus::\n{}'.format(
            rst_title, option))
    monkeypatch.setattr(directives, '_directives',
                        getattr(directives, '_directives').copy())
    monkeypatch.setattr(roles, '_roles', getattr(roles, '_roles').copy())

    srcdir = confdir = str(tmpdir)
    outdir = tmpdir.join('_build', 'html')
    doctreedir = outdir.join('doctrees').ensure(dir=True, rec=True)
    app = application.Sphinx(srcdir, confdir, str(outdir), str(doctreedir),
                             'html')

    if expected:
        app.builder.build_all()
        html_body = outdir.join('index.html').read()
        disqus_div = re.findall(r'(<div[^>]+ id="disqus_thread"[^>]*></div>)',
                                html_body)[0]
        assert 'data-disqus-identifier="{}"'.format(expected) in disqus_div
        return

    with pytest.raises(DisqusError) as exc:
        app.builder.build_all()
    assert 'No title nodes found in document, cannot derive disqus_identifier config value.' == exc.value.args[
        0]
示例#2
0
    def run(self):
        build_cmd = self.get_finalized_command('build')
        build_dir = os.path.join(os.path.abspath(build_cmd.build_base),
                                 'swagger')
        self.mkpath(build_dir)
        doctree_dir = os.path.join(build_dir, 'doctrees')
        self.mkpath(doctree_dir)

        overrides = {}
        if self.output_file is not None:
            overrides['swagger_file'] = self.output_file

        if not self.ignore_distinfo:
            if self.distribution.get_description():
                overrides['swagger_description'] = \
                    self.distribution.get_description()
            if self.distribution.get_license():
                overrides['swagger_license.name'] = \
                    self.distribution.get_license()
            if self.distribution.get_version():
                overrides['version'] = self.distribution.get_version()

        app = application.Sphinx(self.config_dir,
                                 self.config_dir,
                                 build_dir,
                                 doctree_dir,
                                 'swagger',
                                 confoverrides=overrides)
        app.build()
def test(monkeypatch, tmpdir, tail, expected_error):
    """Test valid and invalid values."""
    tmpdir.join('conf.py').write(
        BASE_CONFIG.format(py.path.local(__file__).join('..', '..')))
    tmpdir.join('conf.py').write(tail, mode='a')
    tmpdir.join('index.rst').write(
        '====\nMain\n====\n\n.. toctree::\n    :maxdepth: 2\n.. disqus::')
    monkeypatch.setattr(directives, '_directives',
                        getattr(directives, '_directives').copy())
    monkeypatch.setattr(roles, '_roles', getattr(roles, '_roles').copy())

    srcdir = confdir = str(tmpdir)
    outdir = tmpdir.join('_build', 'html')
    doctreedir = outdir.join('doctrees').ensure(dir=True, rec=True)
    app = application.Sphinx(srcdir, confdir, str(outdir), str(doctreedir),
                             'html')

    if not expected_error:
        app.builder.build_all()
        html_body = outdir.join('index.html').read()
        disqus_div = re.findall(r'(<div[^>]+ id="disqus_thread"[^>]*></div>)',
                                html_body)[0]
        assert 'data-disqus-shortname="good"' in disqus_div
        return

    with pytest.raises(errors.ExtensionError) as exc:
        app.builder.build_all()
    assert expected_error == exc.value.args[0]
示例#4
0
    def _sphinx_run(self, warnerrors):
        if not self.verbose:
            status_stream = cStringIO.StringIO()
        else:
            status_stream = sys.stdout
        confoverrides = {}
        if self.project:
            confoverrides['project'] = self.project
        if self.version:
            confoverrides['version'] = self.version
        if self.release:
            confoverrides['release'] = self.release
        if self.today:
            confoverrides['today'] = self.today
        sphinx_config = config.Config(self.config_dir, 'conf.py', {}, [])
        sphinx_ver = pkg_resources.parse_version(
            pkg_resources.get_distribution("sphinx").version)
        if sphinx_ver > pkg_resources.parse_version('1.2.3'):
            sphinx_config.init_values(warnings.warn)
        else:
            sphinx_config.init_values()
        if self.builder == 'man' and len(sphinx_config.man_pages) == 0:
            return
        if self.sphinx_initialized:
            if sphinx_ver >= pkg_resources.parse_version('1.4.2'):
                confoverrides['suppress_warnings'] = [
                    'app.add_directive', 'app.add_role',
                    'app.add_generic_role', 'app.add_node']
            elif sphinx_ver >= pkg_resources.parse_version('1.4.0'):
                log.warn("[pbr] WARN: Sphinx versions 1.4.0 and 1.4.1 raise "
                         "warnings during this run and will cause warnerrors "
                         "to fail.  For more information see: "
                         "http://docs.openstack.org/developer/pbr/"
                         "compatibility.html#sphinx-1.4")
        app = application.Sphinx(
            self.source_dir, self.config_dir,
            self.builder_target_dir, self.doctree_dir,
            self.builder, confoverrides, status_stream,
            freshenv=self.fresh_env, warningiserror=warnerrors)
        self.sphinx_initialized = True

        try:
            app.build(force_all=self.all_files)
        except Exception as err:
            from docutils import utils
            if isinstance(err, utils.SystemMessage):
                sys.stder.write('reST markup error:\n')
                sys.stderr.write(err.args[0].encode('ascii',
                                                    'backslashreplace'))
                sys.stderr.write('\n')
            else:
                raise

        if self.link_index:
            src = app.config.master_doc + app.builder.out_suffix
            dst = app.builder.get_outfilename('index')
            os.symlink(src, dst)
示例#5
0
    def _sphinx_run(self):
        if not self.verbose:
            status_stream = cStringIO.StringIO()
        else:
            status_stream = sys.stdout
        confoverrides = {}
        if self.project:
            confoverrides['project'] = self.project
        if self.version:
            confoverrides['version'] = self.version
        if self.release:
            confoverrides['release'] = self.release
        if self.today:
            confoverrides['today'] = self.today
        sphinx_config = config.Config(self.config_dir, 'conf.py', {}, [])
        sphinx_ver = pkg_resources.parse_version(
            pkg_resources.get_distribution("sphinx").version)
        if sphinx_ver > pkg_resources.parse_version('1.2.3'):
            sphinx_config.init_values(warnings.warn)
        else:
            sphinx_config.init_values()
        if self.builder == 'man' and len(
                getattr(sphinx_config, 'man_pages', '')) == 0:
            return
        if self.sphinx_initialized:
            confoverrides['suppress_warnings'] = [
                'app.add_directive', 'app.add_role', 'app.add_generic_role',
                'app.add_node'
            ]
        app = application.Sphinx(self.source_dir,
                                 self.config_dir,
                                 self.builder_target_dir,
                                 self.doctree_dir,
                                 self.builder,
                                 confoverrides,
                                 status_stream,
                                 freshenv=self.fresh_env,
                                 warningiserror=self.warning_is_error)
        self.sphinx_initialized = True

        try:
            app.build(force_all=self.all_files)
        except Exception as err:
            from docutils import utils
            if isinstance(err, utils.SystemMessage):
                sys.stder.write('reST markup error:\n')
                sys.stderr.write(err.args[0].encode('ascii',
                                                    'backslashreplace'))
                sys.stderr.write('\n')
            else:
                raise

        if self.link_index:
            src = app.config.master_doc + app.builder.out_suffix
            dst = app.builder.get_outfilename('index')
            os.symlink(src, dst)
示例#6
0
    def test_it(self):
        from sphinx import application

        docs_dir = self._make_temp_docs()
        outdir = os.path.join(docs_dir, 'doctest', 'out')
        doctreedir = os.path.join(docs_dir, 'doctest', 'doctrees')

        app = application.Sphinx(
            srcdir=docs_dir, confdir=docs_dir,
            outdir=outdir, doctreedir=doctreedir,
            buildername='doctest', warningiserror=True, parallel=1)

        app.build()
        self.assertEqual(app.statuscode, 0)
示例#7
0
文件: main.py 项目: rblack42/lpblock
def main():
    with open('conf.py', 'w') as f:
        f.write(BASE_CONF)
    with open('index.rst', 'w') as f:
        f.write(INDEX)

    srcdir = confdir = '.'
    outdir = './_build/html'
    doctreedir = './_build/doctrees'

    app = application.Sphinx(srcdir, confdir, outdir, doctreedir, 'html')
    app.builder.build_all()
    html_body = open(outdir + '/index.html').read()
    print(html_body)
示例#8
0
文件: builddoc.py 项目: nealmcb/pbr
    def _sphinx_run(self):
        if not self.verbose:
            status_stream = cStringIO.StringIO()
        else:
            status_stream = sys.stdout
        confoverrides = {}
        if self.project:
            confoverrides['project'] = self.project
        if self.version:
            confoverrides['version'] = self.version
        if self.release:
            confoverrides['release'] = self.release
        if self.today:
            confoverrides['today'] = self.today
        if self.sphinx_initialized:
            confoverrides['suppress_warnings'] = [
                'app.add_directive',
                'app.add_role',
                'app.add_generic_role',
                'app.add_node',
                'image.nonlocal_uri',
            ]
        app = application.Sphinx(self.source_dir,
                                 self.config_dir,
                                 self.builder_target_dir,
                                 self.doctree_dir,
                                 self.builder,
                                 confoverrides,
                                 status_stream,
                                 freshenv=self.fresh_env,
                                 warningiserror=self.warning_is_error)
        self.sphinx_initialized = True

        try:
            app.build(force_all=self.all_files)
        except Exception as err:
            from docutils import utils
            if isinstance(err, utils.SystemMessage):
                sys.stder.write('reST markup error:\n')
                sys.stderr.write(err.args[0].encode('ascii',
                                                    'backslashreplace'))
                sys.stderr.write('\n')
            else:
                raise

        if self.link_index:
            src = app.config.master_doc + app.builder.out_suffix
            dst = app.builder.get_outfilename('index')
            os.symlink(src, dst)
示例#9
0
        def _sphinx_run(self):
            if not self.verbose:
                status_stream = cStringIO.StringIO()
            else:
                status_stream = sys.stdout
            confoverrides = {}
            if self.version:
                confoverrides['version'] = self.version
            if self.release:
                confoverrides['release'] = self.release
            if self.today:
                confoverrides['today'] = self.today
            sphinx_config = config.Config(self.config_dir, 'conf.py', {}, [])
            sphinx_config.init_values()
            if self.builder == 'man' and len(sphinx_config.man_pages) == 0:
                return
            app = application.Sphinx(self.source_dir,
                                     self.config_dir,
                                     self.builder_target_dir,
                                     self.doctree_dir,
                                     self.builder,
                                     confoverrides,
                                     status_stream,
                                     freshenv=self.fresh_env,
                                     warningiserror=True)

            try:
                app.build(force_all=self.all_files)
            except Exception as err:
                from docutils import utils
                if isinstance(err, utils.SystemMessage):
                    sys.stder.write('reST markup error:\n')
                    sys.stderr.write(err.args[0].encode(
                        'ascii', 'backslashreplace'))
                    sys.stderr.write('\n')
                else:
                    raise

            if self.link_index:
                src = app.config.master_doc + app.builder.out_suffix
                dst = app.builder.get_outfilename('index')
                os.symlink(src, dst)
示例#10
0
def test_quickstart_and_build(tempdir):
    answers = {
        'Root path': tempdir,
        'Project name': 'Fullwidth characters: \u30c9\u30a4\u30c4',
        'Author name': 'Georg Brandl',
        'Project version': '0.1',
    }
    qs.term_input = mock_input(answers)
    d = {}
    qs.ask_user(d)
    qs.generate(d)

    app = application.Sphinx(
        tempdir,  # srcdir
        tempdir,  # confdir
        (tempdir / '_build' / 'html'),  # outdir
        (tempdir / '_build' / '.doctree'),  # doctreedir
        'html',  # buildername
        status=StringIO(),
        warning=warnfile)
    app.builder.build_all()
    warnings = warnfile.getvalue()
    assert not warnings
示例#11
0
def test(monkeypatch: MonkeyPatch, tmpdir: py.path.local, expected: str, rst_title: str, option: str):
    """Test valid and invalid values."""
    tmpdir.join("conf.py").write(BASE_CONFIG.format(py.path.local(__file__).join("..", "..")))
    tmpdir.join("conf.py").write("", mode="a")
    tmpdir.join("index.rst").write("{}.. toctree::\n    :maxdepth: 2\n.. disqus::\n{}".format(rst_title, option))
    monkeypatch.setattr(directives, "_directives", getattr(directives, "_directives").copy())
    monkeypatch.setattr(roles, "_roles", getattr(roles, "_roles").copy())

    srcdir = confdir = str(tmpdir)
    outdir = tmpdir.join("_build", "html")
    doctreedir = outdir.join("doctrees").ensure(dir=True, rec=True)
    app = application.Sphinx(srcdir, confdir, str(outdir), str(doctreedir), "html")

    if expected:
        app.builder.build_all()
        html_body = outdir.join("index.html").read()
        disqus_div = re.findall(r'(<div[^>]+ id="disqus_thread"[^>]*></div>)', html_body)[0]
        assert 'data-disqus-identifier="{}"'.format(expected) in disqus_div
        return

    with pytest.raises(DisqusError) as exc:
        app.builder.build_all()
    assert exc.value.args[0] == "No title nodes found in document, cannot derive disqus_identifier config value."