コード例 #1
0
ファイル: test_intl.py プロジェクト: Brishen/sphinx
def setup_intl(app_params):
    srcdir = path(app_params.kwargs['srcdir'])
    for dirpath, dirs, files in os.walk(srcdir):
        dirpath = path(dirpath)
        for f in [f for f in files if f.endswith('.po')]:
            po = dirpath / f
            mo = srcdir / 'xx' / 'LC_MESSAGES' / (
                os.path.relpath(po[:-3], srcdir) + '.mo')
            if not mo.parent.exists():
                mo.parent.makedirs()

            if not mo.exists() or mo.stat().st_mtime < po.stat().st_mtime:
                # compile .mo file only if needed
                write_mo(mo, read_po(po))
コード例 #2
0
    def builder(srcdir):
        """
        :param str srcdir: app.srcdir
        """
        srcdir = path(srcdir)
        for dirpath, dirs, files in os.walk(srcdir):
            dirpath = path(dirpath)
            for f in [f for f in files if f.endswith('.po')]:
                po = dirpath / f
                mo = srcdir / 'xx' / 'LC_MESSAGES' / (
                    os.path.relpath(po[:-3], srcdir) + '.mo')
                if not mo.parent.exists():
                    mo.parent.makedirs()

                write_mo(mo, read_po(po))
コード例 #3
0
ファイル: test_intl.py プロジェクト: sam-m888/sphinx
    def builder(srcdir):
        """
        :param str srcdir: app.srcdir
        """
        srcdir = path(srcdir)
        for dirpath, dirs, files in os.walk(srcdir):
            dirpath = path(dirpath)
            for f in [f for f in files if f.endswith('.po')]:
                po = dirpath / f
                mo = srcdir / 'xx' / 'LC_MESSAGES' / (
                    os.path.relpath(po[:-3], srcdir) + '.mo')
                if not mo.parent.exists():
                    mo.parent.makedirs()

                write_mo(mo, read_po(po))
コード例 #4
0
    def doctree(
        source,
        config=None,
        return_all=False,
        entrypoint="jupyter_sphinx",
        buildername='html'
    ):
        src_dir = Path(tempfile.mkdtemp())
        source_trees.append(src_dir)

        conf_contents = "extensions = ['%s']" % entrypoint
        if config is not None:
            conf_contents += "\n" + config
        (src_dir / "conf.py").write_text(conf_contents, encoding = "utf8")
        (src_dir / "index.rst").write_text(source, encoding = "utf8")
        
        warnings = StringIO()
        app = SphinxTestApp(
            srcdir=path(src_dir.as_posix()),
            status=StringIO(),
            warning=warnings,
            buildername=buildername
        )
        apps.append(app)
        app.build()

        doctree = app.env.get_and_resolve_doctree("index", app.builder)
        if return_all:
            return doctree, app, warnings.getvalue()
        else:
            return doctree
コード例 #5
0
    def doctree(source,
                config=None,
                return_warnings=False,
                entrypoint="jupyter_sphinx"):
        src_dir = tempfile.mkdtemp()
        source_trees.append(src_dir)
        with open(os.path.join(src_dir, "conf.py"), "w") as f:
            f.write("extensions = ['%s']" % entrypoint)
            if config is not None:
                f.write("\n" + config)
        with open(os.path.join(src_dir, "contents.rst"), "w") as f:
            f.write(source)
        warnings = StringIO()
        app = SphinxTestApp(srcdir=path(src_dir),
                            status=StringIO(),
                            warning=warnings)
        apps.append(app)
        app.build()

        doctree = app.env.get_doctree("contents")

        if return_warnings:
            return doctree, warnings.getvalue()
        else:
            return doctree
コード例 #6
0
def sphinx_test_tempdir(tmpdir_factory: Any) -> "util.path":
    """
    temporary directory that wrapped with `path` class.
    """
    tmpdir = os.environ.get('SPHINX_TEST_TEMPDIR')  # RemovedInSphinx40Warning
    if tmpdir is None:
        tmpdir = tmpdir_factory.getbasetemp()

    return util.path(tmpdir).abspath()
