Parse pytest color output correctly.

This commit is contained in:
Andrew Hamilton 2020-10-12 22:26:29 +10:00
parent b5f712165b
commit ad6a093b92

View file

@ -162,7 +162,7 @@ class TermStr(collections.UserString):
codes = part[1:end_index].split(";") codes = part[1:end_index].split(";")
previous_code = None previous_code = None
for index, code in enumerate(codes): for index, code in enumerate(codes):
if code in ["", "0"]: # Normal if code in ["", "0", "00"]: # Normal
is_bold, is_italic, is_underlined = False, False, False is_bold, is_italic, is_underlined = False, False, False
fg_color, bg_color = None, None fg_color, bg_color = None, None
elif code in ["01", "1"]: # bold elif code in ["01", "1"]: # bold
@ -171,13 +171,13 @@ class TermStr(collections.UserString):
is_italic = True is_italic = True
elif code in ["04", "4"]: # underline elif code in ["04", "4"]: # underline
is_underlined = True is_underlined = True
elif len(code) == 2 and code.startswith("3"): # dim fg color elif 30 <= int(code) <= 37 : # dim fg color
fg_color = int(code[1]) fg_color = int(code[1])
elif len(code) == 2 and code.startswith("4"): # dim bg color elif 40 <= int(code) <= 47: # dim bg color
bg_color = int(code[1]) bg_color = int(code[1])
elif len(code) == 2 and code.startswith("9"): # high fg color elif 90 <= int(code) <= 97: # high fg color
fg_color = int(code[1]) + 8 fg_color = int(code[1]) + 8
elif len(code) == 3 and code.startswith("10"): # high bg color elif 100 <= int(code) <= 107: # high bg color
bg_color = int(code[2]) + 8 bg_color = int(code[2]) + 8
elif code == "5" and previous_code == "38": # simple fg color elif code == "5" and previous_code == "38": # simple fg color
fg_color = int(codes[index+1]) fg_color = int(codes[index+1])