Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test FitsStubImagePlugin for correctness #2430

Merged
merged 2 commits into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tests/images/hopper.fits
Binary file not shown.
36 changes: 35 additions & 1 deletion Tests/test_file_fitsstub.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
from helper import unittest, PillowTestCase

from PIL import FitsStubImagePlugin
from PIL import FitsStubImagePlugin, Image

TEST_FILE = "Tests/images/hopper.fits"


class TestFileFitsStub(PillowTestCase):

def test_open(self):
# Act
im = Image.open(TEST_FILE)

# Assert
self.assertEqual(im.format, "FITS")

# Dummy data from the stub
self.assertEqual(im.mode, "F")
self.assertEqual(im.size, (1, 1))

def test_invalid_file(self):
# Arrange
invalid_file = "Tests/images/flower.jpg"

# Act / Assert
self.assertRaises(SyntaxError,
lambda:
FitsStubImagePlugin.FITSStubImageFile(invalid_file))

def test_load(self):
# Arrange
im = Image.open(TEST_FILE)

# Act / Assert: stub cannot load without an implemented handler
self.assertRaises(IOError, lambda: im.load())

def test_save(self):
# Arrange
im = Image.open(TEST_FILE)
dummy_fp = None
dummy_filename = "dummy.filename"

# Act / Assert: stub cannot save without an implemented handler
self.assertRaises(IOError, lambda: im.save(dummy_filename))
self.assertRaises(
IOError,
lambda: FitsStubImagePlugin._save(im, dummy_fp, dummy_filename))


if __name__ == '__main__':
unittest.main()