1
0

resources.py 661 B

123456789101112131415161718192021222324252627282930
  1. import numpy as np
  2. from io import BytesIO
  3. import pytest
  4. def get_mpl_fig():
  5. pytest.importorskip("matplotlib")
  6. import matplotlib.pyplot as plt
  7. # Data for plotting
  8. t = np.arange(0.0, 2.0, 0.01)
  9. s = 1 + np.sin(2 * np.pi * t)
  10. fig, ax = plt.subplots()
  11. ax.plot(t, s)
  12. buf = BytesIO()
  13. fig.savefig(buf, format='png')
  14. buf.seek(0)
  15. bytes = buf.read()
  16. return fig, bytes
  17. def get_pil_image():
  18. pytest.importorskip("PIL")
  19. from PIL import Image
  20. img = Image.new('RGB', (100, 30), color = (73, 109, 137))
  21. buf = BytesIO()
  22. img.save(buf, format='PNG')
  23. buf.seek(0)
  24. bytes = buf.read()
  25. return img, bytes