Skip to content

Commit

Permalink
use color constants all over the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kvbik committed Nov 13, 2013
1 parent 937a82a commit e2c8417
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions test_ella/test_photos/test_resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

class TestPhotoResize(TestCase):

Expand All @@ -19,52 +22,51 @@ def setUp(self):
self.format = Format(max_height=100, max_width=100)

def test_custom_bg_color_is_used_for_neg_coords(self):
i = Image.new('RGB', (200, 200), "red")
i = Image.new('RGB', (200, 200), RED)
f = Formatter(i, self.format, crop_box=(-50, -50, 50, 50))

i, crop_box = f.format()
tools.assert_equals((-50, -50, 50, 50), crop_box)
tools.assert_equals((100, 100), i.size)
tools.assert_equals((0,0,255), i.getpixel((0, 0)))
tools.assert_equals((255,0,0), i.getpixel((51, 51)))
tools.assert_equals((255,0,0), i.getpixel((50, 50)))
tools.assert_equals((255,0,0), i.getpixel((99, 99)))

tools.assert_equals(BLUE, i.getpixel((0, 0)))
tools.assert_equals(RED, i.getpixel((51, 51)))
tools.assert_equals(RED, i.getpixel((50, 50)))
tools.assert_equals(RED, i.getpixel((99, 99)))

def test_taller_image_gets_cropped_to_ratio(self):
i = Image.new('RGB', (100, 200), "black")
i = Image.new('RGB', (100, 200), BLACK)
f = Formatter(i, self.format)

i, crop_box = f.format()
tools.assert_equals((0, 50, 100, 150), crop_box)
tools.assert_equals((100, 100), i.size)

def test_wider_image_gets_cropped_to_ratio(self):
i = Image.new('RGB', (200, 100), "black")
i = Image.new('RGB', (200, 100), BLACK)
f = Formatter(i, self.format)

i, crop_box = f.format()
tools.assert_equals((50, 0, 150, 100), crop_box)
tools.assert_equals((100, 100), i.size)

def test_bigger_image_gets_shrinked_without_cropping(self):
i = Image.new('RGB', (200, 200), "black")
i = Image.new('RGB', (200, 200), BLACK)
f = Formatter(i, self.format)

i, crop_box = f.format()
tools.assert_equals(None, crop_box)
tools.assert_equals((100, 100), i.size)

def test_smaller_image_remains_untouched(self):
i = Image.new('RGB', (100, 20), "black")
i = Image.new('RGB', (100, 20), BLACK)
f = Formatter(i, self.format)

i, crop_box = f.format()
tools.assert_equals(None, crop_box)
tools.assert_equals((100, 20), i.size)

def test_taller_image_gets_shrinked_to_ratio_with_nocrop(self):
i = Image.new('RGB', (100, 200), "black")
i = Image.new('RGB', (100, 200), BLACK)
self.format.nocrop = True
f = Formatter(i, self.format)

Expand All @@ -73,7 +75,7 @@ def test_taller_image_gets_shrinked_to_ratio_with_nocrop(self):
tools.assert_equals((50, 100), i.size)

def test_wider_image_gets_shrinked_to_ratio_with_nocrop(self):
i = Image.new('RGB', (200, 100), "black")
i = Image.new('RGB', (200, 100), BLACK)
self.format.nocrop = True
f = Formatter(i, self.format)

Expand All @@ -82,7 +84,7 @@ def test_wider_image_gets_shrinked_to_ratio_with_nocrop(self):
tools.assert_equals((100, 50), i.size)

def test_smaller_image_stretches_with_ratio_intact_with_stretch(self):
i = Image.new('RGB', (20, 10), "black")
i = Image.new('RGB', (20, 10), BLACK)
self.format.stretch = True
f = Formatter(i, self.format)

Expand All @@ -91,7 +93,7 @@ def test_smaller_image_stretches_with_ratio_intact_with_stretch(self):
tools.assert_equals((100, 50), i.size)

