-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_function_plotter.py
More file actions
46 lines (38 loc) · 1.5 KB
/
test_function_plotter.py
File metadata and controls
46 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from pytestqt.qtbot import QtBot
import functionPlotter
def test_plot_function(qtbot: QtBot):
# Create the application
app = QApplication(sys.argv)
# Create the widget
widget = functionPlotter.FunctionPlotter()
# Add the widget to the qtbot
qtbot.addWidget(widget)
# Test invalid function input
qtbot.keyClicks(widget.textbox, "")
qtbot.mouseClick(widget.plot_button, Qt.LeftButton)
assert widget.canvas.figure.axes[0].lines == []
# Test invalid xmin and/or xmax input
qtbot.keyClicks(widget.textbox, "x**2")
qtbot.keyClicks(widget.xmin_textbox, "5")
qtbot.keyClicks(widget.xmax_textbox, "2")
qtbot.mouseClick(widget.plot_button, Qt.LeftButton)
assert widget.canvas.figure.axes[0].lines == []
qtbot.keyClicks(widget.xmin_textbox, "a")
qtbot.mouseClick(widget.plot_button, Qt.LeftButton)
assert widget.canvas.figure.axes[0].lines == []
# Test invalid function syntax
qtbot.keyClicks(widget.textbox, "5*x^3+2*x")
qtbot.keyClicks(widget.xmin_textbox, "-5")
qtbot.keyClicks(widget.xmax_textbox, "5")
qtbot.mouseClick(widget.plot_button, Qt.LeftButton)
assert widget.canvas.figure.axes[0].lines == []
# Test valid input
qtbot.keyClicks(widget.textbox, "5*x**3+2*x")
qtbot.mouseClick(widget.plot_button, Qt.LeftButton)
assert widget.canvas.figure.axes[0].lines != []
# Close the widget and application
widget.close()
app.quit()