sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.58k stars 2.12k forks source link

0.16.1: pytest is failing in `tests/test_sphinx/test_sphinx_builds.py::test_gettext_html #10004

Closed kloczek closed 2 years ago

kloczek commented 2 years ago

Describe the bug

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

How to Reproduce

git clone https://github.com/executablebooks/MyST-Parser/ cd MyST-Parser python3 -sBm build -w python3 -sBm pip install -I dist/myst_parser-*-none-any.whl --root /tmp/install_root --no-deps --no-index --no-warn-script-location PYTHONPATH=/tmp/install_root/usr/lib64/python8/site-packages \ pytest -ra

Expected behavior

No response

Your project

N/A

Screenshots

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-myst-parser-0.16.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-myst-parser-0.16.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/MyST-Parser-0.16.1, configfile: tox.ini
plugins: forked-1.4.0, xdist-2.5.0, timeout-2.0.2, datadir-1.3.1, regressions-2.2.0
collected 949 items

tests/test_cli.py .                                                                                                                                                  [  0%]
tests/test_docutils.py ........                                                                                                                                      [  0%]
tests/test_commonmark/test_commonmark.py .............s...................................................s.s....................................................... [ 13%]
.................................................................................................................................................................... [ 31%]
.................................................................................................................................................................... [ 48%]
.................................................................................................................................................................... [ 65%]
..................................                                                                                                                                   [ 69%]
tests/test_html/test_html_to_nodes.py .................                                                                                                              [ 71%]
tests/test_html/test_parse_html.py .....................                                                                                                             [ 73%]
tests/test_renderers/test_error_reporting.py .............                                                                                                           [ 74%]
tests/test_renderers/test_fixtures.py ......................................................................................s........................s...........s.s [ 87%]
.............................ss..............................s.................                                                                                      [ 96%]
tests/test_renderers/test_include_directive.py ........                                                                                                              [ 97%]
tests/test_renderers/test_myst_refs.py .........                                                                                                                     [ 98%]
tests/test_renderers/test_parse_directives.py ...                                                                                                                    [ 98%]
tests/test_sphinx/test_sphinx_builds.py ...........F...                                                                                                              [100%]

================================================================================= FAILURES =================================================================================
____________________________________________________________________________ test_gettext_html _____________________________________________________________________________

app = <SphinxTestApp buildername='html'>, status = <_io.StringIO object at 0x7ff5978fa1f0>, warning = <_io.StringIO object at 0x7ff5978fa280>
get_sphinx_app_doctree = <function get_sphinx_app_doctree.<locals>.read at 0x7ff597955790>
get_sphinx_app_output = <function get_sphinx_app_output.<locals>.read at 0x7ff597955940>, remove_sphinx_builds = None

    @pytest.mark.sphinx(
        buildername="html",
        srcdir=os.path.join(SOURCE_DIR, "gettext"),
        freshenv=True,
        confoverrides={"language": "fr", "gettext_compact": False, "locale_dirs": ["."]},
    )
    def test_gettext_html(
        app,
        status,
        warning,
        get_sphinx_app_doctree,
        get_sphinx_app_output,
        remove_sphinx_builds,
    ):
        """Test gettext message extraction."""
        app.build()
        assert "build succeeded" in status.getvalue()  # Build succeeded
        warnings = warning.getvalue().strip()
        assert warnings == ""

        try:
            get_sphinx_app_doctree(
                app,
                docname="index",
                regress=True,
                regress_ext=f".sphinx{sphinx.version_info[0]}.xml",
            )
        finally:
            get_sphinx_app_doctree(
                app,
                docname="index",
                resolve=True,
                regress=True,
                regress_ext=f".sphinx{sphinx.version_info[0]}.xml",
            )
>       get_sphinx_app_output(
            app,
            filename="index.html",
            regress_html=True,
            regress_ext=f".sphinx{sphinx.version_info[0]}.html",
        )

tests/test_sphinx/test_sphinx_builds.py:453:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

app = <SphinxTestApp buildername='html'>, buildername = 'html', filename = 'index.html', encoding = 'utf-8', extract_body = False, remove_scripts = False
regress_html = True, regress_ext = '.sphinx4.html', replace = None

    def read(
        app,
        buildername="html",
        filename="index.html",
        encoding="utf-8",
        extract_body=False,
        remove_scripts=False,
        regress_html=False,
        regress_ext=".html",
        replace=None,
    ):

        outpath = path(os.path.join(str(app.srcdir), "_build", buildername, filename))
        if not outpath.exists():
            raise IOError("no output file exists: {}".format(outpath))

        try:
            # introduced in sphinx 3.0
            content = outpath.read_text(encoding=encoding)
        except AttributeError:
            content = outpath.text(encoding=encoding)

        if regress_html:
            # only regress the inner body, since other sections are non-deterministic
            soup = BeautifulSoup(content, "html.parser")
            doc_div = soup.findAll("div", {"class": "documentwrapper"})[0]
            text = doc_div.prettify()
            for find, rep in (replace or {}).items():
                text = text.replace(find, rep)
>           file_regression.check(text, extension=regress_ext, encoding="utf8")
E           AssertionError: FILES DIFFER:
E           /tmp/pytest-of-tkloczko/pytest-94/test_gettext_html0/test_sphinx_builds/test_gettext_html.sphinx4.html
E           /tmp/pytest-of-tkloczko/pytest-94/test_gettext_html0/test_sphinx_builds/test_gettext_html.sphinx4.obtained.sphinx4.html
E           HTML DIFF: /tmp/pytest-of-tkloczko/pytest-94/test_gettext_html0/test_sphinx_builds/test_gettext_html.sphinx4.obtained.sphinx4.diff.html
E           ---
E           +++
E           @@ -7,7 +7,7 @@
E                 <strong>
E                  gras
E                 </strong>
E           -     <a class="headerlink" href="#bold-text-1" title="Lien permanent vers ce titre">
E           +     <a class="headerlink" href="#bold-text-1" title="Permalink to this headline">
E                  ¶
E                 </a>
E                </h1>

tests/test_sphinx/conftest.py:89: AssertionError
------------------------------------------------------------------------- Captured stdout teardown -------------------------------------------------------------------------
# testroot: root
# builder: html
# srcdir: /home/tkloczko/rpmbuild/BUILD/MyST-Parser-0.16.1/tests/test_sphinx/sourcedirs/gettext
# outdir: /home/tkloczko/rpmbuild/BUILD/MyST-Parser-0.16.1/tests/test_sphinx/sourcedirs/gettext/_build/html
# status:
Running Sphinx v4.3.2
loading translations [fr]... not available for built-in messages
myst v0.16.1: MdParserConfig(renderer='sphinx', commonmark_only=False, enable_extensions=['deflist'], linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area', disable_syntax=[], url_schemes=['http', 'https', 'mailto', 'ftp'], heading_anchors=None, heading_slug_func=None, html_meta=[], footnote_transition=True, substitutions=[], sub_delimiters=['{', '}'], words_per_minute=200)
building [mo]: targets for 1 po files that are out of date
writing output... [100%] fr/LC_MESSAGES/index.mo
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex done
writing additional pages... search done
copying images... [100%] fun-fish.png
copying static files... done
copying extra files... done
dumping search index in French (code: fr)... done
dumping object inventory... done
build succeeded.

The HTML pages are in tests/test_sphinx/sourcedirs/gettext/_build/html.

# warning:

========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/test_commonmark/test_commonmark.py:21: Expects '+++' to be unconverted (not block break).
SKIPPED [2] tests/test_commonmark/test_commonmark.py:26: Thematic breaks on the first line conflict with front matter syntax
SKIPPED [1] tests/test_renderers/test_fixtures.py:90: SKIP: MockingError: MockState has not yet implemented attribute 'nest_line_block_lines'
SKIPPED [2] tests/test_renderers/test_fixtures.py:110: SKIP: Tested in sphinx builds
SKIPPED [1] tests/test_renderers/test_fixtures.py:110: SKIP: MockingError: MockState has not yet implemented attribute 'nested_list_parse'
SKIPPED [1] tests/test_renderers/test_fixtures.py:134: SKIP cpp:expr (`sphinx.domains.cpp.CPPExprRole`):
SKIPPED [1] tests/test_renderers/test_fixtures.py:134: SKIP cpp:texpr (`sphinx.domains.cpp.CPPExprRole`):
SKIPPED [1] tests/test_renderers/test_fixtures.py:134: SKIP: Non-deterministic output
FAILED tests/test_sphinx/test_sphinx_builds.py::test_gettext_html - AssertionError: FILES DIFFER:
================================================================ 1 failed, 938 passed, 10 skipped in 12.95s ================================================================

OS

Linux/x86_64

Python version

3.8.12

Sphinx version

4.3.2

Sphinx extensions

N/A

Extra tools

N/A

Additional context

No response

tk0miya commented 2 years ago

I'm not good at the test of MyST-Parser, but it seems you'd run testings under fr locale. How about running this under LC_LANG=C?

Running Sphinx v4.3.2 loading translations [fr]... not available for built-in messages

BTW, why did you post this to our project? This is Sphinx, not MyST-Parser project. We can't support you at all.

kloczek commented 2 years ago

I'm not good at the test of MyST-Parser, but it seems you'd run testings under fr locale. How about running this under LC_LANG=C?

Quoted output is from packaging rpm packaging process. rpm always uses "C" as default locale settings in build env (it forces that in generated and executed shell scripts). In other words what you see here is in env with "C" locale settings.

tk0miya commented 2 years ago

Ah, sorry. I found the testcase is configured as language: fr. So It's expected behavior.

    @pytest.mark.sphinx(
        buildername="html",
        srcdir=os.path.join(SOURCE_DIR, "gettext"),
        freshenv=True,
        confoverrides={"language": "fr", "gettext_compact": False, "locale_dirs": ["."]},
    )

Sorry, I don't know what happened. Please ask to the MyST-Parser team.

chrisjsewell commented 2 years ago

Basically, in the test,

# **bold** text 1

should be converted to:

    <h1>
     texte 1 en
     <strong>
      gras
     </strong>
     <a class="headerlink" href="#bold-text-1" title="Lien permanent vers ce titre">
      ¶
     </a>
    </h1>

but for @kloczek, with he's test setup, he gets:

    <h1>
     texte 1 en
     <strong>
      gras
     </strong>
     <a class="headerlink" href="#bold-text-1" title="Permalink to this headline">
      ¶
     </a>
    </h1>

I don't reproduce this issue though; either locally or on Github actions. So I would suggest is an issue with @kloczek testing setup

kloczek commented 2 years ago

Hmm .. so why in my case is produced English text? What could be possible cause?🤔

chrisjsewell commented 2 years ago

No idea myself, @jpmckinney maybe able to comment (who implemented these translation tests)

jpmckinney commented 2 years ago

@chrisjsewell If you're saying you can't reproduce the error, then I will not attempt to guess why the irreproducible error occurs :)

kloczek commented 2 years ago

Looks like 0.17.1 fixes that issue

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-myst-parser-0.17.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-myst-parser-0.17.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/MyST-Parser-0.17.1, configfile: tox.ini
plugins: datadir-1.3.1, regressions-2.3.1, pytest_param_files-0.3.4
collected 1005 items

tests/test_cli.py .                                                                                                                                                  [  0%]
tests/test_docutils.py .........                                                                                                                                     [  0%]
tests/test_commonmark/test_commonmark.py .............s...................................................s.s....................................................... [ 13%]
.................................................................................................................................................................... [ 29%]
.................................................................................................................................................................... [ 45%]
.................................................................................................................................................................... [ 62%]
..................................                                                                                                                                   [ 65%]
tests/test_html/test_html_to_nodes.py .................                                                                                                              [ 67%]
tests/test_html/test_parse_html.py .....................                                                                                                             [ 69%]
tests/test_renderers/test_error_reporting.py ...............                                                                                                         [ 70%]
tests/test_renderers/test_fixtures_docutils.py ...............................................................s..........................                            [ 79%]
tests/test_renderers/test_fixtures_sphinx.py ..............................................................s...........s.s.............................ss........... [ 91%]
...................s.......................                                                                                                                          [ 95%]
tests/test_renderers/test_include_directive.py ........                                                                                                              [ 96%]
tests/test_renderers/test_myst_config.py .....                                                                                                                       [ 97%]
tests/test_renderers/test_myst_refs.py .........                                                                                                                     [ 98%]
tests/test_renderers/test_parse_directives.py ....                                                                                                                   [ 98%]
tests/test_sphinx/test_sphinx_builds.py ...............                                                                                                              [100%]

========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/test_commonmark/test_commonmark.py:21: Expects '+++' to be unconverted (not block break).
SKIPPED [2] tests/test_commonmark/test_commonmark.py:26: Thematic breaks on the first line conflict with front matter syntax
SKIPPED [1] tests/test_renderers/test_fixtures_docutils.py:44: (`docutils.parsers.rst.directives.body.LineBlock`) SKIP: MockingError: MockState has not yet implemented attribute 'nest_line_block_lines'
SKIPPED [2] tests/test_renderers/test_fixtures_sphinx.py:46: SKIP: Tested in sphinx builds
SKIPPED [1] tests/test_renderers/test_fixtures_sphinx.py:46: SKIP: MockingError: MockState has not yet implemented attribute 'nested_list_parse'
SKIPPED [1] tests/test_renderers/test_fixtures_sphinx.py:63: SKIP cpp:expr (`sphinx.domains.cpp.CPPExprRole`):
SKIPPED [1] tests/test_renderers/test_fixtures_sphinx.py:63: SKIP cpp:texpr (`sphinx.domains.cpp.CPPExprRole`):
SKIPPED [1] tests/test_renderers/test_fixtures_sphinx.py:63: SKIP: Non-deterministic output
===================================================================== 995 passed, 10 skipped in 9.14s ======================================================================

Closing.