From 41555edab98034fcc669ef90f25753533ab93327 Mon Sep 17 00:00:00 2001 From: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:08:27 +0530 Subject: [PATCH] Reformatted list (#5919) * Reformatted list * [autofix.ci] apply automated fixes * Reformatted list * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- mitmproxy/contentviews/msgpack.py | 6 ++--- test/mitmproxy/contentviews/test_msgpack.py | 30 +++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/mitmproxy/contentviews/msgpack.py b/mitmproxy/contentviews/msgpack.py index 92aeb8b39..8de6c9abb 100644 --- a/mitmproxy/contentviews/msgpack.py +++ b/mitmproxy/contentviews/msgpack.py @@ -64,11 +64,11 @@ def format_msgpack( elif type(data) is list: output[-1] += [("text", "[")] - for item in data: + + for count, item in enumerate(data): output.append([indent, ("text", " ")]) format_msgpack(item, output, indent_count + 1) - - if item != data[-1]: + if count != len(data) - 1: output[-1] += [("text", ",")] output.append([indent, ("text", "]")]) diff --git a/test/mitmproxy/contentviews/test_msgpack.py b/test/mitmproxy/contentviews/test_msgpack.py index 65c8487f0..d3c53d3a9 100644 --- a/test/mitmproxy/contentviews/test_msgpack.py +++ b/test/mitmproxy/contentviews/test_msgpack.py @@ -57,7 +57,9 @@ def test_format_msgpack(): [("text", ""), ("text", "}")], ] - assert list(msgpack.format_msgpack({"object": {"key": "value"}, "list": [1]})) == [ + assert list( + msgpack.format_msgpack({"object": {"key": "value"}, "list": [0, 0, 1, 0, 0]}) + ) == [ [("text", "{")], [ ("text", ""), @@ -81,7 +83,31 @@ def test_format_msgpack(): ("text", ": "), ("text", "["), ], - [("text", " "), ("text", " "), ("Token_Literal_Number", "1")], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "1"), + ("text", ","), + ], + [ + ("text", " "), + ("text", " "), + ("Token_Literal_Number", "0"), + ("text", ","), + ], + [("text", " "), ("text", " "), ("Token_Literal_Number", "0")], [("text", " "), ("text", "]")], [("text", ""), ("text", "}")], ]