This commit is contained in:
Arushit Mudgal 2018-01-25 20:36:19 +05:30 committed by Maximilian Hils
parent 6dd336fcec
commit f41d521ce5
2 changed files with 20 additions and 3 deletions

View File

@ -49,8 +49,9 @@ def format_dict(
]
entries, where key is padded to a uniform width.
"""
max_key_len = max(len(k) for k in d.keys())
max_key_len = min(max_key_len, KEY_MAX)
max_key_len = max((len(k) for k in d.keys()), default=0)
max_key_len = min((max_key_len, KEY_MAX), default=0)
for key, value in d.items():
if isinstance(key, bytes):
key += b":"

View File

@ -1 +1,17 @@
# TODO: write tests
import pytest
from mitmproxy.contentviews import base
def test_format_dict():
d = {"one": "two", "three": "four"}
f_d = base.format_dict(d)
assert next(f_d)
d = {"adsfa": ""}
f_d = base.format_dict(d)
assert next(f_d)
d = {}
f_d = base.format_dict(d)
with pytest.raises(StopIteration):
next(f_d)