pyodide/packages/matplotlib/test_matplotlib.py

31 lines
1.0 KiB
Python

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("plt.plot([1,2,3])")
selenium.run("plt.show()")
def test_svg(selenium):
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("import io")
selenium.run("fd = io.BytesIO()")
selenium.run("plt.savefig(fd, format='svg')")
content = selenium.run("fd.getvalue().decode('utf8')")
assert len(content) == 15752
assert content.startswith("<?xml")
def test_pdf(selenium):
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("import io")
selenium.run("fd = io.BytesIO()")
selenium.run("plt.savefig(fd, format='pdf')")