2
0
Fork 0
textout/tests/test_builtin.py

55 lines
1.8 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.
# *****************************************************************************
"""Builtin tag tests for textoutpc."""
from __future__ import annotations
import pytest
from textoutpc.builtin import AlignTag, TextTag
from textoutpc.exceptions import InvalidValue, MissingValue, UnexpectedValue
@pytest.mark.parametrize(
"name,value,exc",
(
("[font]", None, MissingValue),
("[font]", "invalid", InvalidValue),
("[arial]", "unexpected", UnexpectedValue),
("[big]", "unexpected", UnexpectedValue),
("[small]", "unexpected", UnexpectedValue),
("[size]", None, MissingValue),
("[size]", "invalid", InvalidValue),
("[size]", "-1", InvalidValue),
("[size]", "-1.00", InvalidValue),
("[c]", None, MissingValue),
("[c]", "rgb(", InvalidValue),
("[f]", None, MissingValue),
("[f]", "rgb(", InvalidValue),
("[red]", "unexpected", UnexpectedValue),
("[css]", None, MissingValue),
),
)
def test_text_tag_errors(exc: type[Exception], name: str, value: str | None):
"""Test the text tag errors."""
with pytest.raises(exc):
TextTag(name=name, value=value)
def test_align_tag_errors():
"""Test the align tag errors."""
with pytest.raises(MissingValue):
AlignTag(name="[align]")
with pytest.raises(InvalidValue):
AlignTag(name="[align]", value="invalid")
with pytest.raises(ValueError):
AlignTag(name="[invalid]")
with pytest.raises(UnexpectedValue):
AlignTag(name="[center]", value="unexpected")