From 68de9439cd3911e2fffe5eba7b741ae65bf9181d Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Feb 2019 18:09:16 -0500 Subject: [PATCH 1/3] Fix matplotlib wasm backend after undefined attribute behavior changed --- packages/matplotlib/src/wasm_backend.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/matplotlib/src/wasm_backend.py b/packages/matplotlib/src/wasm_backend.py index 88a7ac41e..ecced2f43 100644 --- a/packages/matplotlib/src/wasm_backend.py +++ b/packages/matplotlib/src/wasm_backend.py @@ -90,15 +90,15 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg): This is typically 2 on a HiDPI ("Retina") display, and 1 otherwise. """ backing_store = ( - context.backingStorePixelRatio or - context.webkitBackingStorePixel or - context.mozBackingStorePixelRatio or - context.msBackingStorePixelRatio or - context.oBackingStorePixelRatio or - context.backendStorePixelRatio or + getattr(context, 'backingStorePixelRatio', 0) or + getattr(context, 'webkitBackingStorePixel', 0) or + getattr(context, 'mozBackingStorePixelRatio', 0) or + getattr(context, 'msBackingStorePixelRatio', 0) or + getattr(context, 'oBackingStorePixelRatio', 0) or + getattr(context, 'backendStorePixelRatio', 0) or 1 ) - return (window.devicePixelRatio or 1) / backing_store + return (getattr(window, 'devicePixelRatio', 0) or 1) / backing_store def create_root_element(self): # Designed to be overridden by subclasses for use in contexts other From 45d14492093b2a7143aa2798443060c01203badd Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Feb 2019 18:17:24 -0500 Subject: [PATCH 2/3] Include plt.show() in test --- test/test_matplotlib.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_matplotlib.py b/test/test_matplotlib.py index 37776fd0c..8454a7111 100644 --- a/test/test_matplotlib.py +++ b/test/test_matplotlib.py @@ -3,6 +3,7 @@ def test_matplotlib(selenium): selenium.run("from matplotlib import pyplot as plt") selenium.run("plt.figure()") selenium.run("x = plt.plot([1,2,3])") + selenium.run("plt.show()") def test_svg(selenium): From 2f3a727eabe01befd79924adba757b1f45d31516 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 21 Feb 2019 18:23:03 -0500 Subject: [PATCH 3/3] Add test for wasm_backend. Fix PDF test. --- packages/matplotlib/src/wasm_backend.py | 5 ++++- test/test_matplotlib.py | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/matplotlib/src/wasm_backend.py b/packages/matplotlib/src/wasm_backend.py index ecced2f43..a16ab91c0 100644 --- a/packages/matplotlib/src/wasm_backend.py +++ b/packages/matplotlib/src/wasm_backend.py @@ -104,7 +104,10 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg): # Designed to be overridden by subclasses for use in contexts other # than iodide. from js import iodide - return iodide.output.element('div') + if iodide is not None: + return iodide.output.element('div') + else: + return document.createElement('div') def show(self): # If we've already shown this canvas elsewhere, don't create a new one, diff --git a/test/test_matplotlib.py b/test/test_matplotlib.py index 8454a7111..b9e51aecd 100644 --- a/test/test_matplotlib.py +++ b/test/test_matplotlib.py @@ -1,8 +1,9 @@ -def test_matplotlib(selenium): +def test_matplotlib(selenium_standalone): + selenium = selenium_standalone selenium.load_package("matplotlib") selenium.run("from matplotlib import pyplot as plt") selenium.run("plt.figure()") - selenium.run("x = plt.plot([1,2,3])") + selenium.run("plt.plot([1,2,3])") selenium.run("plt.show()") @@ -27,5 +28,3 @@ def test_pdf(selenium): selenium.run("import io") selenium.run("fd = io.BytesIO()") selenium.run("plt.savefig(fd, format='pdf')") - content = selenium.run("fd.getvalue()") - assert len(content) == 5559