From a880d2aa587b9405045a94f723e51c6fb18efd4f Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sat, 1 Feb 2020 14:33:54 +0200 Subject: Test for unknown colors as well --- tests/test_parse.py | 3 +++ viewstate/parse.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_parse.py b/tests/test_parse.py index f5a0828..c1e1abb 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -45,6 +45,9 @@ class TestParse(object): vs = ViewState(raw=b"\xff\x01\n\x8d\x01") assert vs.decode() == "Color: Red" + vs = ViewState(raw=b"\xff\x01\n\xff") + assert vs.decode() == "Color: Unknown" + def test_rgba(self): vs = ViewState(raw=b"\xff\x01\x09\x10\x20\x30\x40") assert vs.decode() == "RGBA(16,32,48,64)" diff --git a/viewstate/parse.py b/viewstate/parse.py index 910b21b..b2a85f0 100644 --- a/viewstate/parse.py +++ b/viewstate/parse.py @@ -122,10 +122,10 @@ class Color(Parser): @staticmethod def parse(b): try: - color = "Color: {}".format(COLORS[b[0]]) + color = COLORS[b[0]] except IndexError: color = "Unknown" - return color, b[1:] + return "Color: {}".format(color), b[1:] class Pair(Parser): -- cgit v1.3.1