File: test_doctype.py

package info (click to toggle)
python-kajiki 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 692 kB
  • sloc: python: 4,145; makefile: 115
file content (44 lines) | stat: -rw-r--r-- 1,281 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pytest

from kajiki.doctype import DocumentTypeDeclaration, extract_dtd

XHTML1 = (
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
    '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
)


@pytest.mark.parametrize(
    ["uri", "name", "rendering_mode", "stringified"],
    [
        ["", "html5", "html5", "<!DOCTYPE html>"],
        [None, "xhtml5", "xml", "<!DOCTYPE html>"],
        [
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
            "xhtml1transitional",
            "xml",
            XHTML1,
        ],
    ],
)
def test_dtd_by_uri(uri, name, rendering_mode, stringified):
    dtd = DocumentTypeDeclaration.by_uri[uri]
    assert dtd.name == name
    assert dtd.rendering_mode == rendering_mode
    assert str(dtd) == stringified


def test_extract_dtd():
    html = "<div>Test template</div>"
    markup = XHTML1 + html
    extracted, pos, rest = extract_dtd(markup)  # The function being tested
    assert extracted == XHTML1
    assert pos == 0
    assert rest == html
    dtd = DocumentTypeDeclaration.matching(extracted)  # Another function
    assert (
        dtd
        is DocumentTypeDeclaration.by_uri[
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
        ]
    )