def test_flexible_height_doesnt_affect_wider_images(self):
i = Image.new('RGB', (200, 100), "black")
i = Image.new('RGB', (200, 100), BLACK)
self.format.flexible_max_height = 200
self.format.flexible_height = True
f = Formatter(i, self.format)
Expand All @@ -101,7 +103,7 @@ def test_flexible_height_doesnt_affect_wider_images(self):
tools.assert_equals((100, 100), i.size)

def test_flexible_height_doesnt_raise_exception_no_max_height(self):
i = Image.new('RGB', (200, 100), "black")
i = Image.new('RGB', (200, 100), BLACK)
self.format.flexible_max_height = None
self.format.flexible_height = True
f = Formatter(i, self.format)
Expand All @@ -110,7 +112,7 @@ def test_flexible_height_doesnt_raise_exception_no_max_height(self):
tools.assert_equals((100, 100), i.size)

def test_flexible_height_saves_taller_images(self):
i = Image.new('RGB', (100, 200), "black")
i = Image.new('RGB', (100, 200), BLACK)
self.format.flexible_max_height = 200
self.format.flexible_height = True
f = Formatter(i, self.format)
Expand All @@ -120,44 +122,44 @@ def test_flexible_height_saves_taller_images(self):
tools.assert_equals((100, 200), i.size)

def test_custom_crop_box_is_used(self):
i = Image.new('RGB', (200, 200), "red")
i = Image.new('RGB', (200, 200), RED)
f = Formatter(i, self.format, crop_box=(0,0,100,100))
i.putpixel((99, 99), 0)
i.putpixel((99, 99), BLACK)

i, crop_box = f.format()
tools.assert_equals((0,0,100,100), crop_box)
tools.assert_equals((100, 100), i.size)
tools.assert_equals((0,0,0), i.getpixel((99,99)))
tools.assert_equals(BLACK, i.getpixel((99,99)))

def test_important_box_is_used(self):
i = Image.new('RGB', (200, 100), "red")
i = Image.new('RGB', (200, 100), RED)
f = Formatter(i, self.format, important_box=(0,0,100,100))
i.putpixel((99, 99), 0)
i.putpixel((99, 99), BLACK)

i, crop_box = f.format()
tools.assert_equals((0,0,100,100), crop_box)
tools.assert_equals((100, 100), i.size)
tools.assert_equals((0,0,0), i.getpixel((99,99)))
tools.assert_equals(BLACK, i.getpixel((99,99)))

def test_important_box_is_used_for_other_positive_x_motion_as_well(self):
i = Image.new('RGB', (200, 100), "red")
i = Image.new('RGB', (200, 100), RED)
f = Formatter(i, self.format, important_box=(100,0,200,100))
i.putpixel((100, 0), 0)
i.putpixel((100, 0), BLACK)

i, crop_box = f.format()
tools.assert_equals((100,0,200,100), crop_box)
tools.assert_equals((100, 100), i.size)
tools.assert_equals((0,0,0), i.getpixel((0,0)))
tools.assert_equals(BLACK, i.getpixel((0,0)))

def test_important_box_is_used_for_positive_y_motion_as_well(self):
i = Image.new('RGB', (100, 200), "red")
i = Image.new('RGB', (100, 200), RED)
f = Formatter(i, self.format, important_box=(0,100,100,200))
i.putpixel((0, 100), 0)
i.putpixel((0, 100), BLACK)

i, crop_box = f.format()
tools.assert_equals((0,100,100,200), crop_box)
tools.assert_equals((100, 100), i.size)
tools.assert_equals((0,0,0), i.getpixel((0,0)))
tools.assert_equals(BLACK, i.getpixel((0,0)))

class TestPhotoResizeWithRotate(TestCase):

Expand Down

0 comments on commit e2c8417

Please sign in to comment.