aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2017-02-03 18:58:34 +0100
committerGitHub <noreply@github.com>2017-02-03 18:58:34 +0100
commit53f298ac41ff812ca69a8220862746f55c1505b8 (patch)
tree929f23b75ffbc5b1e76171beafc36efc7bd842a5 /test
parentbbdb7300fd7a513f13a3ed52124265798e646c91 (diff)
parent15548ff433d4283d4e46906decde5baa406b6584 (diff)
downloadmitmproxy-53f298ac41ff812ca69a8220862746f55c1505b8.tar.gz
mitmproxy-53f298ac41ff812ca69a8220862746f55c1505b8.tar.bz2
mitmproxy-53f298ac41ff812ca69a8220862746f55c1505b8.zip
Merge pull request #1967 from s4chin/remove-pillow
Add png parser
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/contentviews/test_image_parser.py76
-rw-r--r--test/mitmproxy/data/png_parser/aspect.pngbin0 -> 1230326 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ct0n0g04.pngbin0 -> 273 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ct1n0g04.pngbin0 -> 792 bytes
-rw-r--r--test/mitmproxy/data/png_parser/cten0g04.pngbin0 -> 742 bytes
-rw-r--r--test/mitmproxy/data/png_parser/ctzn0g04.pngbin0 -> 753 bytes
-rw-r--r--test/mitmproxy/data/png_parser/g07n0g16.pngbin0 -> 321 bytes
7 files changed, 76 insertions, 0 deletions
diff --git a/test/mitmproxy/contentviews/test_image_parser.py b/test/mitmproxy/contentviews/test_image_parser.py
new file mode 100644
index 00000000..62a07f56
--- /dev/null
+++ b/test/mitmproxy/contentviews/test_image_parser.py
@@ -0,0 +1,76 @@
+import pytest
+
+from mitmproxy.contentviews.image import image_parser
+from mitmproxy.test import tutils
+
+
+@pytest.mark.parametrize("filename, metadata", {
+ # no textual data
+ "mitmproxy/data/png_parser/ct0n0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0')
+ ],
+ # with textual data
+ "mitmproxy/data/png_parser/ct1n0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('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\n'
+ 'various 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.')
+ ],
+ # with compressed textual data
+ "mitmproxy/data/png_parser/ctzn0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('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\n'
+ 'various 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.')
+ ],
+ # UTF-8 international text - english
+ "mitmproxy/data/png_parser/cten0g04.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '1.0'),
+ ('Title', 'PngSuite'),
+ ('Author', 'Willem van Schaik (willem@schaik.com)'),
+ ('Copyright', 'Copyright Willem van Schaik, Canada 2011'),
+ ('Description', 'A compilation of a set of images created to test the '
+ 'various color-types of the PNG format. Included are black&white, color,'
+ ' paletted, with alpha channel, with transparency formats. All bit-depths'
+ ' allowed according to the spec are present.'),
+ ('Software', 'Created on a NeXTstation color using "pnmtopng".'),
+ ('Disclaimer', 'Freeware.')
+ ],
+ # check gamma value
+ "mitmproxy/data/png_parser/g07n0g16.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '32 x 32 px'),
+ ('gamma', '0.7')
+ ],
+ # check aspect value
+ "mitmproxy/data/png_parser/aspect.png": [
+ ('Format', 'Portable network graphics'),
+ ('Size', '1280 x 798 px'),
+ ('aspect', '72 x 72'),
+ ('date:create', '2012-07-11T14:04:52-07:00'),
+ ('date:modify', '2012-07-11T14:04:52-07:00')
+ ],
+}.items())
+def test_parse_png(filename, metadata):
+ with open(tutils.test_data.path(filename), "rb") as f:
+ assert metadata == image_parser.parse_png(f.read())
diff --git a/test/mitmproxy/data/png_parser/aspect.png b/test/mitmproxy/data/png_parser/aspect.png
new file mode 100644
index 00000000..17c01913
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/aspect.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ct0n0g04.png b/test/mitmproxy/data/png_parser/ct0n0g04.png
new file mode 100644
index 00000000..40d1e062
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ct0n0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ct1n0g04.png b/test/mitmproxy/data/png_parser/ct1n0g04.png
new file mode 100644
index 00000000..3ba110aa
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ct1n0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/cten0g04.png b/test/mitmproxy/data/png_parser/cten0g04.png
new file mode 100644
index 00000000..a6a56faf
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/cten0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/ctzn0g04.png b/test/mitmproxy/data/png_parser/ctzn0g04.png
new file mode 100644
index 00000000..b4401c9c
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/ctzn0g04.png
Binary files differ
diff --git a/test/mitmproxy/data/png_parser/g07n0g16.png b/test/mitmproxy/data/png_parser/g07n0g16.png
new file mode 100644
index 00000000..d6a47c2d
--- /dev/null
+++ b/test/mitmproxy/data/png_parser/g07n0g16.png
Binary files differ