From 674fd9744df001de0bd3a978a211ed424dd78f57 Mon Sep 17 00:00:00 2001 From: hugovk Date: Tue, 26 Aug 2014 11:45:28 +0300 Subject: [PATCH] Tests for GimpGradientFile and a sample .ggr by me --- Tests/images/gimp_gradient.ggr | 6 ++ Tests/test_file_gimpgradient.py | 103 ++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 Tests/images/gimp_gradient.ggr create mode 100644 Tests/test_file_gimpgradient.py diff --git a/Tests/images/gimp_gradient.ggr b/Tests/images/gimp_gradient.ggr new file mode 100644 index 000000000..4644e5537 --- /dev/null +++ b/Tests/images/gimp_gradient.ggr @@ -0,0 +1,6 @@ +GIMP Gradient +4 +0.000000 0.351923 0.534893 1.000000 1.000000 1.000000 0.910000 0.730303 0.510606 1.000000 0.480000 1 0 +0.501504 0.611002 0.637730 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 1.000000 1 0 +0.931891 0.951264 1.000000 0.531255 0.316078 1.031173 1.000000 0.000000 0.000000 0.000000 1.000000 0 0 +0.810551 0.881217 0.921883 0.717576 0.441331 0.081217 1.000000 0.751576 0.410331 0.081217 1.000000 0 0 \ No newline at end of file diff --git a/Tests/test_file_gimpgradient.py b/Tests/test_file_gimpgradient.py new file mode 100644 index 000000000..e024c0903 --- /dev/null +++ b/Tests/test_file_gimpgradient.py @@ -0,0 +1,103 @@ +from helper import unittest, PillowTestCase + +from PIL import GimpGradientFile + +TEST_FILE = "Tests/images/gimp_gradient.ggr" + + +class TestImage(PillowTestCase): + + def test_linear_pos_le_middle(self): + # Arrange + middle = 0.5 + pos = 0.25 + + # Act + ret = GimpGradientFile.linear(middle, pos) + + # Assert + self.assertEqual(ret, 0.25) + + def test_linear_pos_le_small_middle(self): + # Arrange + middle = 1e-11 + pos = 1e-12 + + # Act + ret = GimpGradientFile.linear(middle, pos) + + # Assert + self.assertEqual(ret, 0.0) + + def test_linear_pos_gt_middle(self): + # Arrange + middle = 0.5 + pos = 0.75 + + # Act + ret = GimpGradientFile.linear(middle, pos) + + # Assert + self.assertEqual(ret, 0.75) + + def test_linear_pos_gt_small_middle(self): + # Arrange + middle = 1 - 1e-11 + pos = 1 - 1e-12 + + # Act + ret = GimpGradientFile.linear(middle, pos) + + # Assert + self.assertEqual(ret, 1.0) + + def test_curved(self): + # Arrange + middle = 0.5 + pos = 0.75 + + # Act + ret = GimpGradientFile.curved(middle, pos) + + # Assert + self.assertEqual(ret, 0.75) + + def test_sphere_increasing(self): + # Arrange + middle = 0.5 + pos = 0.75 + + # Act + ret = GimpGradientFile.sphere_increasing(middle, pos) + + # Assert + self.assertEqual(ret, 0.9682458365518543) + + def test_sphere_decreasing(self): + # Arrange + middle = 0.5 + pos = 0.75 + + # Act + ret = GimpGradientFile.sphere_decreasing(middle, pos) + + # Assert + self.assertEqual(ret, 0.3385621722338523) + + def test_load_via_imagepalette(self): + # Arrange + from PIL import ImagePalette + + # Act + palette = ImagePalette.load(TEST_FILE) + + # Assert + # load returns raw palette information + self.assertEqual(len(palette[0]), 1024) + self.assertEqual(palette[1], "RGBA") + + +if __name__ == '__main__': + unittest.main() + +# End of file