File: test_html_parser.py

package info (click to toggle)
doxysphinx 3.3.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,296 kB
  • sloc: python: 2,974; javascript: 235; cpp: 88; makefile: 52; sh: 10
file content (61 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
from pathlib import Path
from typing import Any, Iterable, List, Tuple

import lxml.etree as etree
import pytest

from doxysphinx.html_parser import DoxygenHtmlParser, HtmlParser


def _read_data() -> List[Any]:
    results = []
    test_files = Path(__file__).parent / "test_files"
    for input_file in test_files.glob("*.input.html"):
        expected_name = Path(input_file.stem).stem
        expected_file = input_file.parent / (expected_name + ".expected.html")
        results.append((input_file, expected_file))
    return results


def ids_for(values: List[Any]) -> List[str]:
    results = []

    for v in values:
        first, second = v
        name = Path(first.stem).stem
        results.append(name)

    return results


DATA = _read_data()


@pytest.mark.parametrize("input, expected", DATA, ids=ids_for(DATA))
def test_html_parser_works_as_expected(input: Path, expected: Path):

    x = DoxygenHtmlParser(Path(__file__).parent)
    result = x.parse(input)

    # if the result has no tree (= no snippets found), we ensure that no expected file exists and vice versa
    if not expected.exists():
        assert result.tree == None
        return

    if result.tree == None:
        assert not expected.exists()
        return

    parsed_html = etree.tostring(
        result.tree,
        encoding="unicode",
    )

    # if there was a result and an expected file then we compare them...
    parsed_output = input.parent / (Path(input.stem).stem + ".parsed.html")
    parsed_output.write_text(parsed_html)

    expected_html = expected.read_text()

    assert parsed_html.strip() == expected_html.strip()