"""The page emitter, against md2mews.py's. mews.pages repeats md2mews.page() because md2mews.py is a standalone script with its own dependencies. This is what keeps the two in step. """ import importlib.util from pathlib import Path import sys import pytest from mews import pages ROOT = Path(__file__).resolve().parent.parent def load_md2mews(): """Import md2mews.py, which is a script rather than part of the package.""" spec = importlib.util.spec_from_file_location("md2mews", ROOT / "md2mews.py") module = importlib.util.module_from_spec(spec) sys.modules["md2mews"] = module spec.loader.exec_module(module) return module CASES = [ ("Plain", ["
x
"], "en", None, None, None), ("With a variant", ["x
"], "en", None, "mews-cool", None), ("Right to left", ["x
"], "he", "rtl", None, None), ("Described", ["x
"], "en", None, "mews-warm", "A page."), ("An ampersand & ax
"], "en", None, None, None), ] @pytest.mark.parametrize("case", CASES) def test_the_two_emitters_agree(case): """Same prologue, head order, body attributes and escaping of & and <. The two differ on quote characters in text, which md2mews.py escapes because its one escape helper also fills attribute values. Both are well-formed; mews.pages leaves them alone so prose reads as prose. """ md2mews = pytest.importorskip("mistune") and load_md2mews() title, body, language, direction, variant, description = case assert pages.page(title, body, language, direction, variant, description) == ( md2mews.page(title, body, language, direction, variant, description) ) def test_a_message_page_conforms(): from mews.lint import validate_bytes text = pages.message("Hello", ["One.", "Two."], [("/", "Home")]) assert validate_bytes(text.encode()).conforms def test_quotes_in_text_are_left_alone(): text = pages.site_page('A "quoted" title', ["x
"]) assert '