def test_dollarmath(file_params, sphinx_doctree_no_tr: CreateDoctree): sphinx_doctree_no_tr.set_conf({ "extensions": ["myst_parser"], "myst_enable_extensions": ["dollarmath"] }) result = sphinx_doctree_no_tr(file_params.content, "index.md") file_params.assert_expected(result.pformat("index"), rstrip_lines=True)
def test_amsmath(file_params, sphinx_doctree_no_tr: CreateDoctree, monkeypatch): monkeypatch.setattr(SphinxRenderer, "_random_label", lambda self: "mock-uuid") sphinx_doctree_no_tr.set_conf({ "extensions": ["myst_parser"], "myst_enable_extensions": ["amsmath"] }) result = sphinx_doctree_no_tr(file_params.content, "index.md") file_params.assert_expected(result.pformat("index"), rstrip_lines=True)
def test_sphinx_roles(file_params, sphinx_doctree_no_tr: CreateDoctree): 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) sphinx_doctree_no_tr.set_conf({"extensions": ["myst_parser"]}) pformat = sphinx_doctree_no_tr(file_params.content, "index.md").pformat("index") # sphinx 3 adds a parent key pformat = re.sub('cpp:parent_key="[^"]*"', 'cpp:parent_key=""', pformat) # sphinx >= 4.5.0 adds a trailing slash to PEP URLs, # see https://github.com/sphinx-doc/sphinx/commit/658689433eacc9eb pformat = pformat.replace( ' refuri="http://www.python.org/dev/peps/pep-0001">', ' refuri="http://www.python.org/dev/peps/pep-0001/">', ) file_params.assert_expected(pformat, rstrip_lines=True)
def test_sphinx_directives(file_params, sphinx_doctree_no_tr: CreateDoctree): # TODO fix skipped directives # TODO test domain directives 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) sphinx_doctree_no_tr.set_conf({"extensions": ["myst_parser"]}) pformat = sphinx_doctree_no_tr(file_params.content, "index.md").pformat("index") # see https://github.com/sphinx-doc/sphinx/issues/9827 pformat = pformat.replace('<glossary sorted="False">', "<glossary>") # see https://github.com/executablebooks/MyST-Parser/issues/522 if sys.maxsize == 2147483647: pformat = pformat.replace('"2147483647"', '"9223372036854775807"') file_params.assert_expected(pformat, rstrip_lines=True)
def test_parse( test_name: str, text: str, should_warn: bool, sphinx_doctree: CreateDoctree, file_regression, ): sphinx_doctree.set_conf({"extensions": ["myst_parser"]}) result = sphinx_doctree(text, "index.md") assert not result.warnings doctree = result.get_resolved_doctree("index") if should_warn: assert result.warnings else: assert not result.warnings doctree["source"] = "root/index.md" file_regression.check(doctree.pformat(), basename=test_name, extension=".xml")