From adda419ad6abdc90d263c70e7a5a6d9722f1a3bb Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 4 Mar 2017 13:04:50 +0200 Subject: [PATCH 1/5] From http://www.globalmarinenet.com/free-grib-file-downloads/ --- Tests/images/WAlaska.wind.7days.grb | Bin 0 -> 9274 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tests/images/WAlaska.wind.7days.grb diff --git a/Tests/images/WAlaska.wind.7days.grb b/Tests/images/WAlaska.wind.7days.grb new file mode 100644 index 0000000000000000000000000000000000000000..37f9fd9b50b4856d8036e1527bb89bead80a147b GIT binary patch literal 9274 zcmcK9c{G&m|G@FflFSSu+a$@(h-`x)Nen}l>^s@QSi)G6WQi<^hwMv{C0n+lP>L)i zm7Nk5;j#9$6m8GrH|BfJ@9ulfocuF0fB3_hbG*;X=f3Xix^J9`t_A=#Gyw3@?zP%( z6QBV!Y;^Ph&@h0V4<`V$0Purt0N4NvSahU)!XHUrmDJ;vrVsZ(p ztt2B#=~^}7RCMs90JuM2lL{uM3n95boX+FaP#EmTvAW}063n?#l##11aWnG-(}KNIrJnJ7eXr(@u29a9 z8wZOc*FFbYOq{lnFpq5I;v2x*MMZu-cNVH8=St~XlIy`j0FR$v65ML{S%fQvz0>mN zJ@!|I{gdb!T{y!9&NeV^X7e{^9s+LKj<&GvR#3ZG(o^|h7gr=TT;2LBWJ` zV{{2|_ZSMs-uWir>YY?zB3>%UL~|>Rb$lO-Sl?2BlBmeO+WY55?IqbSO3!}(vn!=* zNv?+?0oOifX|+6IGkIcYxqm#yT5Hf^{b z`LiclB;kVfSXvAgjD9#v?(JE2xqCf(QxAJs?D?}RrE5v9{KWOu;(+MNbX4Ki z!W+MXikEy0_YR?Wjm#RRM72#=joOdzODkMtVJS(K($$vnM`>vC)9l~HRe~C>UVYm{ zS37$)=h0w}hqA%_o{G=k{`A(0Vw7;hZb{7D<35caRQ1@S)F3WCXt6$tH&YvV@g`cn z^1kw)T`65lauxgt;6Y9v-I%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qLFk~W&7&austwd;n>*e$=-5r z=~(tIoo9k)B}*Y!=>7`1Qo43$Z>`D74`2_cRjBsZx=)DRUXo~{9HVIt=cIxO{tnXw)!y2(;)HZ~O_ zsl5V(IBqw_Vg41pa;JyaIZ(FSaY|U{hL_MV{Tj-q{TetJVp&!Avd}xmVOMxN=}~3Iaah>>c^_T`NqqlG4oWHBXoP`bjGNKaL~N AMF0Q* literal 0 HcmV?d00001 From 0abfa08ff74c075f05b19a491e01106dd1815fb4 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 4 Mar 2017 13:07:48 +0200 Subject: [PATCH 2/5] Test GribStubImagePlugin for correctness --- Tests/test_file_gribstub.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index 79025d3b4..ea43d13c0 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -1,23 +1,47 @@ from helper import unittest, PillowTestCase, hopper -from PIL import GribStubImagePlugin +from PIL import GribStubImagePlugin, Image + +TEST_FILE = "Tests/images/WAlaska.wind.7days.grb" class TestFileGribStub(PillowTestCase): + def test_open(self): + # Act + im = Image.open(TEST_FILE) + + # Assert + self.assertEqual(im.format, "GRIB") + + # Dummy data from the stub + self.assertEqual(im.mode, "F") + self.assertEqual(im.size, (1, 1)) + def test_invalid_file(self): + # Arrange invalid_file = "Tests/images/flower.jpg" + # Act / Assert self.assertRaises(SyntaxError, lambda: GribStubImagePlugin.GribStubImageFile(invalid_file)) def test_save(self): + # Arrange im = hopper() - tmpfile = self.tempfile("temp.grib") + + # Act / Assert: stub cannot save without an implemented handler self.assertRaises(IOError, lambda: im.save(tmpfile)) + def test_load(self): + # Arrange + im = Image.open(TEST_FILE) + + # Act / Assert: stub cannot load without an implemented handler + self.assertRaises(IOError, lambda: im.load()) + if __name__ == '__main__': unittest.main() From 4ece1ae78af94456ad01a6e19ec752b634f0a3c4 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 4 Mar 2017 13:52:14 +0200 Subject: [PATCH 3/5] Python 3 fix --- PIL/GribStubImagePlugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PIL/GribStubImagePlugin.py b/PIL/GribStubImagePlugin.py index 1fbfe61dc..33c8291ea 100644 --- a/PIL/GribStubImagePlugin.py +++ b/PIL/GribStubImagePlugin.py @@ -10,6 +10,7 @@ # from . import Image, ImageFile +from ._binary import i8 _handler = None @@ -28,7 +29,7 @@ def register_handler(handler): # Image adapter def _accept(prefix): - return prefix[0:4] == b"GRIB" and prefix[7] == b'\x01' + return prefix[0:4] == b"GRIB" and i8(prefix[7]) == 1 class GribStubImageFile(ImageFile.StubImageFile): From 5d2e4f48dd4783f4ed02bd22addf6db5f7d33fc7 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 4 Mar 2017 16:10:52 +0200 Subject: [PATCH 4/5] Reorder tests to match others --- Tests/test_file_gribstub.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index ea43d13c0..80e141503 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -27,6 +27,13 @@ class TestFileGribStub(PillowTestCase): lambda: GribStubImagePlugin.GribStubImageFile(invalid_file)) + def test_load(self): + # Arrange + im = Image.open(TEST_FILE) + + # Act / Assert: stub cannot load without an implemented handler + self.assertRaises(IOError, lambda: im.load()) + def test_save(self): # Arrange im = hopper() @@ -35,13 +42,6 @@ class TestFileGribStub(PillowTestCase): # Act / Assert: stub cannot save without an implemented handler self.assertRaises(IOError, lambda: im.save(tmpfile)) - def test_load(self): - # Arrange - im = Image.open(TEST_FILE) - - # Act / Assert: stub cannot load without an implemented handler - self.assertRaises(IOError, lambda: im.load()) - if __name__ == '__main__': unittest.main() From 052905bf5cfefd4e53508907a3c7aa7e1099536e Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 4 Mar 2017 23:19:41 +0200 Subject: [PATCH 5/5] Remove unnecessary lambda --- Tests/test_file_gribstub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_gribstub.py b/Tests/test_file_gribstub.py index 80e141503..dc0fa22d7 100644 --- a/Tests/test_file_gribstub.py +++ b/Tests/test_file_gribstub.py @@ -32,7 +32,7 @@ class TestFileGribStub(PillowTestCase): im = Image.open(TEST_FILE) # Act / Assert: stub cannot load without an implemented handler - self.assertRaises(IOError, lambda: im.load()) + self.assertRaises(IOError, im.load) def test_save(self): # Arrange