-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_function_plotter_gui.py
86 lines (58 loc) · 2.47 KB
/
test_function_plotter_gui.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import pytest
from PySide2.QtCore import Qt
from function_plotter import Window
@pytest.fixture
def app(qapp, qtbot):
window = Window()
window.show()
qtbot.addWidget(window)
return window
def test_plot_equation(app, qtbot):
# Find the relevant widgets
equation = app.equation
minValueEdit = app.minValueEdit
maxValueEdit = app.maxValueEdit
button = app.button
######################################## Test-1 ########################################
# Simulate user input
equation.setText("x**2")
minValueEdit.setText("0")
maxValueEdit.setText("10")
# Click the draw button
qtbot.mouseClick(button, Qt.LeftButton)
# Retrieve the plot widget and assert the plot is drawn correctly
plot_widget = app.canvas
assert len(plot_widget.figure.axes) == 1 # Verify that one axis is present
assert len(plot_widget.figure.axes[0].lines) == 1 # Verify that one line is drawn
######################################## Test-2 ########################################
# Simulate user input
equation.setText("x**2") # Invalid equation with "^" instead of "**"
minValueEdit.setText("b")
maxValueEdit.setText("10")
# Click the draw button
qtbot.mouseClick(button, Qt.LeftButton)
# Retrieve the error label and verify that an error message is displayed
error_label = app.error
assert error_label.text() == "Max x and Min x should be numbers only"
######################################## Test-3 ########################################
# Simulate user input
equation.setText("x**2") # Invalid equation with "^" instead of "**"
minValueEdit.setText("20")
maxValueEdit.setText("10")
# Click the draw button
qtbot.mouseClick(button, Qt.LeftButton)
# Retrieve the error label and verify that an error message is displayed
error_label = app.error
assert error_label.text() == "Max x should be greater than Min x"
######################################## Test-4 ########################################
# Simulate user input
equation.setText("x**2 + c") # Invalid equation with "^" instead of "**"
minValueEdit.setText("0")
maxValueEdit.setText("10")
# Click the draw button
qtbot.mouseClick(button, Qt.LeftButton)
# Retrieve the error label and verify that an error message is displayed
error_label = app.error
assert error_label.text() == "Supported Operators: x, /, +, *, ^, -"
if __name__ == "__main__":
pytest.main()