Skip to content

Figure out why test_interactive_backend fails on Travis macOS #18213

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

Closed
QuLogic opened this issue Aug 10, 2020 · 11 comments
Closed

Figure out why test_interactive_backend fails on Travis macOS #18213

QuLogic opened this issue Aug 10, 2020 · 11 comments
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! GUI: MacOSX OS: Apple topic: testing
Milestone

Comments

@QuLogic
Copy link
Member

QuLogic commented Aug 10, 2020

In the interest of getting 3.3.1 out, we skipped the test_interactive_backend test on Travis macOS. It works correctly on a 'real' macOS machine from MacStadium, so we were okay with this for now. However, we should get to the bottom of this failure, whether it's because of old macOS settings on Travis, or whether it's something we can't rely on overall.

Matplotlib version

Marked as Good first issue, as this should be self-contained to the macOS backend and CI, but Medium difficulty, because it's CI...

@QuLogic QuLogic added OS: Apple GUI: MacOSX topic: testing Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! labels Aug 10, 2020
@QuLogic QuLogic added this to the v3.4.0 milestone Aug 10, 2020
QuLogic added a commit to QuLogic/matplotlib that referenced this issue Aug 10, 2020
@QuLogic
Copy link
Member Author

QuLogic commented Aug 10, 2020

Also, cc @jkseppan since you worked on the Travis macOS build. Note that the code in #18184 that was reverted to used to work fine, but that was before the Travis changes.

@dopplershift
Copy link
Contributor

Well it's not just CI, I can't get that test to pass at all on my system. What I'm seeing on my system is that the two images in that test are saved with two different DPI's. Here's the before image (Mac Preview says 100 dpi):
before

And here's the after (Mac Preview says 200 DPI):
after

I can get the test to pass by passing dpi=100 to the two calls to savefig() in the test. That doesn't feel like a fix, though--why would the DPI change in this code?

fig, ax = plt.subplots()
assert_equal(
    type(fig.canvas).__module__,
    "matplotlib.backends.backend_{}".format(backend))

ax.plot([0, 1], [2, 3])

timer = fig.canvas.new_timer(1.)  # Test that floats are cast to int as needed.
timer.add_callback(FigureCanvasBase.key_press_event, fig.canvas, "q")
# Trigger quitting upon draw.
fig.canvas.mpl_connect("draw_event", lambda event: timer.start())
fig.canvas.mpl_connect("close_event", print)

result = io.BytesIO()
fig.savefig(result, format='png')

plt.show()

# Ensure that the window is really closed.
plt.pause(0.5)

# Test that saving works after interactive window is closed, but the figure is
# not deleted.
result_after = io.BytesIO()
fig.savefig(result_after, format='png')

@dopplershift
Copy link
Contributor

Here's the minimum reproducible case for getting the DPI change:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
fig.savefig('before.png')

plt.pause(0.5)  # Need for change in DPI; plt.show() also equivalent

fig.savefig('after.png')

@dopplershift
Copy link
Contributor

So the issue is that the macosx backend assumes its device scale is 1.0 until it does a draw, then it knows it from the graphics context. Just need to plumb something in to allow it to know that from the start.

@LuiGiovanni
Copy link

LuiGiovanni commented Dec 3, 2020

Hello! This is my first time contributing, I'd like to work on this issue. Is there anything I should do previously or some steps I need to follow? @QuLogic

@QuLogic
Copy link
Member Author

QuLogic commented Jan 4, 2021

I think @dopplershift is working on this in the above-linked PR; I don't know what the state of it is at this moment.

@dopplershift
Copy link
Contributor

I've poked at it, but I don't have anything useful to share IIRC.

@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 27, 2021
@dstansby
Copy link
Member

Can this be closed now we've migrated off Travis?

@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Sep 25, 2021
@QuLogic
Copy link
Member Author

QuLogic commented Oct 19, 2021

Well, @dopplershift could also reproduce the problem, but maybe it can be fixed by #21365?

@greglucas
Copy link
Contributor

I can reproduce the failure with mpl 3.4.3, but everything seems to work OK with the current 3.5rc and master even without that additional PR. Note that it does still work with that additional PR for me too. So, I think this issue can be closed and returned to the v3.5.0 milestone.

@QuLogic QuLogic modified the milestones: v3.6.0, v3.5.0 Oct 20, 2021
@QuLogic
Copy link
Member Author

QuLogic commented Oct 20, 2021

OK, we can close then.

@QuLogic QuLogic closed this as completed Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Good first issue Open a pull request against these issues if there are no active ones! GUI: MacOSX OS: Apple topic: testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants