def test_stub_deprecated(): class Handler: opened = False loaded = False def open(self, im): self.opened = True def load(self, im): self.loaded = True return Image.new("RGB", (1, 1)) handler = Handler() with pytest.warns(DeprecationWarning): FitsStubImagePlugin.register_handler(handler) with Image.open(TEST_FILE) as im: assert im.format == "FITS" assert im.size == (128, 128) assert im.mode == "L" assert handler.opened assert not handler.loaded im.load() assert handler.loaded FitsStubImagePlugin._handler = None Image.register_open( FitsImagePlugin.FitsImageFile.format, FitsImagePlugin.FitsImageFile, FitsImagePlugin._accept, )
def test_save(): # Arrange with Image.open(TEST_FILE) as im: dummy_fp = None dummy_filename = "dummy.filename" # Act / Assert: stub cannot save without an implemented handler with pytest.raises(OSError): im.save(dummy_filename) with pytest.raises(OSError): FitsStubImagePlugin._save(im, dummy_fp, dummy_filename)
def test_invalid_file(): # Arrange invalid_file = "Tests/images/flower.jpg" # Act / Assert with pytest.raises(SyntaxError): FitsStubImagePlugin.FITSStubImageFile(invalid_file)
def test_invalid_file(self): # Arrange invalid_file = "Tests/images/flower.jpg" # Act / Assert self.assertRaises( SyntaxError, lambda: FitsStubImagePlugin.FITSStubImageFile(invalid_file))
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))
def test_truncated_fits(): # No END to headers image_data = b"SIMPLE = T" + b" " * 50 + b"TRUNCATE" with pytest.raises(OSError): FitsStubImagePlugin.FITSStubImageFile(BytesIO(image_data))
def test_invalid_file(self): invalid_file = "Tests/images/flower.jpg" self.assertRaises( InvalidFileType, lambda: FitsStubImagePlugin.FITSStubImageFile(invalid_file))