File indexing completed on 2024-09-08 05:10:01
0001 import pytest 0002 0003 from pology.colors import ColorString 0004 0005 0006 class TTYMock: 0007 0008 def isatty(self): 0009 return True 0010 0011 0012 TTY_MOCK = TTYMock() 0013 0014 0015 def test_iter(): 0016 character_list = [c for c in ColorString("foo")] 0017 assert character_list == [ 0018 ColorString("f"), 0019 ColorString("o"), 0020 ColorString("o"), 0021 ] 0022 assert all(isinstance(c, ColorString) for c in character_list) 0023 0024 0025 @pytest.mark.parametrize( 0026 "input,output,ctype,dest", 0027 ( 0028 ("<red>foo</red>", "foo", None, None), 0029 ("<red>foo</red>", "foo", "term", None), 0030 ("<red>foo</red>", "\033[31mfoo\033[0;0m", "term", TTY_MOCK), 0031 ("<red><blue>foo</blue></red>", "\033[31m<blue>foo</blue>\033[0;0m", "term", TTY_MOCK), 0032 ("<red>foo</red>", "<font color='#ff0000'>foo</font><br/>", "html", None), 0033 ), 0034 ) 0035 def test_resolve(input, output, ctype, dest): 0036 assert ColorString(input).resolve(ctype=ctype, dest=dest) == output