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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
import pytest
from tcolorpy import AnsiBGColor, AnsiFGColor, Color, tcolor
class Test_truecolor_color:
@pytest.mark.parametrize(
["string", "color", "expected"],
[
["test", "#ff8822", "\x1b[38;2;255;136;34mtest\x1b[0m"],
["test", "ff8822", "\x1b[38;2;255;136;34mtest\x1b[0m"],
["test", "red", "\x1b[31mtest\x1b[0m"],
["test", Color("red"), "\x1b[31mtest\x1b[0m"],
["test", (255, 136, 34), "\x1b[38;2;255;136;34mtest\x1b[0m"],
["test", Color("#ff8822"), "\x1b[38;2;255;136;34mtest\x1b[0m"],
["test", Color((255, 136, 34)), "\x1b[38;2;255;136;34mtest\x1b[0m"],
["test", None, "test"],
],
)
def test_normal(self, string, color, expected):
assert tcolor(string, color=color) == expected
def test_smoke(self):
string = "test"
for color in AnsiFGColor:
assert tcolor(string, color=color) != string
for color in AnsiBGColor:
assert tcolor(string, bg_color=color) != string
@pytest.mark.parametrize(
["value", "expected"],
[
["#fffff", ValueError],
["#GGGGGG", ValueError],
],
)
def test_exception(self, value, expected):
with pytest.raises(expected):
tcolor("test", color=value) == expected
class Test_truecolor_bg_color:
@pytest.mark.parametrize(
["string", "color", "expected"],
[
["test", "#ff8822", "\x1b[48;2;255;136;34mtest\x1b[0m"],
["test", "ff8822", "\x1b[48;2;255;136;34mtest\x1b[0m"],
["test", "red", "\x1b[41mtest\x1b[0m"],
["test", Color("red"), "\x1b[41mtest\x1b[0m"],
["test", "light-red", "\x1b[101mtest\x1b[0m"],
["test", (255, 136, 34), "\x1b[48;2;255;136;34mtest\x1b[0m"],
["test", Color("#ff8822"), "\x1b[48;2;255;136;34mtest\x1b[0m"],
["test", Color((255, 136, 34)), "\x1b[48;2;255;136;34mtest\x1b[0m"],
["test", None, "test"],
],
)
def test_normal_bg_color(self, string, color, expected):
assert tcolor(string, bg_color=color) == expected
class Test_truecolor_fg_bg_color:
@pytest.mark.parametrize(
["string", "color", "bg_color", "expected"],
[
["test", "#111111", "#ffffff", "\x1b[48;2;255;255;255m\x1b[38;2;17;17;17mtest\x1b[0m"],
["test", "red", "white", "\x1b[47m\x1b[31mtest\x1b[0m"],
["test", None, None, "test"],
],
)
def test_normal_fg_bg_color(self, string, color, bg_color, expected):
assert tcolor(string, color=color, bg_color=bg_color) == expected
class Test_truecolor_styles:
@pytest.mark.parametrize(
["string", "styles", "expected"],
[
["test", [], "test"],
["test", ["bold"], "\x1b[1mtest\x1b[0m"],
["test", ["dim"], "\x1b[2mtest\x1b[0m"],
["test", ["italic"], "\x1b[3mtest\x1b[0m"],
["test", ["underline"], "\x1b[4mtest\x1b[0m"],
["test", ["blink"], "\x1b[5mtest\x1b[0m"],
["test", ["invert"], "\x1b[7mtest\x1b[0m"],
["test", ["strike"], "\x1b[9mtest\x1b[0m"],
["test", ["bold", "dim"], "\x1b[1m\x1b[2mtest\x1b[0m"],
],
)
def test_normal_bg_color(self, string, styles, expected):
assert tcolor("test", styles=styles) == expected
|