Skip to content

Commit

Permalink
Update tests to allow for refactored apply_pil
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed May 26, 2020
1 parent eb4ef0a commit e73308f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions trollimage/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,21 +1984,23 @@ def dummy_fun(pil_obj, *args, **kwargs):
return pil_obj

img = xrimage.XRImage(data)
pi = mock.MagicMock()
img.pil_image = pi
res = img.apply_pil(dummy_fun, 'RGB')
# check that the pil image generation is delayed
pi.assert_not_called()
# make it happen
res.data.data.compute()
pi.return_value.convert.assert_called_with('RGB')
with mock.patch.object(xrimage, "PILImage") as pi:
pil_img = mock.MagicMock()
pi.fromarray = mock.Mock(wraps=lambda *args, **kwargs: pil_img)
res = img.apply_pil(dummy_fun, 'RGB')
# check that the pil image generation is delayed
pi.fromarray.assert_not_called()
# make it happen
res.data.data.compute()
pil_img.convert.assert_called_with('RGB')

img = xrimage.XRImage(data)
pi = mock.MagicMock()
img.pil_image = pi
res = img.apply_pil(dummy_fun, 'RGB',
fun_args=('Hey', 'Jude'),
fun_kwargs={'chorus': "La lala lalalala"})
self.assertEqual(dummy_args, [({}, ), {}])
res.data.data.compute()
self.assertEqual(dummy_args, [(OrderedDict(), 'Hey', 'Jude'), {'chorus': "La lala lalalala"}])
with mock.patch.object(xrimage, "PILImage") as pi:
pil_img = mock.MagicMock()
pi.fromarray = mock.Mock(wraps=lambda *args, **kwargs: pil_img)
res = img.apply_pil(dummy_fun, 'RGB',
fun_args=('Hey', 'Jude'),
fun_kwargs={'chorus': "La lala lalalala"})
self.assertEqual(dummy_args, [({}, ), {}])
res.data.data.compute()
self.assertEqual(dummy_args, [(OrderedDict(), 'Hey', 'Jude'), {'chorus': "La lala lalalala"}])

0 comments on commit e73308f

Please sign in to comment.