@@ -113,6 +113,80 @@ def test_timestamp(dumb_tty: DumbTTY, toggle_timestamp: None) -> None:
113113 assert datetime .datetime .strptime (match .groups ()[0 ], "%Y-%m-%d %H:%M:%S" )
114114
115115
116+ def test_table_with_lists_no_color (dumb_tty : DumbTTY ) -> None :
117+ headers = ["name" , "score" ]
118+ data = [
119+ [(cli_ui .bold , "John" ), (cli_ui .green , 10 )],
120+ [(cli_ui .bold , "Jane" ), (cli_ui .green , 5 )],
121+ ]
122+ cli_ui .info_table (data , headers = headers , fileobj = dumb_tty )
123+ actual = dumb_tty .getvalue ()
124+ # fmt: off
125+ expected = (
126+ "name score\n "
127+ "------ -------\n "
128+ "John 10\n "
129+ "Jane 5\n "
130+ )
131+ # fmt: on
132+ assert actual == expected
133+
134+
135+ def test_table_with_dict_no_color (dumb_tty : DumbTTY ) -> None :
136+ data = {
137+ (cli_ui .bold , "Name" ): [(cli_ui .green , "Alice" ), (cli_ui .green , "Bob" )],
138+ (cli_ui .bold , "Age" ): [(cli_ui .blue , 24 ), (cli_ui .blue , 9 )],
139+ }
140+ cli_ui .info_table (data , headers = "keys" , fileobj = dumb_tty )
141+ actual = dumb_tty .getvalue ()
142+ # fmt: off
143+ expected = (
144+ "Name Age\n "
145+ "------ -----\n "
146+ "Alice 24\n "
147+ "Bob 9\n "
148+ )
149+ # fmt: on
150+ assert actual == expected
151+
152+
153+ def test_table_with_dict_and_color (smart_tty : SmartTTY ) -> None :
154+ data = {
155+ (cli_ui .bold , "Name" ,): [(cli_ui .green , "Alice" ), (cli_ui .green , "Bob" )],
156+ (cli_ui .bold , "Age" ,): [(cli_ui .blue , 24 ), (cli_ui .blue , 9 )],
157+ }
158+ cli_ui .info_table (data , headers = "keys" , fileobj = smart_tty )
159+ actual = smart_tty .getvalue ()
160+ # fmt: off
161+ expected = (
162+ f"{ BRIGHT } Name{ RESET_ALL } { BRIGHT } Age{ RESET_ALL } \n "
163+ "------ -----\n "
164+ f"{ GREEN } Alice{ RESET_ALL } { BLUE } 24{ RESET_ALL } \n "
165+ f"{ GREEN } Bob{ RESET_ALL } { BLUE } 9{ RESET_ALL } \n "
166+ )
167+ # fmt: on
168+ assert actual == expected
169+
170+
171+ def test_table_with_lists_with_color (smart_tty : SmartTTY ) -> None :
172+ headers = ["name" , "score" ]
173+ data = [
174+ [(cli_ui .bold , "John" ), (cli_ui .green , 10 )],
175+ [(cli_ui .bold , "Jane" ), (cli_ui .green , 5 )],
176+ ]
177+ cli_ui .info_table (data , headers = headers , fileobj = smart_tty )
178+ actual = smart_tty .getvalue ()
179+ # fmt: off
180+ expected = (
181+ "name score\n "
182+ "------ -------\n "
183+ f"{ BRIGHT } John{ RESET_ALL } { GREEN } 10{ RESET_ALL } \n "
184+ f"{ BRIGHT } Jane{ RESET_ALL } { GREEN } 5{ RESET_ALL } \n "
185+ )
186+ # fmt: on
187+ assert actual == expected
188+
189+
116190def test_record_message (message_recorder : MessageRecorder ) -> None :
117191 cli_ui .info_1 ("This is foo" )
118192 assert message_recorder .find ("foo" )
0 commit comments