40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/env python
|
|
# *****************************************************************************
|
|
# Copyright (C) 2023 Thomas Touhey <thomas@touhey.fr>
|
|
# This file is part of the textoutpc project, which is MIT-licensed.
|
|
# *****************************************************************************
|
|
"""Tags tests for textoutpc."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Sequence
|
|
|
|
from docutils.nodes import Node, Text, TextElement, container
|
|
import pytest
|
|
|
|
from textoutpc.tags import Tag
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"nodes,expected",
|
|
(
|
|
([], ""),
|
|
([TextElement("", Text("hello, world"))], "hello, world"),
|
|
),
|
|
)
|
|
def test_get_raw_text(nodes: Sequence[Node], expected: str):
|
|
"""Get raw text."""
|
|
assert Tag.get_text_from_raw_children(nodes) == expected
|
|
|
|
|
|
def test_get_raw_text_with_more_children():
|
|
"""Check that raw text cannot be obtained in some cases."""
|
|
with pytest.raises(AssertionError, match=r"More than one"):
|
|
Tag.get_text_from_raw_children([Text("hello,"), Text(" world")])
|
|
|
|
|
|
def test_get_raw_text_from_unsupported_children():
|
|
"""Check that raw text cannot be obtained with unsupported types."""
|
|
with pytest.raises(AssertionError, match=r"Unsupported child"):
|
|
Tag.get_text_from_raw_children([container("", Text("hello"))])
|