diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0dd67f00..7cd01786 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,7 +84,7 @@ jobs: run: | python -m pip install --upgrade pip pip install . - pip install pytest~=6.2 docutils==${{ matrix.docutils-version }} + pip install pytest~=6.2 pytest-param-files~=0.2.2 docutils==${{ matrix.docutils-version }} - name: ensure sphinx is not installed run: | python -c "\ diff --git a/setup.cfg b/setup.cfg index a17d78df..e48e4080 100644 --- a/setup.cfg +++ b/setup.cfg @@ -79,6 +79,7 @@ testing = pytest>=6,<7 pytest-cov pytest-regressions + pytest-param-files~=0.2.2 [flake8] max-line-length = 100 diff --git a/tests/test_renderers/fixtures/docutil_directives.md b/tests/test_renderers/fixtures/docutil_directives.md index 33e3f012..e15bf2e0 100644 --- a/tests/test_renderers/fixtures/docutil_directives.md +++ b/tests/test_renderers/fixtures/docutil_directives.md @@ -1,5 +1,5 @@ -------------------------------- -attention (`docutils.parsers.rst.directives.admonitions.Attention`): +[attention] (`docutils.parsers.rst.directives.admonitions.Attention`): . ```{attention} @@ -13,7 +13,7 @@ a . -------------------------------- -caution (`docutils.parsers.rst.directives.admonitions.Caution`): +[caution] (`docutils.parsers.rst.directives.admonitions.Caution`): . ```{caution} @@ -27,7 +27,7 @@ a . -------------------------------- -danger (`docutils.parsers.rst.directives.admonitions.Danger`): +[danger] (`docutils.parsers.rst.directives.admonitions.Danger`): . ```{danger} @@ -41,7 +41,7 @@ a . -------------------------------- -error (`docutils.parsers.rst.directives.admonitions.Error`): +[error] (`docutils.parsers.rst.directives.admonitions.Error`): . ```{error} @@ -55,7 +55,7 @@ a . -------------------------------- -important (`docutils.parsers.rst.directives.admonitions.Important`): +[important] (`docutils.parsers.rst.directives.admonitions.Important`): . ```{important} @@ -69,7 +69,7 @@ a . -------------------------------- -note (`docutils.parsers.rst.directives.admonitions.Note`): +[note] (`docutils.parsers.rst.directives.admonitions.Note`): . ```{note} @@ -83,7 +83,7 @@ a . -------------------------------- -tip (`docutils.parsers.rst.directives.admonitions.Tip`): +[tip] (`docutils.parsers.rst.directives.admonitions.Tip`): . ```{tip} @@ -97,7 +97,7 @@ a . -------------------------------- -hint (`docutils.parsers.rst.directives.admonitions.Hint`): +[hint] (`docutils.parsers.rst.directives.admonitions.Hint`): . ```{hint} @@ -111,7 +111,7 @@ a . -------------------------------- -warning (`docutils.parsers.rst.directives.admonitions.Warning`): +[warning] (`docutils.parsers.rst.directives.admonitions.Warning`): . ```{warning} @@ -125,7 +125,7 @@ a . -------------------------------- -admonition (`docutils.parsers.rst.directives.admonitions.Admonition`): +[admonition] (`docutils.parsers.rst.directives.admonitions.Admonition`): . ```{admonition} myclass @@ -141,7 +141,7 @@ a . -------------------------------- -sidebar (`docutils.parsers.rst.directives.body.Sidebar`): +[sidebar] (`docutils.parsers.rst.directives.body.Sidebar`): . ```{sidebar} sidebar title @@ -157,7 +157,7 @@ a . -------------------------------- -topic (`docutils.parsers.rst.directives.body.Topic`): +[topic] (`docutils.parsers.rst.directives.body.Topic`): . ```{topic} Topic Title @@ -173,8 +173,7 @@ a . -------------------------------- -line-block (`docutils.parsers.rst.directives.body.LineBlock`): -SKIP: MockingError: MockState has not yet implemented attribute 'nest_line_block_lines' +[line-block] (`docutils.parsers.rst.directives.body.LineBlock`) SKIP: MockingError: MockState has not yet implemented attribute 'nest_line_block_lines' . ```{line-block} @@ -185,7 +184,7 @@ SKIP: MockingError: MockState has not yet implemented attribute 'nest_line_block . -------------------------------- -parsed-literal (`docutils.parsers.rst.directives.body.ParsedLiteral`): +[parsed-literal] (`docutils.parsers.rst.directives.body.ParsedLiteral`): . ```{parsed-literal} @@ -198,7 +197,7 @@ a . -------------------------------- -rubric (`docutils.parsers.rst.directives.body.Rubric`): +[rubric] (`docutils.parsers.rst.directives.body.Rubric`): . ```{rubric} Rubric Title ``` @@ -209,7 +208,7 @@ rubric (`docutils.parsers.rst.directives.body.Rubric`): . -------------------------------- -epigraph (`docutils.parsers.rst.directives.body.Epigraph`): +[epigraph] (`docutils.parsers.rst.directives.body.Epigraph`): . ```{epigraph} @@ -227,7 +226,7 @@ a . -------------------------------- -highlights (`docutils.parsers.rst.directives.body.Highlights`): +[highlights] (`docutils.parsers.rst.directives.body.Highlights`): . ```{highlights} @@ -245,7 +244,7 @@ a . -------------------------------- -pull-quote (`docutils.parsers.rst.directives.body.PullQuote`): +[pull-quote] (`docutils.parsers.rst.directives.body.PullQuote`): . ```{pull-quote} @@ -263,7 +262,7 @@ a . -------------------------------- -compound (`docutils.parsers.rst.directives.body.Compound`): +[compound] (`docutils.parsers.rst.directives.body.Compound`): . ```{compound} @@ -277,7 +276,7 @@ a . -------------------------------- -container (`docutils.parsers.rst.directives.body.Container`): +[container] (`docutils.parsers.rst.directives.body.Container`): . ```{container} @@ -291,7 +290,7 @@ a . -------------------------------- -image (`docutils.parsers.rst.directives.images.Image`): +[image] (`docutils.parsers.rst.directives.images.Image`): . ```{image} path/to/image :alt: abc @@ -303,7 +302,7 @@ image (`docutils.parsers.rst.directives.images.Image`): . -------------------------------- -raw (`docutils.parsers.rst.directives.misc.Raw`): +[raw] (`docutils.parsers.rst.directives.misc.Raw`): . ```{raw} raw @@ -316,7 +315,7 @@ a . -------------------------------- -class (`docutils.parsers.rst.directives.misc.Class`): +[class] (`docutils.parsers.rst.directives.misc.Class`): . ```{class} myclass @@ -329,7 +328,7 @@ a . -------------------------------- -role (`docutils.parsers.rst.directives.misc.Role`) + raw (`docutils.parsers.rst.roles.raw_role`): +[role] (`docutils.parsers.rst.directives.misc.Role`) + raw (`docutils.parsers.rst.roles.raw_role`): . ```{role} raw-latex(raw) :format: latex @@ -344,7 +343,7 @@ role (`docutils.parsers.rst.directives.misc.Role`) + raw (`docutils.parsers.rst. . -------------------------------- -title (`docutils.parsers.rst.directives.misc.Title`): +[title] (`docutils.parsers.rst.directives.misc.Title`): . ```{title} title ``` @@ -353,7 +352,7 @@ title (`docutils.parsers.rst.directives.misc.Title`): . -------------------------------- -restructuredtext-test-directive (`docutils.parsers.rst.directives.misc.TestDirective`): +[restructuredtext-test-directive] (`docutils.parsers.rst.directives.misc.TestDirective`): . ```{restructuredtext-test-directive} ``` @@ -365,7 +364,7 @@ restructuredtext-test-directive (`docutils.parsers.rst.directives.misc.TestDirec . -------------------------------- -contents (`docutils.parsers.rst.directives.parts.Contents`): +[contents] (`docutils.parsers.rst.directives.parts.Contents`): . ```{contents} Contents ``` @@ -381,7 +380,7 @@ contents (`docutils.parsers.rst.directives.parts.Contents`): . -------------------------------- -sectnum (`docutils.parsers.rst.directives.parts.Sectnum`): +[sectnum] (`docutils.parsers.rst.directives.parts.Sectnum`): . ```{sectnum} ``` @@ -394,7 +393,7 @@ sectnum (`docutils.parsers.rst.directives.parts.Sectnum`): . -------------------------------- -header (`docutils.parsers.rst.directives.parts.Header`): +[header] (`docutils.parsers.rst.directives.parts.Header`): . ```{header} @@ -409,7 +408,7 @@ a . -------------------------------- -footer (`docutils.parsers.rst.directives.parts.Footer`): +[footer] (`docutils.parsers.rst.directives.parts.Footer`): . ```{footer} @@ -424,7 +423,7 @@ a . -------------------------------- -target-notes (`docutils.parsers.rst.directives.references.TargetNotes`): +[target-notes] (`docutils.parsers.rst.directives.references.TargetNotes`): . ```{target-notes} ``` diff --git a/tests/test_renderers/fixtures/docutil_roles.md b/tests/test_renderers/fixtures/docutil_roles.md index a75711f8..1aabac99 100644 --- a/tests/test_renderers/fixtures/docutil_roles.md +++ b/tests/test_renderers/fixtures/docutil_roles.md @@ -1,5 +1,5 @@ -------------------------------- -abbreviation (`docutils.parsers.rst.roles.GenericRole`): +[abbreviation] (`docutils.parsers.rst.roles.GenericRole`): . {abbreviation}`a` . @@ -10,7 +10,7 @@ abbreviation (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -acronym (`docutils.parsers.rst.roles.GenericRole`): +[acronym] (`docutils.parsers.rst.roles.GenericRole`): . {acronym}`a` . @@ -21,7 +21,7 @@ acronym (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -emphasis (`docutils.parsers.rst.roles.GenericRole`): +[emphasis] (`docutils.parsers.rst.roles.GenericRole`): . {emphasis}`a` . @@ -32,7 +32,7 @@ emphasis (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -literal (`docutils.parsers.rst.roles.GenericRole`): +[literal] (`docutils.parsers.rst.roles.GenericRole`): . {literal}`a` . @@ -43,7 +43,7 @@ literal (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -strong (`docutils.parsers.rst.roles.GenericRole`): +[strong] (`docutils.parsers.rst.roles.GenericRole`): . {strong}`a` . @@ -54,7 +54,7 @@ strong (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -subscript (`docutils.parsers.rst.roles.GenericRole`): +[subscript] (`docutils.parsers.rst.roles.GenericRole`): . {subscript}`a` . @@ -65,7 +65,7 @@ subscript (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -superscript (`docutils.parsers.rst.roles.GenericRole`): +[superscript] (`docutils.parsers.rst.roles.GenericRole`): . {superscript}`a` . @@ -76,7 +76,7 @@ superscript (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -title-reference (`docutils.parsers.rst.roles.GenericRole`): +[title-reference] (`docutils.parsers.rst.roles.GenericRole`): . {title-reference}`t` . @@ -87,7 +87,7 @@ title-reference (`docutils.parsers.rst.roles.GenericRole`): . -------------------------------- -pep-reference (`docutils.parsers.rst.roles.pep_reference_role`): +[pep-reference] (`docutils.parsers.rst.roles.pep_reference_role`): . {pep-reference}`0` . @@ -98,7 +98,7 @@ pep-reference (`docutils.parsers.rst.roles.pep_reference_role`): . -------------------------------- -rfc-reference (`docutils.parsers.rst.roles.rfc_reference_role`): +[rfc-reference] (`docutils.parsers.rst.roles.rfc_reference_role`): . {rfc-reference}`1` . @@ -109,7 +109,7 @@ rfc-reference (`docutils.parsers.rst.roles.rfc_reference_role`): . -------------------------------- -code (`docutils.parsers.rst.roles.code_role`): +[code] (`docutils.parsers.rst.roles.code_role`): . {code}`a` . @@ -120,7 +120,7 @@ code (`docutils.parsers.rst.roles.code_role`): . -------------------------------- -math (`docutils.parsers.rst.roles.math_role`): +[math] (`docutils.parsers.rst.roles.math_role`): . {math}`a` . diff --git a/tests/test_renderers/test_error_reporting.py b/tests/test_renderers/test_error_reporting.py index 5babebf4..daa677e8 100644 --- a/tests/test_renderers/test_error_reporting.py +++ b/tests/test_renderers/test_error_reporting.py @@ -1,28 +1,21 @@ from io import StringIO from pathlib import Path -import pytest from docutils.core import publish_doctree -from markdown_it.utils import read_fixture_file +from pytest_param_files import with_parameters from myst_parser.docutils_ import Parser FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("reporter_warnings.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "reporter_warnings.md") - ], -) -def test_basic(line, title, input, expected): +@with_parameters(FIXTURE_PATH / "reporter_warnings.md") +def test_basic(file_params): """Test basic functionality.""" report_stream = StringIO() publish_doctree( - input, parser=Parser(), settings_overrides={"warning_stream": report_stream} + file_params.content, + parser=Parser(), + settings_overrides={"warning_stream": report_stream}, ) - - assert report_stream.getvalue().rstrip() == expected.rstrip() + file_params.assert_expected(report_stream.getvalue(), rstrip=True) diff --git a/tests/test_renderers/test_fixtures_docutils.py b/tests/test_renderers/test_fixtures_docutils.py index 462900d3..d9482e81 100644 --- a/tests/test_renderers/test_fixtures_docutils.py +++ b/tests/test_renderers/test_fixtures_docutils.py @@ -5,7 +5,7 @@ from pathlib import Path import pytest -from markdown_it.utils import read_fixture_file +from pytest_param_files import with_parameters from myst_parser.docutils_renderer import DocutilsRenderer, make_document from myst_parser.main import MdParserConfig, create_md_parser @@ -13,70 +13,33 @@ FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("docutil_syntax_elements.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "docutil_syntax_elements.md") - ], -) -def test_syntax_elements(line, title, input, expected): +@with_parameters(FIXTURE_PATH / "docutil_syntax_elements.md") +def test_syntax_elements(file_params): parser = create_md_parser( MdParserConfig(highlight_code_blocks=False), DocutilsRenderer ) parser.options["document"] = document = make_document() - parser.render(input) - outcome = "\n".join([ll.rstrip() for ll in document.pformat().splitlines()]) + parser.render(file_params.content) # in docutils 0.18 footnote ids have changed - outcome = outcome.replace('"footnote-reference-1"', '"id1"') - try: - assert outcome == "\n".join([ll.rstrip() for ll in expected.splitlines()]) - except AssertionError: - print(document.pformat()) - raise + outcome = document.pformat().replace('"footnote-reference-1"', '"id1"') + file_params.assert_expected(outcome, rstrip_lines=True) -@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): +@with_parameters(FIXTURE_PATH / "docutil_roles.md") +def test_docutils_roles(file_params): """Test output of docutils roles.""" 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 + parser.render(file_params.content) + file_params.assert_expected(document.pformat(), rstrip_lines=True) -@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): +@with_parameters(FIXTURE_PATH / "docutil_directives.md") +def test_docutils_directives(file_params): """Test output of docutils directives.""" - if title.startswith("SKIP"): # line-block directive not yet supported - pytest.skip(title) + if "SKIP" in file_params.description: # line-block directive not yet supported + pytest.skip(file_params.description) 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 + parser.render(file_params.content) + file_params.assert_expected(document.pformat(), rstrip_lines=True) diff --git a/tests/test_renderers/test_fixtures_sphinx.py b/tests/test_renderers/test_fixtures_sphinx.py index 3ada5c58..69d0c87b 100644 --- a/tests/test_renderers/test_fixtures_sphinx.py +++ b/tests/test_renderers/test_fixtures_sphinx.py @@ -7,7 +7,7 @@ import pytest import sphinx -from markdown_it.utils import read_fixture_file +from pytest_param_files import with_parameters from myst_parser.main import MdParserConfig, to_docutils from myst_parser.sphinx_renderer import SphinxRenderer, mock_sphinx_env @@ -20,163 +20,84 @@ def test_minimal_sphinx(): assert app.config["author"] == "bob geldof" -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("sphinx_syntax_elements.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "sphinx_syntax_elements.md") - ], -) -def test_syntax_elements(line, title, input, expected): - document = to_docutils(input, in_sphinx_env=True) - 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("tables.md")), - ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "tables.md")], -) -def test_tables(line, title, input, expected): - document = to_docutils(input, in_sphinx_env=True) - 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("directive_options.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "directive_options.md") - ], -) -def test_directive_options(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("sphinx_directives.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "sphinx_directives.md") - ], -) -def test_sphinx_directives(line, title, input, expected): +@with_parameters(FIXTURE_PATH / "sphinx_syntax_elements.md") +def test_syntax_elements(file_params): + document = to_docutils(file_params.content, in_sphinx_env=True) + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "tables.md") +def test_tables(file_params): + document = to_docutils(file_params.content, in_sphinx_env=True) + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "directive_options.md") +def test_directive_options(file_params): + document = to_docutils(file_params.content) + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "sphinx_directives.md") +def test_sphinx_directives(file_params): # TODO fix skipped directives # TODO test domain directives - if title.startswith("SKIP"): - pytest.skip(title) - elif title.startswith("SPHINX3") and sphinx.version_info[0] < 3: - pytest.skip(title) - elif title.startswith("SPHINX4") and sphinx.version_info[0] < 4: - pytest.skip(title) - document = to_docutils(input, in_sphinx_env=True) - _actual, _expected = [ - "\n".join([ll.rstrip() for ll in text.splitlines()]) - for text in (document.pformat(), expected) - ] - try: - assert _actual == _expected - except AssertionError: - print(document.pformat()) - raise - - -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("sphinx_roles.md")), - ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "sphinx_roles.md")], -) -def test_sphinx_roles(line, title, input, expected): - if title.startswith("SKIP"): - pytest.skip(title) - elif title.startswith("SPHINX4") and sphinx.version_info[0] < 4: - pytest.skip(title) - document = to_docutils(input, in_sphinx_env=True) - print(document.pformat()) - _actual, _expected = [ - "\n".join([ll.rstrip() for ll in text.splitlines()]) - for text in (document.pformat(), expected) - ] + if file_params.title.startswith("SKIP"): + pytest.skip(file_params.title) + elif file_params.title.startswith("SPHINX3") and sphinx.version_info[0] < 3: + pytest.skip(file_params.title) + elif file_params.title.startswith("SPHINX4") and sphinx.version_info[0] < 4: + pytest.skip(file_params.title) + document = to_docutils(file_params.content, in_sphinx_env=True) + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "sphinx_roles.md") +def test_sphinx_roles(file_params): + if file_params.title.startswith("SKIP"): + pytest.skip(file_params.title) + elif file_params.title.startswith("SPHINX4") and sphinx.version_info[0] < 4: + pytest.skip(file_params.title) + document = to_docutils(file_params.content, in_sphinx_env=True) + actual = document.pformat() # sphinx 3 adds a parent key - _actual = re.sub('cpp:parent_key="[^"]*"', 'cpp:parent_key=""', _actual) - assert _actual == _expected + actual = re.sub('cpp:parent_key="[^"]*"', 'cpp:parent_key=""', actual) + file_params.assert_expected(actual, rstrip_lines=True) -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("amsmath.md")), - ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "amsmath.md")], -) -def test_amsmath(line, title, input, expected, monkeypatch): +@with_parameters(FIXTURE_PATH / "amsmath.md") +def test_amsmath(file_params, monkeypatch): monkeypatch.setattr(SphinxRenderer, "_random_label", lambda self: "mock-uuid") document = to_docutils( - input, MdParserConfig(enable_extensions=["amsmath"]), in_sphinx_env=True + file_params.content, + MdParserConfig(enable_extensions=["amsmath"]), + in_sphinx_env=True, ) - print(document.pformat()) - _actual, _expected = [ - "\n".join([ll.rstrip() for ll in text.splitlines()]) - for text in (document.pformat(), expected) - ] - assert _actual == _expected - - -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("containers.md")), - ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "containers.md")], -) -def test_containers(line, title, input, expected, monkeypatch): + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "containers.md") +def test_containers(file_params, monkeypatch): monkeypatch.setattr(SphinxRenderer, "_random_label", lambda self: "mock-uuid") document = to_docutils( - input, MdParserConfig(enable_extensions=["colon_fence"]), in_sphinx_env=True + file_params.content, + MdParserConfig(enable_extensions=["colon_fence"]), + in_sphinx_env=True, ) - print(document.pformat()) - _actual, _expected = [ - "\n".join([ll.rstrip() for ll in text.splitlines()]) - for text in (document.pformat(), expected) - ] - assert _actual == _expected - - -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("eval_rst.md")), - ids=[f"{i[0]}-{i[1]}" for i in read_fixture_file(FIXTURE_PATH / "eval_rst.md")], -) -def test_evalrst_elements(line, title, input, expected): - document = to_docutils(input, in_sphinx_env=True) - 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("definition_lists.md")), - ids=[ - f"{i[0]}-{i[1]}" - for i in read_fixture_file(FIXTURE_PATH / "definition_lists.md") - ], -) -def test_definition_lists(line, title, input, expected): + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "eval_rst.md") +def test_evalrst_elements(file_params): + document = to_docutils(file_params.content, in_sphinx_env=True) + file_params.assert_expected(document.pformat(), rstrip_lines=True) + + +@with_parameters(FIXTURE_PATH / "definition_lists.md") +def test_definition_lists(file_params): document = to_docutils( - input, MdParserConfig(enable_extensions=["deflist"]), in_sphinx_env=True + file_params.content, + MdParserConfig(enable_extensions=["deflist"]), + in_sphinx_env=True, ) - print(document.pformat()) - assert "\n".join( - [ll.rstrip() for ll in document.pformat().splitlines()] - ) == "\n".join([ll.rstrip() for ll in expected.splitlines()]) + file_params.assert_expected(document.pformat(), rstrip_lines=True) diff --git a/tests/test_renderers/test_include_directive.py b/tests/test_renderers/test_include_directive.py index 8cdc5881..908afb8b 100644 --- a/tests/test_renderers/test_include_directive.py +++ b/tests/test_renderers/test_include_directive.py @@ -2,7 +2,7 @@ from pathlib import Path import pytest -from markdown_it.utils import read_fixture_file +from pytest_param_files import with_parameters from myst_parser.docutils_renderer import make_document from myst_parser.main import to_docutils @@ -10,26 +10,21 @@ FIXTURE_PATH = Path(__file__).parent.joinpath("fixtures") -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("mock_include.md")), -) -def test_render(line, title, input, expected, tmp_path): +@with_parameters(FIXTURE_PATH / "mock_include.md") +def test_render(file_params, tmp_path): tmp_path.joinpath("other.md").write_text("a\nb\nc") tmp_path.joinpath("fmatter.md").write_text("---\na: 1\n---\nb") document = make_document(str(tmp_path / "test.md")) - to_docutils(input, document=document, in_sphinx_env=True, srcdir=str(tmp_path)) + to_docutils( + file_params.content, document=document, in_sphinx_env=True, srcdir=str(tmp_path) + ) output = document.pformat().replace(str(tmp_path) + os.sep, "tmpdir" + "/").rstrip() - print(output) - assert output == expected.rstrip() + file_params.assert_expected(output, rstrip=True) -@pytest.mark.parametrize( - "line,title,input,expected", - read_fixture_file(FIXTURE_PATH.joinpath("mock_include_errors.md")), -) -def test_errors(line, title, input, expected, tmp_path): - if title.startswith("Non-existent path") and os.name == "nt": +@with_parameters(FIXTURE_PATH / "mock_include_errors.md") +def test_errors(file_params, tmp_path): + if file_params.title.startswith("Non-existent path") and os.name == "nt": pytest.skip("tmp_path not converted correctly on Windows") tmp_path.joinpath("bad.md").write_text("{a}`b`") @@ -44,5 +39,7 @@ def observer(msg_node): document.reporter.attach_observer(observer) document.reporter.halt_level = 6 - to_docutils(input, document=document, in_sphinx_env=True, srcdir=str(tmp_path)) - assert "\n".join(messages).rstrip() == expected.rstrip() + to_docutils( + file_params.content, document=document, in_sphinx_env=True, srcdir=str(tmp_path) + ) + file_params.assert_expected("\n".join(messages), rstrip=True)