X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=plugins%2Fthumbnailer%2Ftest_thumbnails.py;fp=plugins%2Fthumbnailer%2Ftest_thumbnails.py;h=090036e1197532c38034ae8a43378c46de922b0d;hb=5b6e1f86d097cb362496af487d616420d233d8b3;hp=0000000000000000000000000000000000000000;hpb=f1d23291e10b9cde47c452b8e848688d28e0d4e9;p=markerbeacon.git diff --git a/plugins/thumbnailer/test_thumbnails.py b/plugins/thumbnailer/test_thumbnails.py new file mode 100644 index 0000000..090036e --- /dev/null +++ b/plugins/thumbnailer/test_thumbnails.py @@ -0,0 +1,61 @@ +from thumbnailer import Resizer +from unittest import TestCase, main +import os +from PIL import Image + +class ThumbnailerTests(TestCase): + + def path(self, filename): + return os.path.join(self.img_path, filename) + + def setUp(self): + self.img_path = os.path.join(os.path.dirname(__file__), "test_data") + self.img = Image.open(self.path("sample_image.jpg")) + + def testSquare(self): + r = Resizer('square', '100', self.img_path) + output = r.resize(self.img) + self.assertEqual((100, 100), output.size) + + def testExact(self): + r = Resizer('exact', '250x100', self.img_path) + output = r.resize(self.img) + self.assertEqual((250, 100), output.size) + + def testWidth(self): + r = Resizer('aspect', '250x?', self.img_path) + output = r.resize(self.img) + self.assertEqual((250, 166), output.size) + + def testHeight(self): + r = Resizer('aspect', '?x250', self.img_path) + output = r.resize(self.img) + self.assertEqual((376, 250), output.size) + +class ThumbnailerFilenameTest(TestCase): + + def path(self, *parts): + return os.path.join(self.img_path, *parts) + + def setUp(self): + self.img_path = os.path.join(os.path.dirname(__file__), "test_data") + + def testRoot(self): + """Test a file that is in the root of img_path.""" + r = Resizer('square', '100', self.img_path) + new_name = r.get_thumbnail_name(self.path('sample_image.jpg')) + self.assertEqual('sample_image_square.jpg', new_name) + + def testRootWithSlash(self): + r = Resizer('square', '100', self.img_path + '/') + new_name = r.get_thumbnail_name(self.path('sample_image.jpg')) + self.assertEqual('sample_image_square.jpg', new_name) + + def testSubdir(self): + """Test a file that is in a sub-directory of img_path.""" + r = Resizer('square', '100', self.img_path) + new_name = r.get_thumbnail_name(self.path('subdir', 'sample_image.jpg')) + self.assertEqual('subdir/sample_image_square.jpg', new_name) + +if __name__=="__main__": + main()