-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add PEP 519 support #6788
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
Add PEP 519 support #6788
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import numpy as np | ||
from numpy.testing import assert_equal | ||
from nose.tools import assert_false, assert_true | ||
from nose.plugins.skip import SkipTest | ||
import matplotlib as mpl | ||
from matplotlib import pyplot as plt | ||
from matplotlib import animation | ||
|
@@ -107,6 +108,12 @@ def test_save_animation_smoketest(): | |
for writer, extension in six.iteritems(WRITER_OUTPUT): | ||
yield check_save_animation, writer, extension | ||
|
||
for writer, extension in six.iteritems(WRITER_OUTPUT): | ||
yield check_save_animation_pep_519, writer, extension | ||
|
||
for writer, extension in six.iteritems(WRITER_OUTPUT): | ||
yield check_save_animation_pathlib, writer, extension | ||
|
||
|
||
@cleanup | ||
def check_save_animation(writer, extension='mp4'): | ||
|
@@ -144,6 +151,91 @@ def animate(i): | |
pass | ||
|
||
|
||
@cleanup | ||
def check_save_animation_pep_519(writer, extension='mp4'): | ||
class FakeFSPathClass(object): | ||
def __init__(self, path): | ||
self._path = path | ||
|
||
def __fspath__(self): | ||
return self._path | ||
|
||
if not animation.writers.is_available(writer): | ||
skip("writer '%s' not available on this system" | ||
% writer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am, again, surprised pep8 allows that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't for me; I don't know why this is passing either. |
||
fig, ax = plt.subplots() | ||
line, = ax.plot([], []) | ||
|
||
ax.set_xlim(0, 10) | ||
ax.set_ylim(-1, 1) | ||
|
||
def init(): | ||
line.set_data([], []) | ||
return line, | ||
|
||
def animate(i): | ||
x = np.linspace(0, 10, 100) | ||
y = np.sin(x + i) | ||
line.set_data(x, y) | ||
return line, | ||
|
||
# Use NamedTemporaryFile: will be automatically deleted | ||
F = tempfile.NamedTemporaryFile(suffix='.' + extension) | ||
F.close() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works on windows to get a named temp file name... |
||
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5) | ||
try: | ||
anim.save(FakeFSPathClass(F.name), fps=30, writer=writer, bitrate=500) | ||
except UnicodeDecodeError: | ||
xfail("There can be errors in the numpy import stack, " | ||
"see issues #1891 and #2679") | ||
finally: | ||
try: | ||
os.remove(F.name) | ||
except Exception: | ||
pass | ||
|
||
|
||
@cleanup | ||
def check_save_animation_pathlib(writer, extension='mp4'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test and the previous one looks like they could be refactoring to loop other Path and fspath compatible object to minimize the code duplication. |
||
try: | ||
from pathlib import Path | ||
except ImportError: | ||
raise SkipTest("pathlib not installed") | ||
|
||
if not animation.writers.is_available(writer): | ||
skip("writer '%s' not available on this system" % writer) | ||
fig, ax = plt.subplots() | ||
line, = ax.plot([], []) | ||
|
||
ax.set_xlim(0, 10) | ||
ax.set_ylim(-1, 1) | ||
|
||
def init(): | ||
line.set_data([], []) | ||
return line, | ||
|
||
def animate(i): | ||
x = np.linspace(0, 10, 100) | ||
y = np.sin(x + i) | ||
line.set_data(x, y) | ||
return line, | ||
|
||
# Use NamedTemporaryFile: will be automatically deleted | ||
F = tempfile.NamedTemporaryFile(suffix='.' + extension) | ||
F.close() | ||
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5) | ||
try: | ||
anim.save(Path(F.name), fps=30, writer=writer, bitrate=500) | ||
except UnicodeDecodeError: | ||
xfail("There can be errors in the numpy import stack, " | ||
"see issues #1891 and #2679") | ||
finally: | ||
try: | ||
os.remove(F.name) | ||
except Exception: | ||
pass | ||
|
||
|
||
@cleanup | ||
def test_no_length_frames(): | ||
fig, ax = plt.subplots() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from matplotlib import pyplot as plt | ||
from matplotlib.testing.decorators import (image_comparison, knownfailureif, | ||
cleanup) | ||
from nose.plugins.skip import SkipTest | ||
|
||
if 'TRAVIS' not in os.environ: | ||
@image_comparison(baseline_images=['pdf_use14corefonts'], | ||
|
@@ -132,3 +133,39 @@ def test_grayscale_alpha(): | |
ax.imshow(dd, interpolation='none', cmap='gray_r') | ||
ax.set_xticks([]) | ||
ax.set_yticks([]) | ||
|
||
|
||
@cleanup | ||
def test_pdfpages_accept_pep_519(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those two tests look like they could be refactored into one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test_pdfpages_accept_pep_519 and test_savefig_accept_pathlib? I'm not sure it's possible to skip part of a test and have that appear in nose/pytest. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmh… good question. |
||
from tempfile import NamedTemporaryFile | ||
|
||
class FakeFSPathClass(object): | ||
def __init__(self, path): | ||
self._path = path | ||
|
||
def __fspath__(self): | ||
return self._path | ||
tmpfile = NamedTemporaryFile(suffix='.pdf') | ||
tmpfile.close() | ||
with PdfPages(FakeFSPathClass(tmpfile.name)) as pdf: | ||
fig, ax = plt.subplots() | ||
ax.plot([1, 2], [3, 4]) | ||
pdf.savefig(fig) | ||
|
||
|
||
@cleanup | ||
def test_savefig_accept_pathlib(): | ||
try: | ||
from pathlib import Path | ||
except ImportError: | ||
raise SkipTest("pathlib not installed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kojoley What is the correct way to handle this now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is OK to use |
||
from tempfile import NamedTemporaryFile | ||
|
||
fig, ax = plt.subplots() | ||
ax.plot([1, 2], [3, 4]) | ||
tmpfile = NamedTemporaryFile(suffix='.pdf') | ||
tmpfile.close() | ||
with PdfPages(Path(tmpfile.name)) as pdf: | ||
fig, ax = plt.subplots() | ||
ax.plot([1, 2], [3, 4]) | ||
pdf.savefig(fig) |
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.
I would avoid referencing to peps in function name. It is unclear what it does.
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.
What about check_save_animation_PathLike?
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.
check_save_animation_path_like
?