-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_function_plotter.py
More file actions
89 lines (67 loc) · 2.53 KB
/
test_function_plotter.py
File metadata and controls
89 lines (67 loc) · 2.53 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
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
87
88
89
import pytest
from PySide2.QtWidgets import QMessageBox
from Function_Plotter import Window
from PySide2.QtCore import Qt
@pytest.fixture
def app(qtbot):
window = Window()
qtbot.addWidget(window)
return window
# test replacing ^ with **
def test_getText(app, qtbot):
window = app
qtbot.waitExposed(window)
assert window.windowTitle() == "Function Plotter"
assert window.getText('x^2+x^3') == 'x**2+x**3'
# test fig properties in correct input
def test_plot_function(app, qtbot):
window = app
window.equationText.setText("x^2 + 2*x + 1")
window.minXText.setValue(-10)
window.maxXText.setValue(10)
qtbot.mouseClick(window.confirmBtn, Qt.LeftButton)
assert window.fig.axes[0].get_title() == "Function Plotter"
assert window.fig.axes[0].get_xlabel() == "X"
assert window.fig.axes[0].get_ylabel() == "Y"
# test min x is larger that max x
def test_plot_function2(app, qtbot):
window = app
window.equationText.setText("x**2 + 2*x + 1")
window.minXText.setValue(10)
window.maxXText.setValue(0)
qtbot.mouseClick(window.confirmBtn, Qt.LeftButton)
message_box = qtbot.waitExposed(QMessageBox)
assert window.xRange is None
assert message_box is not None
assert window.error == "Make sure Max X is larger than Min X"
assert window.fig.get_axes() == []
# test equation form
def test_equation(app, qtbot):
window = app
window.equationText.setText("y+2")
window.minXText.setValue(0)
window.maxXText.setValue(10)
qtbot.mouseClick(window.confirmBtn, Qt.LeftButton)
assert window.yRange is None
message_box = qtbot.waitExposed(QMessageBox)
assert message_box is not None
assert window.error == "Make sure the equation is a function of X, allowed operators are +, -, *, /, ^ eg:'2*x^2+x+5'"
assert window.fig.get_axes() == []
# test that the figure has appeared
def test_plot_function3(app, qtbot):
window = app
window.equationText.setText("x**2 + 2*x + 1")
window.minXText.setValue(0)
window.maxXText.setValue(10)
qtbot.mouseClick(window.confirmBtn, Qt.LeftButton)
assert window.fig.get_axes() != []
def test_min_max(app):
window = app
assert window.minXLabel.text() == 'Minimum X'
assert window.minXText.value() == -1
assert window.minXText.minimum() == -1000
assert window.minXText.maximum() == 1000
assert window.maxXLabel.text() == 'Maximum X'
assert window.maxXText.value() == 1
assert window.maxXText.minimum() == -1000
assert window.maxXText.maximum() == 1000