From 978ef078f259b214cf86e6ebe9799174131229ea Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 28 Dec 2021 14:53:28 +0100 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=A7=AA=20TESTS:=20Add=20more=20tests?= =?UTF-8?q?=20for=20myst-docutils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1bdb9cf7..1aaa10e6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -83,7 +83,7 @@ jobs: run: | python -m pip install --upgrade pip pip install . - pip install docutils==${{ matrix.docutils-version }} + pip install pytest>=6,<7 docutils==${{ matrix.docutils-version }} - name: ensure sphinx is not installed run: | python -c "\ @@ -93,6 +93,8 @@ jobs: pass else: raise AssertionError()" + - name: Run pytest for docutils-only tests + run: pytest tests/test_docutils.py - name: Run docutils CLI run: echo "test" | myst-docutils-html From 866cef12d92744cccda2266d21e3945420f12de1 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 28 Dec 2021 15:14:36 +0100 Subject: [PATCH 2/8] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1aaa10e6..f38ca9d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -83,7 +83,7 @@ jobs: run: | python -m pip install --upgrade pip pip install . - pip install pytest>=6,<7 docutils==${{ matrix.docutils-version }} + pip install pytest~=6.2 docutils==${{ matrix.docutils-version }} - name: ensure sphinx is not installed run: | python -c "\ From 3874d412a253278ad176b596dae1fff70565f152 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 28 Dec 2021 15:21:34 +0100 Subject: [PATCH 3/8] Update conftest.py --- tests/conftest.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 970578a0..52c3382b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,7 @@ -pytest_plugins = "sphinx.testing.fixtures" +try: + import sphinx # noqa: F401 +except ImportError: + pass +else: + # only use when Sphinx is installed, to allow testing myst-docutils + pytest_plugins = "sphinx.testing.fixtures" From 394e0132efeb4e53ccb52c32c544e9d99fccb050 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 28 Dec 2021 15:31:12 +0100 Subject: [PATCH 4/8] add fix --- myst_parser/docutils_renderer.py | 5 +++-- tests/conftest.py | 1 + tests/test_renderers/fixtures/syntax_elements.md | 15 ++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/myst_parser/docutils_renderer.py b/myst_parser/docutils_renderer.py index ae77d4d9..5ff73d1c 100644 --- a/myst_parser/docutils_renderer.py +++ b/myst_parser/docutils_renderer.py @@ -741,9 +741,10 @@ def dict_to_fm_field_list( value = str(value) if key in bibliofields: para_nodes, _ = state.inline_text(value, line) - body_children = [nodes.paragraph("", "", *para_nodes)] else: - body_children = [nodes.Text(value, value)] + para_nodes = [nodes.Text(value, value)] + + body_children = [nodes.paragraph("", "", *para_nodes)] field_node = nodes.field() field_node.source = value diff --git a/tests/conftest.py b/tests/conftest.py index 52c3382b..11b20c47 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,4 @@ +"""Top-level configuration for pytest.""" try: import sphinx # noqa: F401 except ImportError: diff --git a/tests/test_renderers/fixtures/syntax_elements.md b/tests/test_renderers/fixtures/syntax_elements.md index 4e0ebf9d..a20a7f5a 100644 --- a/tests/test_renderers/fixtures/syntax_elements.md +++ b/tests/test_renderers/fixtures/syntax_elements.md @@ -631,17 +631,20 @@ c: a - 1 + + 1 b - foo + + foo c - {"d": 2} + + {"d": 2} . -------------------------- @@ -758,7 +761,8 @@ other: Something else other - Something else + + Something else . -------------------------- @@ -859,7 +863,8 @@ a = 1 a - 1 + + 1
From d4aedea5010dfb6af84e7055ec726b45f27c3345 Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Tue, 28 Dec 2021 20:03:48 +0100 Subject: [PATCH 5/8] Split docutils/sphinx fixture testing --- .../test_renderers/test_fixtures_docutils.py | 56 +++++++++++++++++++ ...st_fixtures.py => test_fixtures_sphinx.py} | 39 ++----------- 2 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 tests/test_renderers/test_fixtures_docutils.py rename tests/test_renderers/{test_fixtures.py => test_fixtures_sphinx.py} (84%) diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py new file mode 100644 index 00000000..542346b9 --- /dev/null +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -0,0 +1,56 @@ +"""Test fixture files, using the ``DocutilsRenderer``. + +Note, the output AST is before any transforms are applied. +""" +from pathlib import Path + +import pytest +from markdown_it.utils import read_fixture_file + +from myst_parser.docutils_renderer import DocutilsRenderer, make_document +from myst_parser.main import MdParserConfig, create_md_parser + +FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") + + +@pytest.mark.parametrize( + "line,title,input,expected", + read_fixture_file(FIXTURE_PATH.joinpath("docutil_roles.md")), + ids=[ + f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "docutil_roles.md") + ], +) +def test_docutils_roles(line, title, input, expected): + parser = create_md_parser(MdParserConfig(), DocutilsRenderer) + parser.options["document"] = document = make_document() + parser.render(input) + try: + assert "\n".join( + [ll.rstrip() for ll in document.pformat().splitlines()] + ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) + except AssertionError: + print(document.pformat()) + raise + + +@pytest.mark.parametrize( + "line,title,input,expected", + read_fixture_file(FIXTURE_PATH.joinpath("docutil_directives.md")), + ids=[ + f"{i[0]}-{i[1]}" + for i in read_fixture_file(FIXTURE_PATH / "docutil_directives.md") + ], +) +def test_docutils_directives(line, title, input, expected): + if title.startswith("SKIP"): # line-block directive not yet supported + pytest.skip(title) + parser = create_md_parser(MdParserConfig(), DocutilsRenderer) + parser.options["document"] = document = make_document() + parser.render(input) + try: + assert "\n".join( + [ll.rstrip() for ll in document.pformat().splitlines()] + ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) + except AssertionError: + print(document.pformat()) + raise diff --git a/tests/test_renderers/test_fixtures.py b/tests/test_renderers/test_fixtures_sphinx.py similarity index 84% rename from tests/test_renderers/test_fixtures.py rename to tests/test_renderers/test_fixtures_sphinx.py index 7771a552..c14d0b85 100644 --- a/tests/test_renderers/test_fixtures.py +++ b/tests/test_renderers/test_fixtures_sphinx.py @@ -1,3 +1,7 @@ +"""Test fixture files, using the ``SphinxRenderer``. + +Note, the output AST is before any transforms are applied. +""" import re from pathlib import Path @@ -60,41 +64,6 @@ def test_directive_options(line, title, input, expected): ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("docutil_roles.md")), - ids=[ - f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "docutil_roles.md") - ], -) -def test_docutils_roles(line, title, input, expected): - document = to_docutils(input) - print(document.pformat()) - assert "\n".join( - [ll.rstrip() for ll in document.pformat().splitlines()] - ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) - - -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("docutil_directives.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "docutil_directives.md") - ], -) -def test_docutils_directives(line, title, input, expected): - # TODO fix skipped directives - # TODO test domain directives - if title.startswith("SKIP"): - pytest.skip(title) - document = to_docutils(input) - print(document.pformat()) - assert "\n".join( - [ll.rstrip() for ll in document.pformat().splitlines()] - ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) - - @pytest.mark.parametrize( "line,title,input,expected", read_fixture_file(FIXTURE_PATH.joinpath("sphinx_directives.md")), From 5f750cb16c6a8c68338fbd8ad9de6bbe663835a8 Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Tue, 28 Dec 2021 20:05:40 +0100 Subject: [PATCH 6/8] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f38ca9d8..089f8bb8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -94,7 +94,7 @@ jobs: else: raise AssertionError()" - name: Run pytest for docutils-only tests - run: pytest tests/test_docutils.py + run: pytest tests/test_docutils.py tests/test_renderers/test_fixtures_docutils.py - name: Run docutils CLI run: echo "test" | myst-docutils-html From 50a04f52ecea06e9de94ce7017e7d8b213cffdad Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Tue, 28 Dec 2021 20:17:25 +0100 Subject: [PATCH 7/8] Update test_fixtures_docutils.py --- tests/test_renderers/test_fixtures_docutils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py index 542346b9..3bfaf085 100644 --- a/tests/test_renderers/test_fixtures_docutils.py +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -21,6 +21,7 @@ ], ) def test_docutils_roles(line, title, input, expected): + """Test output of docutils roles.""" parser = create_md_parser(MdParserConfig(), DocutilsRenderer) parser.options["document"] = document = make_document() parser.render(input) @@ -42,6 +43,7 @@ def test_docutils_roles(line, title, input, expected): ], ) def test_docutils_directives(line, title, input, expected): + """Test output of docutils directives.""" if title.startswith("SKIP"): # line-block directive not yet supported pytest.skip(title) parser = create_md_parser(MdParserConfig(), DocutilsRenderer) From 56214b0c7a4d39c87593e3ec4661056b1b00da09 Mon Sep 17 00:00:00 2001 From: Chris Sewell <chrisj_sewell@hotmail.com> Date: Tue, 28 Dec 2021 20:25:49 +0100 Subject: [PATCH 8/8] Update docutils_renderer.py --- myst_parser/docutils_renderer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/myst_parser/docutils_renderer.py b/myst_parser/docutils_renderer.py index 5ff73d1c..33d1b97f 100644 --- a/myst_parser/docutils_renderer.py +++ b/myst_parser/docutils_renderer.py @@ -730,6 +730,7 @@ def dict_to_fm_field_list( """ field_list = nodes.field_list() + field_list.source, field_list.line = self.document["source"], line bibliofields = get_language(language_code).bibliographic_fields state_machine = MockStateMachine(self, line) @@ -745,6 +746,8 @@ def dict_to_fm_field_list( para_nodes = [nodes.Text(value, value)] body_children = [nodes.paragraph("", "", *para_nodes)] + body_children[0].source = self.document["source"] + body_children[0].line = 0 field_node = nodes.field() field_node.source = value