diff options
author | Sachin Kelkar <sachinkel19@gmail.com> | 2017-02-02 16:30:01 +0530 |
---|---|---|
committer | Sachin Kelkar <sachinkel19@gmail.com> | 2017-02-03 14:12:54 +0530 |
commit | abef020e07bcb6b0fd6493f73fbb48c8275f502e (patch) | |
tree | 02c691016bcca9f4da587337cafd9a152b1d29df /test | |
parent | 6202958048dd73af55b55e879317d583851fc2e3 (diff) | |
download | mitmproxy-abef020e07bcb6b0fd6493f73fbb48c8275f502e.tar.gz mitmproxy-abef020e07bcb6b0fd6493f73fbb48c8275f502e.tar.bz2 mitmproxy-abef020e07bcb6b0fd6493f73fbb48c8275f502e.zip |
Fix as per feedback and add more tests
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/contentviews/test_image.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/contentviews/test_image_parser.py | 60 | ||||
-rw-r--r-- | test/mitmproxy/data/png_parser/aspect.png | bin | 0 -> 1230326 bytes | |||
-rw-r--r-- | test/mitmproxy/data/png_parser/ct0n0g04.png | bin | 0 -> 273 bytes | |||
-rw-r--r-- | test/mitmproxy/data/png_parser/ct1n0g04.png | bin | 0 -> 792 bytes | |||
-rw-r--r-- | test/mitmproxy/data/png_parser/cten0g04.png | bin | 0 -> 742 bytes | |||
-rw-r--r-- | test/mitmproxy/data/png_parser/g07n0g16.png | bin | 0 -> 321 bytes |
7 files changed, 53 insertions, 11 deletions
diff --git a/test/mitmproxy/contentviews/test_image.py b/test/mitmproxy/contentviews/test_image.py index 000b9da5..9e7e28f5 100644 --- a/test/mitmproxy/contentviews/test_image.py +++ b/test/mitmproxy/contentviews/test_image.py @@ -1,10 +1,10 @@ -from mitmproxy.contentviews.image import pillow +from mitmproxy.contentviews import image from mitmproxy.test import tutils from . import full_eval def test_view_image(): - v = full_eval(pillow.ViewImage()) + v = full_eval(image.ViewImage()) for img in [ "mitmproxy/data/image.png", "mitmproxy/data/image.gif", diff --git a/test/mitmproxy/contentviews/test_image_parser.py b/test/mitmproxy/contentviews/test_image_parser.py index d4116392..2544e3f1 100644 --- a/test/mitmproxy/contentviews/test_image_parser.py +++ b/test/mitmproxy/contentviews/test_image_parser.py @@ -3,12 +3,54 @@ import io from mitmproxy.contentviews.image import image_parser from mitmproxy.test import tutils -def test_png_parser(): - img = "mitmproxy/data/image.png" - with open(tutils.test_data.path(img), "rb") as f: - fmt, parts = image_parser.get_png(io.BytesIO(f.read())) - assert fmt == "PNG" - assert parts - assert parts["width"] == 174 - assert parts["height"] == 174 - assert parts["format"] == "Portable network graphics" +class TestPngParser: + def test_png_parser(self): + img = "mitmproxy/data/image.png" + with open(tutils.test_data.path(img), "rb") as f: + parts = image_parser.parse_png(io.BytesIO(f.read())) + assert parts + assert tuple(['Size', '174 x 174 px']) in parts + assert tuple(["Format", "Portable network graphics"]) in parts + + def test_textual_data(self): + img = "mitmproxy/data/png_parser/ct1n0g04.png" + with open(tutils.test_data.path(img), "rb") as f: + parts = image_parser.parse_png(io.BytesIO(f.read())) + assert parts + expected = [ + ('Title', 'PngSuite'), + ('Author', 'Willem A.J. van Schaik\n(willem@schaik.com)'), + ('Copyright', 'Copyright Willem van Schaik, Singapore 1995-96'), + ('Description', 'A compilation of a set of images created to test the\nvarious color-types of the PNG format. Included are\nblack&white, color, paletted, with alpha channel, with\ntransparency formats. All bit-depths allowed according\nto the spec are present.'), + ('Software', 'Created on a NeXTstation color using "pnmtopng".'), + ('Disclaimer', 'Freeware.') + ] + for data in expected: + assert data in parts + + def test_no_textual_data(self): + img = "mitmproxy/data/png_parser/ct0n0g04.png" + with open(tutils.test_data.path(img), "rb") as f: + parts = image_parser.parse_png(io.BytesIO(f.read())) + assert parts + metadata = [ + ('Format', 'Portable network graphics'), + ('Size', '32 x 32 px'), + ('gamma', '1.0') + ] + parts = [data for data in parts if data not in metadata] + assert not parts + + def test_gamma(self): + img = "mitmproxy/data/png_parser/g07n0g16.png" + with open(tutils.test_data.path(img), "rb") as f: + parts = image_parser.parse_png(io.BytesIO(f.read())) + assert parts + assert ('gamma', '0.7') in parts + + def test_gamma(self): + img = "mitmproxy/data/png_parser/aspect.png" + with open(tutils.test_data.path(img), "rb") as f: + parts = image_parser.parse_png(io.BytesIO(f.read())) + assert parts + assert ('aspect', '72 x 72') in parts diff --git a/test/mitmproxy/data/png_parser/aspect.png b/test/mitmproxy/data/png_parser/aspect.png Binary files differnew file mode 100644 index 00000000..17c01913 --- /dev/null +++ b/test/mitmproxy/data/png_parser/aspect.png diff --git a/test/mitmproxy/data/png_parser/ct0n0g04.png b/test/mitmproxy/data/png_parser/ct0n0g04.png Binary files differnew file mode 100644 index 00000000..40d1e062 --- /dev/null +++ b/test/mitmproxy/data/png_parser/ct0n0g04.png diff --git a/test/mitmproxy/data/png_parser/ct1n0g04.png b/test/mitmproxy/data/png_parser/ct1n0g04.png Binary files differnew file mode 100644 index 00000000..3ba110aa --- /dev/null +++ b/test/mitmproxy/data/png_parser/ct1n0g04.png diff --git a/test/mitmproxy/data/png_parser/cten0g04.png b/test/mitmproxy/data/png_parser/cten0g04.png Binary files differnew file mode 100644 index 00000000..a6a56faf --- /dev/null +++ b/test/mitmproxy/data/png_parser/cten0g04.png diff --git a/test/mitmproxy/data/png_parser/g07n0g16.png b/test/mitmproxy/data/png_parser/g07n0g16.png Binary files differnew file mode 100644 index 00000000..d6a47c2d --- /dev/null +++ b/test/mitmproxy/data/png_parser/g07n0g16.png |