跳转到主要内容

用于测试 Sphinx 扩展的实用工具

项目描述

快速入门

如果您有一个包含 Sphinx 项目的目录,可以使用类似的方法来测试它是否构建

class TestMyProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'

    def test_basic_build(self):
        # Get doctree for page "a_page.rst"
        doctree = self.get_doctree('a_page')
        # Assert stuff about doctree version of page
        html = self.get_built_file('a_page.html')
        # Assert stuff about html version of page

您可以通过使用 rst_sources 字典来尝试添加其他页面内容

class TestChangedProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'
    rst_sources = {'a_page': """Replacement text for page""",
                   'b_page': """An entirely new page"""}

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

使用 conf_source 属性设置 conf.py 文件的文本

class TestConfeddProject(SourcesBuilder):

    page_source_template = 'path/to/sphinx_dir'
    rst_sources = {'a_page': """Replacement text for page""",
                   'b_page': """An entirely new page"""}
    conf_source = """ # This overwrites existing conf.py """

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

您不需要设置 page_source_template;如果不设置,您将从一个新的项目开始,其中只有您在 rst_sources 中指定的页面。

class TestFreshProject(SourcesBuilder):

    rst_sources = {'a_page': """A new page""",
                   'b_page': """Another new page"""}
    conf_source = """ # Stuff for the conf.py file """

    def test_basic_build(self):
        a_doctree = self.get_doctree('a_page')
        b_doctree = self.get_doctree('b_page')
        # Your tests for the new page content here

有关使用 Sphinxtesters 测试 Sphinx 项目构建的示例,请参阅测试。

安装

pip install sphinxtesters

代码

查看 https://github.com/matthew-brett/sphinxtesters

在源分发中发布于 BSD 双条款许可证 - 请参阅 LICENSE 文件。

travis-ci 慷慨地在 Python 2.7 和 3.3 到 3.6 版本下自动测试代码。

最新发布版本可在 https://pypi.python.org/pypi/sphinxtesters 找到。

测试

  • 安装 sphinxtesters

  • 安装 pytest 测试框架

    pip install pytest
  • 使用以下命令运行测试

    pytest sphinxtesters

支持

请在 sphinxtesters 问题跟踪器 上提出问题。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

sphinxtesters-0.2.3.tar.gz (29.2 kB 查看哈希值)

上传时间

支持