test: cover the validator, the directory and the site
This commit is contained in:
parent
003bb0b4b1
commit
1e75a69381
44 changed files with 1796 additions and 0 deletions
65
tests/test_pages.py
Normal file
65
tests/test_pages.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
"""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", [" <p>x</p>"], "en", None, None, None),
|
||||
("With a variant", [" <p>x</p>"], "en", None, "mews-cool", None),
|
||||
("Right to left", [" <p>x</p>"], "he", "rtl", None, None),
|
||||
("Described", [" <p>x</p>"], "en", None, "mews-warm", "A page."),
|
||||
("An ampersand & a <tag>", [" <p>x</p>"], "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', [" <p>x</p>"])
|
||||
assert '<title>A "quoted" title</title>' in text
|
||||
|
||||
|
||||
def test_an_apostrophe_is_not_escaped():
|
||||
text = pages.message("Hello", ["It isn't escaped."], [("/", "Home")])
|
||||
assert "isn't escaped" in text
|
||||
Loading…
Add table
Add a link
Reference in a new issue