Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc693df6

Browse files
committed
Add tests for
1 parentba09058 commitc693df6

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

‎lib/matplotlib/tests/test_image.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def test_nonuniformimage_setnorm():
455455

456456
@knownfailureif(notHAS_PIL)
457457
@cleanup
458-
deftest_jpeg_alpha():
458+
deftest_flatten():
459459
plt.figure(figsize=(1,1),dpi=300)
460460
# Create an image that is all black, with a gradient from 0-1 in
461461
# the alpha channel from left to right.
@@ -464,21 +464,43 @@ def test_jpeg_alpha():
464464

465465
plt.figimage(im)
466466

467-
buff=io.BytesIO()
467+
jpg_buf=io.BytesIO()
468+
pngF_buf=io.BytesIO()
469+
png_buf=io.BytesIO()
470+
468471
withrc_context({'savefig.facecolor':'red'}):
469-
plt.savefig(buff,transparent=True,format='jpg',dpi=300)
472+
plt.savefig(jpg_buf,transparent=True,format='jpg',dpi=300)
473+
plt.savefig(pngF_buf,transparent=True,format='png',
474+
flatten=True,dpi=300)
475+
plt.savefig(png_buf,transparent=True,format='png',dpi=300)
470476

471-
buff.seek(0)
472-
image=Image.open(buff)
477+
jpg_buf.seek(0)
478+
pngF_buf.seek(0)
479+
png_buf.seek(0)
480+
481+
jpg_im=Image.open(jpg_buf)
482+
pngF_im=Image.open(pngF_buf)
483+
png_im=Image.open(png_buf)
473484

474485
# If this fails, there will be only one color (all black). If this
475486
# is working, we should have all 256 shades of grey represented.
476-
print("num colors: ",len(image.getcolors(256)))
477-
assertlen(image.getcolors(256))>=175andlen(image.getcolors(256))<=185
487+
print("num colors [jpg]: ",len(jpg_im.getcolors(256)))
488+
print("num colors [png, flattened]: ",len(pngF_im.getcolors(256)))
489+
print("num colors [png, not flattened]: ",len(pngF_im.getcolors(256)))
490+
491+
assertlen(jpg_im.getcolors(256))>=175andlen(jpg_im.getcolors(256))<=185
492+
assertlen(pngF_im.getcolor(256))==256
493+
assertlen(png_im.getcolor(256))==256
494+
478495
# The fully transparent part should be red, not white or black
479-
# or anything else
480-
print("corner pixel: ",image.getpixel((0,0)))
481-
assertimage.getpixel((0,0))== (254,0,0)
496+
# or anything else when flattened.
497+
print("corner pixel [jpg]: ",jpg_im.getpixel((0,0)))
498+
print("corner pixel [png, flattened]: ",pngF_im.getpixel((0,0)))
499+
print("corner pixel [png, not flattened]: ",png_im.getpixel((0,0)))
500+
501+
assertjpg_im.getpixel((0,0))== (254,0,0)
502+
assertpngF_im.getpixel((0,0))== (255,0,0,255)
503+
assertpng_im.getpixel((0,0))== (255,255,255,0)
482504

483505

484506
if__name__=='__main__':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp