22
33import typing
44
5+ import pytest
6+
57import progressbar
68import progressbar .env
79import progressbar .terminal
8- import pytest
910from progressbar import env , terminal , widgets
10- from progressbar .terminal import Colors , apply_colors , colors
11+ from progressbar .terminal import apply_colors , Colors , colors
1112
1213
1314@pytest .mark .parametrize (
@@ -52,7 +53,7 @@ def test_color_environment_variables(monkeypatch, variable):
5253 'xterm-256' ,
5354 'xterm' ,
5455 ],
55- )
56+ )
5657def test_color_support_from_env (monkeypatch , variable , value ):
5758 monkeypatch .setenv ('JUPYTER_COLUMNS' , '' )
5859 monkeypatch .setenv ('JUPYTER_LINES' , '' )
@@ -222,63 +223,63 @@ def test_rgb_to_hls(rgb, hls):
222223 ('test' , None , None , None , None , None , 'test' ),
223224 ('test' , None , None , None , None , 1 , 'test' ),
224225 (
225- 'test' ,
226- None ,
227- None ,
228- None ,
229- colors .red ,
230- None ,
231- '\x1b [48;5;9mtest\x1b [49m' ,
226+ 'test' ,
227+ None ,
228+ None ,
229+ None ,
230+ colors .red ,
231+ None ,
232+ '\x1b [48;5;9mtest\x1b [49m' ,
232233 ),
233234 (
234- 'test' ,
235- None ,
236- colors .green ,
237- None ,
238- colors .red ,
239- None ,
240- '\x1b [48;5;9mtest\x1b [49m' ,
235+ 'test' ,
236+ None ,
237+ colors .green ,
238+ None ,
239+ colors .red ,
240+ None ,
241+ '\x1b [48;5;9mtest\x1b [49m' ,
241242 ),
242243 ('test' , None , colors .red , None , None , 1 , '\x1b [48;5;9mtest\x1b [49m' ),
243244 ('test' , None , colors .red , None , None , None , 'test' ),
244245 (
245- 'test' ,
246- colors .green ,
247- None ,
248- colors .red ,
249- None ,
250- None ,
251- '\x1b [38;5;9mtest\x1b [39m' ,
246+ 'test' ,
247+ colors .green ,
248+ None ,
249+ colors .red ,
250+ None ,
251+ None ,
252+ '\x1b [38;5;9mtest\x1b [39m' ,
252253 ),
253254 (
254- 'test' ,
255- colors .green ,
256- colors .red ,
257- None ,
258- None ,
259- 1 ,
260- '\x1b [48;5;9m\x1b [38;5;2mtest\x1b [39m\x1b [49m' ,
255+ 'test' ,
256+ colors .green ,
257+ colors .red ,
258+ None ,
259+ None ,
260+ 1 ,
261+ '\x1b [48;5;9m\x1b [38;5;2mtest\x1b [39m\x1b [49m' ,
261262 ),
262263 ('test' , colors .red , None , None , None , 1 , '\x1b [38;5;9mtest\x1b [39m' ),
263264 ('test' , colors .red , None , None , None , None , 'test' ),
264265 ('test' , colors .red , colors .red , None , None , None , 'test' ),
265266 (
266- 'test' ,
267- colors .red ,
268- colors .yellow ,
269- None ,
270- None ,
271- 1 ,
272- '\x1b [48;5;11m\x1b [38;5;9mtest\x1b [39m\x1b [49m' ,
267+ 'test' ,
268+ colors .red ,
269+ colors .yellow ,
270+ None ,
271+ None ,
272+ 1 ,
273+ '\x1b [48;5;11m\x1b [38;5;9mtest\x1b [39m\x1b [49m' ,
273274 ),
274275 (
275- 'test' ,
276- colors .red ,
277- colors .yellow ,
278- None ,
279- None ,
280- 1 ,
281- '\x1b [48;5;11m\x1b [38;5;9mtest\x1b [39m\x1b [49m' ,
276+ 'test' ,
277+ colors .red ,
278+ colors .yellow ,
279+ None ,
280+ None ,
281+ 1 ,
282+ '\x1b [48;5;11m\x1b [38;5;9mtest\x1b [39m\x1b [49m' ,
282283 ),
283284 ],
284285)
@@ -290,13 +291,39 @@ def test_apply_colors(text, fg, bg, fg_none, bg_none, percentage, expected,
290291 progressbar .env .ColorSupport .XTERM_256 ,
291292 )
292293 assert (
293- apply_colors (
294- text ,
295- fg = fg ,
296- bg = bg ,
297- fg_none = fg_none ,
298- bg_none = bg_none ,
299- percentage = percentage ,
300- )
301- == expected
294+ apply_colors (
295+ text ,
296+ fg = fg ,
297+ bg = bg ,
298+ fg_none = fg_none ,
299+ bg_none = bg_none ,
300+ percentage = percentage ,
301+ )
302+ == expected
302303 )
304+
305+
306+ def test_ansi_color (monkeypatch ):
307+ color = progressbar .terminal .Color (
308+ colors .red .rgb ,
309+ colors .red .hls ,
310+ 'red-ansi' ,
311+ None ,
312+ )
313+
314+ for color_support in {
315+ env .ColorSupport .NONE ,
316+ env .ColorSupport .XTERM ,
317+ env .ColorSupport .XTERM_256 ,
318+ env .ColorSupport .XTERM_TRUECOLOR ,
319+ }:
320+ monkeypatch .setattr (
321+ env ,
322+ 'COLOR_SUPPORT' ,
323+ color_support ,
324+ )
325+ assert color .ansi is not None or color_support == env .ColorSupport .NONE
326+
327+
328+ def test_sgr_call ():
329+ assert progressbar .terminal .encircled ('test' ) == '\x1b [52mtest\x1b [54m'
0 commit comments