def test_autorotate_image(): path = '/tmp/foo.jpg' with mock.patch('spreadsplug.autorotate.JPEGImage') as mockcls: img = mock.Mock() mockcls.return_value = img img.exif_orientation = 1 autorotate.autorotate_image(path) assert img.exif_autotransform.call_count == 0 img.exif_orientation = None autorotate.autorotate_image(path) assert img.exif_autotransform.call_count == 0 img.exif_orientation = 6 autorotate.autorotate_image(path) assert img.exif_autotransform.call_count == 1
def test_autorotate_image(tmpdir): in_path = tmpdir.join('foo.jpg') out_path = tmpdir.join('foo_rotated.jpg') shutil.copyfile('./tests/data/odd.jpg', unicode(in_path)) with mock.patch('spreadsplug.autorotate.JPEGImage') as mockcls: img = mock.Mock() mockcls.return_value = img img.exif_orientation = 1 autorotate.autorotate_image(unicode(in_path), unicode(out_path)) assert img.exif_autotransform.call_count == 0 assert out_path.exists() img.exif_orientation = None autorotate.autorotate_image(unicode(in_path), unicode(out_path)) assert img.exif_autotransform.call_count == 0 assert out_path.exists() img.exif_orientation = 6 img.exif_autotransform.return_value = mock.Mock() autorotate.autorotate_image(unicode(in_path), unicode(out_path)) assert img.exif_autotransform.call_count == 1 img.exif_autotransform.return_value.save.assert_called_with( unicode(out_path))