Added test

This commit is contained in:
Ujjwal Verma 2017-06-25 01:05:20 +05:30
parent e81144e26b
commit 8ca29679df
3 changed files with 30 additions and 7 deletions

View File

@ -91,11 +91,12 @@ def parse_ico(data: bytes) -> Metadata:
for i, image in enumerate(img.images):
parts.append(
(
'Image {}'.format(i), "Size: {} x {}\n "
"Bits per pixel: {}\n "
"PNG: {}".format(256 if not image.width else image.width,
'Image {}'.format(i+1), "Size: {} x {}\n"
"{: >18}Bits per pixel: {}\n"
"{: >18}PNG: {}".format(256 if not image.width else image.width,
256 if not image.height else image.height,
image.bpp, image.is_png)
'', image.bpp,
'', image.is_png)
)
)

View File

@ -167,3 +167,26 @@ def test_parse_gif(filename, metadata):
def test_parse_jpeg(filename, metadata):
with open(tutils.test_data.path(filename), 'rb') as f:
assert metadata == image_parser.parse_jpeg(f.read())
@pytest.mark.parametrize("filename, metadata", {
"mitmproxy/data/image.ico": [
('Format', 'ICO'),
('Number of images', '3'),
('Image 1', "Size: {} x {}\n"
"{: >18}Bits per pixel: {}\n"
"{: >18}PNG: {}".format(48, 48, '', 24, '', False)
),
('Image 2', "Size: {} x {}\n"
"{: >18}Bits per pixel: {}\n"
"{: >18}PNG: {}".format(32, 32, '', 24, '', False)
),
('Image 3', "Size: {} x {}\n"
"{: >18}Bits per pixel: {}\n"
"{: >18}PNG: {}".format(16, 16, '', 24, '', False)
)
]
}.items())
def test_ico(filename, metadata):
with open(tutils.test_data.path(filename), 'rb') as f:
assert metadata == image_parser.parse_ico(f.read())

View File

@ -9,8 +9,7 @@ def test_view_image():
"mitmproxy/data/image.png",
"mitmproxy/data/image.gif",
"mitmproxy/data/all.jpeg",
# https://bugs.python.org/issue21574
# "mitmproxy/data/image.ico",
"mitmproxy/data/image.ico",
]:
with open(tutils.test_data.path(img), "rb") as f:
viewname, lines = v(f.read())