-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Convert some tests to pytest style #4369
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import PIL | ||
import PIL.Image | ||
|
||
from .helper import PillowTestCase | ||
|
||
def test_sanity(): | ||
# Make sure we have the binary extension | ||
PIL.Image.core.new("L", (100, 100)) | ||
|
||
class TestSanity(PillowTestCase): | ||
def test_sanity(self): | ||
# Create an image and do stuff with it. | ||
im = PIL.Image.new("1", (100, 100)) | ||
assert (im.mode, im.size) == ("1", (100, 100)) | ||
assert len(im.tobytes()) == 1300 | ||
|
||
# Make sure we have the binary extension | ||
PIL.Image.core.new("L", (100, 100)) | ||
|
||
# Create an image and do stuff with it. | ||
im = PIL.Image.new("1", (100, 100)) | ||
self.assertEqual((im.mode, im.size), ("1", (100, 100))) | ||
self.assertEqual(len(im.tobytes()), 1300) | ||
|
||
# Create images in all remaining major modes. | ||
PIL.Image.new("L", (100, 100)) | ||
PIL.Image.new("P", (100, 100)) | ||
PIL.Image.new("RGB", (100, 100)) | ||
PIL.Image.new("I", (100, 100)) | ||
PIL.Image.new("F", (100, 100)) | ||
# Create images in all remaining major modes. | ||
PIL.Image.new("L", (100, 100)) | ||
PIL.Image.new("P", (100, 100)) | ||
PIL.Image.new("RGB", (100, 100)) | ||
PIL.Image.new("I", (100, 100)) | ||
PIL.Image.new("F", (100, 100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
from PIL import _binary | ||
|
||
from .helper import PillowTestCase | ||
|
||
def test_standard(): | ||
assert _binary.i8(b"*") == 42 | ||
assert _binary.o8(42) == b"*" | ||
|
||
class TestBinary(PillowTestCase): | ||
def test_standard(self): | ||
self.assertEqual(_binary.i8(b"*"), 42) | ||
self.assertEqual(_binary.o8(42), b"*") | ||
|
||
def test_little_endian(self): | ||
self.assertEqual(_binary.i16le(b"\xff\xff\x00\x00"), 65535) | ||
self.assertEqual(_binary.i32le(b"\xff\xff\x00\x00"), 65535) | ||
def test_little_endian(): | ||
assert _binary.i16le(b"\xff\xff\x00\x00") == 65535 | ||
assert _binary.i32le(b"\xff\xff\x00\x00") == 65535 | ||
|
||
self.assertEqual(_binary.o16le(65535), b"\xff\xff") | ||
self.assertEqual(_binary.o32le(65535), b"\xff\xff\x00\x00") | ||
assert _binary.o16le(65535) == b"\xff\xff" | ||
assert _binary.o32le(65535) == b"\xff\xff\x00\x00" | ||
|
||
def test_big_endian(self): | ||
self.assertEqual(_binary.i16be(b"\x00\x00\xff\xff"), 0) | ||
self.assertEqual(_binary.i32be(b"\x00\x00\xff\xff"), 65535) | ||
|
||
self.assertEqual(_binary.o16be(65535), b"\xff\xff") | ||
self.assertEqual(_binary.o32be(65535), b"\x00\x00\xff\xff") | ||
def test_big_endian(): | ||
assert _binary.i16be(b"\x00\x00\xff\xff") == 0 | ||
assert _binary.i32be(b"\x00\x00\xff\xff") == 65535 | ||
|
||
assert _binary.o16be(65535) == b"\xff\xff" | ||
assert _binary.o32be(65535) == b"\x00\x00\xff\xff" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,46 @@ | ||
import pytest | ||
from PIL import BufrStubImagePlugin, Image | ||
|
||
from .helper import PillowTestCase, hopper | ||
from .helper import hopper | ||
|
||
TEST_FILE = "Tests/images/gfs.t06z.rassda.tm00.bufr_d" | ||
|
||
|
||
class TestFileBufrStub(PillowTestCase): | ||
def test_open(self): | ||
# Act | ||
with Image.open(TEST_FILE) as im: | ||
def test_open(): | ||
# Act | ||
with Image.open(TEST_FILE) as im: | ||
|
||
# Assert | ||
self.assertEqual(im.format, "BUFR") | ||
# Assert | ||
assert im.format == "BUFR" | ||
|
||
# Dummy data from the stub | ||
self.assertEqual(im.mode, "F") | ||
self.assertEqual(im.size, (1, 1)) | ||
# Dummy data from the stub | ||
assert im.mode == "F" | ||
assert im.size == (1, 1) | ||
|
||
def test_invalid_file(self): | ||
# Arrange | ||
invalid_file = "Tests/images/flower.jpg" | ||
|
||
# Act / Assert | ||
self.assertRaises( | ||
SyntaxError, BufrStubImagePlugin.BufrStubImageFile, invalid_file | ||
) | ||
def test_invalid_file(): | ||
# Arrange | ||
invalid_file = "Tests/images/flower.jpg" | ||
|
||
def test_load(self): | ||
# Arrange | ||
with Image.open(TEST_FILE) as im: | ||
# Act / Assert | ||
with pytest.raises(SyntaxError): | ||
BufrStubImagePlugin.BufrStubImageFile(invalid_file) | ||
|
||
# Act / Assert: stub cannot load without an implemented handler | ||
self.assertRaises(IOError, im.load) | ||
|
||
def test_save(self): | ||
# Arrange | ||
im = hopper() | ||
tmpfile = self.tempfile("temp.bufr") | ||
def test_load(): | ||
# Arrange | ||
with Image.open(TEST_FILE) as im: | ||
|
||
# Act / Assert: stub cannot save without an implemented handler | ||
self.assertRaises(IOError, im.save, tmpfile) | ||
# Act / Assert: stub cannot load without an implemented handler | ||
with pytest.raises(IOError): | ||
im.load() | ||
|
||
|
||
def test_save(tmp_path): | ||
# Arrange | ||
im = hopper() | ||
tmpfile = str(tmp_path / "temp.bufr") | ||
|
||
# Act / Assert: stub cannot save without an implemented handler | ||
with pytest.raises(IOError): | ||
im.save(tmpfile) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting something new to me, this looks handy:
https://docs.pytest.org/en/latest/tmpdir.html