def test_adjust__width(self): im = Image.open(self._data_path('100x100.png')) crop = Crop(width=50) adjusted = crop.adjust(im) self.assertEqual(adjusted.size, (50, 100)) expected = Image.open(self._data_path('50x100_crop.png')) self.assertImageEqual(adjusted, expected)
def test_adjust__height(self): im = Image.open(self._data_path('100x100.png')) crop = Crop(height=50) adjusted = crop.adjust(im) self.assertEqual(adjusted.size, (100, 50)) expected = Image.open(self._data_path('100x50_crop.png')) self.assertImageEqual(adjusted, expected)
def test_adjust__area(self): im = Image.open(self._data_path('100x100.png')) crop = Crop(width=50, height=50) areas = [Area(x1=21, y1=46, x2=70, y2=95)] adjusted = crop.adjust(im, areas=areas) self.assertEqual(adjusted.size, (50, 50)) expected = Image.open(self._data_path('50x50_crop_area.png')) self.assertImageEqual(adjusted, expected)
def test_preprepped(self): image = self.create_image('100x100.png') crop = Crop(width=50, height=50) helper = AdjustmentHelper([image], generate=True).adjust(crop) with self.assertNumQueries(4): adjusted = helper[0][1] with self.assertNumQueries(1): info_dict = AdjustmentHelper([image], generate=False).adjust(crop)[0][1] self.assertEqual(info_dict['url'], adjusted['url'])
def test_info_dicts__non_bulk(self): images = [ self.create_image('100x100.png'), self.create_image('100x100.png'), self.create_image('100x50_crop.png'), self.create_image('50x100_crop.png'), ] adj = Crop(width=50, height=50) with self.assertNumQueries(4): for image in images: helper = AdjustmentHelper([image], generate=False) helper.adjust(adj) helper._finalize()
def test_prepped(self): image = self.create_image('100x100.png') crop = Crop(width=50, height=50) with self.assertNumQueries(1): helper = AdjustmentHelper([image], generate=False) helper.adjust(crop) info_dict = helper[0][1] with self.assertNumQueries(4): AdjustmentHelper([image], generate=True).adjust(crop)._finalize() with self.assertNumQueries(1): response = self.client.get(info_dict['url']) self.assertEqual(response.status_code, 302)
def test_info_dicts__prepped(self): images = [ self.create_image('100x100.png'), self.create_image('100x100.png'), self.create_image('100x50_crop.png'), self.create_image('50x100_crop.png'), ] iterable = [BulkTestObject(image) for image in images] adj = Crop(width=50, height=50) helper = AdjustmentHelper(iterable, lookup='storage_path', generate=True) helper.adjust(adj) helper._finalize() helper = AdjustmentHelper(iterable, lookup='storage_path', generate=False) helper.adjust(adj) with self.assertNumQueries(1): helper._finalize()
def test_calculate__height(self): crop = Crop(height=50) self.assertEqual(crop.calculate((100, 100)), (100, 50))
def test_calculate__width(self): crop = Crop(width=50) self.assertEqual(crop.calculate((100, 100)), (50, 100))
def test_serialize(self): adjustments = [Fit(width=25, height=50), Crop(width=25)] requested = AdjustmentHelper._serialize_requested(adjustments) self.assertEqual(requested, 'fit|25|50>crop|25|')