コード例 #7
0
 def doctree(source):
     src_dir = tempfile.mkdtemp()
     source_trees.append(src_dir)
     with open(os.path.join(src_dir, 'conf.py'), 'w') as f:
         f.write("extensions = ['jupyter_sphinx.execute']")
     with open(os.path.join(src_dir, 'index.rst'), 'w') as f:
         f.write(source)
     app = SphinxTestApp(srcdir=path(src_dir),
                         status=StringIO(),
                         warning=StringIO())
     apps.append(app)
     app.build()
     return app.env.get_doctree('index')
コード例 #8
0
def test_second_update():
    # delete, add and "edit" (change saved mtime) some files and update again
    env.all_docs['contents'] = 0
    root = path(app.srcdir)
    # important: using "autodoc" because it is the last one to be included in
    # the contents.txt toctree; otherwise section numbers would shift
    (root / 'autodoc.txt').unlink()
    (root / 'new.txt').write_text('New file\n========\n')
    updated = env.update(app.config, app.srcdir, app.doctreedir)
    # "includes" and "images" are in there because they contain references
    # to nonexisting downloadable or image files, which are given another
    # chance to exist
    assert set(updated) == set(['contents', 'new', 'includes', 'images'])
    assert 'autodoc' not in env.all_docs
    assert 'autodoc' not in env.found_docs
コード例 #9
0
ファイル: test_environment.py プロジェクト: LFYG/sphinx
def test_second_update():
    # delete, add and "edit" (change saved mtime) some files and update again
    env.all_docs['contents'] = 0
    root = path(app.srcdir)
    # important: using "autodoc" because it is the last one to be included in
    # the contents.txt toctree; otherwise section numbers would shift
    (root / 'autodoc.txt').unlink()
    (root / 'new.txt').write_text('New file\n========\n')
    updated = env.update(app.config, app.srcdir, app.doctreedir)
    # "includes" and "images" are in there because they contain references
    # to nonexisting downloadable or image files, which are given another
    # chance to exist
    assert set(updated) == set(['contents', 'new', 'includes', 'images'])
    assert 'autodoc' not in env.all_docs
    assert 'autodoc' not in env.found_docs
コード例 #10
0
    def doctree(source, config=None, return_warnings=False):
        src_dir = tempfile.mkdtemp()
        source_trees.append(src_dir)
        with open(os.path.join(src_dir, 'conf.py'), 'w') as f:
            f.write("extensions = ['jupyter_sphinx.execute']")
            if config is not None:
                f.write('\n' + config)
        with open(os.path.join(src_dir, 'contents.rst'), 'w') as f:
            f.write(source)
        warnings = StringIO()
        app = SphinxTestApp(srcdir=path(src_dir), status=StringIO(),
                            warning=warnings)
        apps.append(app)
        app.build()

        doctree = app.env.get_doctree("contents")

        if return_warnings:
            return doctree, warnings.getvalue()
        else:
            return doctree
コード例 #11
0
def rootdir():
    """rootdir is a sphinx fixture that allows for specifying where our "document root" is when running marked tests"""
    return util.path(__file__).parent.parent.abspath()
コード例 #12
0
ファイル: fixtures.py プロジェクト: RanaRostampour/mysite
def tempdir(tmpdir: str) -> "util.path":
    """
    temporary directory that wrapped with `path` class.
    this fixture is for compat with old test implementation.
    """
    return util.path(tmpdir)
コード例 #13
0
ファイル: fixtures.py プロジェクト: RanaRostampour/mysite
def sphinx_test_tempdir(tmpdir_factory: Any) -> "util.path":
    """
    temporary directory that wrapped with `path` class.
    """
    tmpdir = tmpdir_factory.getbasetemp()
    return util.path(tmpdir).abspath()
コード例 #14
0
def tempdir(tmpdir: str) -> "util.path":
    """
    Temporary directory wrapped with `path` class.
    This fixture is for back-compatibility with old test implementation.
    """
    return util.path(tmpdir)