Example #1
0
def create_site(toc_file, path, extension, overwrite):
    """Create a site directory from a ToC file."""
    create_site_from_toc(
        toc_file, root_path=path, default_ext="." + extension, overwrite=overwrite
    )
    # TODO option to add basic conf.py?
    click.secho("SUCCESS!", fg="green")
def test_absolute_path(tmp_path: Path, sphinx_build_factory):
    """Test if `external_toc_path` is supplied as an absolute path."""
    src_dir = tmp_path / "srcdir"
    # write document files
    toc_path = Path(__file__).parent.joinpath("_toc_files", "basic.yml")
    create_site_from_toc(toc_path, root_path=src_dir, toc_name=None)
    # write conf.py
    content = f"""
extensions = ["sphinx_external_toc"]
external_toc_path = {Path(os.path.abspath(toc_path)).as_posix()!r}

"""
    src_dir.joinpath("conf.py").write_text(content, encoding="utf8")
    # run sphinx
    builder = sphinx_build_factory(src_dir)
    builder.build()
def test_warning(path: Path, tmp_path: Path, sphinx_build_factory):
    src_dir = tmp_path / "srcdir"
    # write document files
    sitemap = create_site_from_toc(path, root_path=src_dir)
    # write conf.py
    src_dir.joinpath("conf.py").write_text(CONF_CONTENT, encoding="utf8")
    # run sphinx
    builder = sphinx_build_factory(src_dir)
    builder.build(assert_pass=False)
    assert sitemap.meta["expected_warning"] in builder.warnings
def test_success(path: Path, tmp_path: Path, sphinx_build_factory,
                 file_regression):
    """Test successful builds."""
    src_dir = tmp_path / "srcdir"
    # write document files
    site_map = create_site_from_toc(path, root_path=src_dir)
    # write conf.py
    src_dir.joinpath("conf.py").write_text(
        CONF_CONTENT + ("external_toc_exclude_missing = True" if
                        site_map.meta.get("exclude_missing") is True else ""),
        encoding="utf8",
    )
    # run sphinx
    builder = sphinx_build_factory(src_dir)
    builder.build()
    # optionally check the doctree of a file
    if "regress" in site_map.meta:
        doctree = builder.app.env.get_doctree(site_map.meta["regress"])
        doctree["source"] = site_map.meta["regress"]
        file_regression.check(doctree.pformat(),
                              extension=".xml",
                              encoding="utf8")
Example #5
0
def test_file_to_sitemap(path: Path, tmp_path: Path, data_regression):
    create_site_from_toc(path, root_path=tmp_path)
    file_list = [p.relative_to(tmp_path).as_posix() for p in tmp_path.glob("**/*")]
    data_regression.check(sorted(file_list))