I know there might be a lot of issues related with testing matplotlib's GUI. I found some advice here: How can I write unit tests against code that uses matplotlib?
I use matplotlib to generate "user" input for my code. How can I mock this input generation?
In the following, I describe my function.
import numpy as np
import matplotlib.pyplot as plt
def select_pixel(xRes, yRes):
pos = []
pos2d = np.zeros([xRes, yRes])
fig, axes = plt.subplots()
axes.set_title('Click to select pixels, middle mouse button to finish')
axes.imshow(pos2d)
# Gather selection
val = [()]
while len(val):
val = plt.ginput(1, timeout=-1)
if len(val):
x, y = val[0]
if (x is not None) & (y is not None):
pos.append([int(x), int(y)])
return pos
For this function, I want to generate a mock output with several use cases:
- No input
- A single input
- Several inputs (eventually also mocking None values?)