test_thumbnails.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from thumbnailer import _resizer
  2. from unittest import TestCase, main
  3. import os.path as path
  4. from PIL import Image, ImageChops
  5. class ThumbnailerTests(TestCase):
  6. def path(self, filename):
  7. return path.join(self.img_path, filename)
  8. def setUp(self):
  9. self.img_path = path.join(path.dirname(__file__), "test_data")
  10. self.img = Image.open(self.path("sample_image.jpg"))
  11. def testSquare(self):
  12. r = _resizer('square', '100')
  13. output = r.resize(self.img)
  14. self.assertEqual((100, 100), output.size)
  15. def testExact(self):
  16. r = _resizer('exact', '250x100')
  17. output = r.resize(self.img)
  18. self.assertEqual((250, 100), output.size)
  19. def testWidth(self):
  20. r = _resizer('aspect', '250x?')
  21. output = r.resize(self.img)
  22. self.assertEqual((250, 166), output.size)
  23. def testHeight(self):
  24. r = _resizer('aspect', '?x250')
  25. output = r.resize(self.img)
  26. self.assertEqual((375, 250), output.size)
  27. if __name__=="__main__":
  28. main()