Skip to content

Commit e1ccb86

Browse files
committed
change structure of invalid input tests
1 parent f82c581 commit e1ccb86

File tree

1 file changed

+58
-49
lines changed

1 file changed

+58
-49
lines changed

tests/test_function_plotter.py

+58-49
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import sys
22
import os
33
import pytest
4-
from PySide2.QtWidgets import QApplication, QMessageBox
4+
from PySide2.QtWidgets import QApplication, QMessageBox, QWidget
55
from PySide2.QtCore import Qt
6+
from PySide2.QtCore import Qt
7+
from PySide2.QtTest import QTest
68

79
# Add the src directory to the Python path
810
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../src")))
@@ -157,51 +159,58 @@ def test_function_with_spaces(function_plotter, qtbot):
157159
# bad input tests
158160

159161

160-
# def test_invalid_function_input_characters(function_plotter, qtbot):
161-
# function_plotter.function_input.setText("5*x^3 + 2*x + !")
162-
# function_plotter.min_input.setText("0")
163-
# function_plotter.max_input.setText("10")
164-
# qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
165-
# qtbot.waitUntil(lambda: function_plotter.centralWidget().findChildren(QMessageBox))
166-
# message_box = function_plotter.centralWidget().findChildren(QMessageBox)[0]
167-
# assert "Function contains invalid characters." in message_box.text()
168-
169-
170-
# def test_empty_function_input(function_plotter, qtbot):
171-
# function_plotter.function_input.setText("")
172-
# function_plotter.min_input.setText("0")
173-
# function_plotter.max_input.setText("10")
174-
# qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
175-
# qtbot.waitUntil(lambda: function_plotter.centralWidget().findChildren(QMessageBox))
176-
# message_box = function_plotter.centralWidget().findChildren(QMessageBox)[0]
177-
# assert "Function cannot be empty." in message_box.text()
178-
179-
180-
# def test_invalid_min_max_values(function_plotter, qtbot):
181-
# function_plotter.function_input.setText("5*x^3 + 2*x")
182-
# function_plotter.min_input.setText("10")
183-
# function_plotter.max_input.setText("0")
184-
# qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
185-
# qtbot.waitUntil(lambda: function_plotter.centralWidget().findChildren(QMessageBox))
186-
# message_box = function_plotter.centralWidget().findChildren(QMessageBox)[0]
187-
# assert "Min value must be less than Max value." in message_box.text()
188-
189-
190-
# def test_non_numeric_min_max_values(function_plotter, qtbot):
191-
# function_plotter.function_input.setText("5*x^3 + 2*x")
192-
# function_plotter.min_input.setText("a")
193-
# function_plotter.max_input.setText("b")
194-
# qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
195-
# qtbot.waitUntil(lambda: function_plotter.centralWidget().findChildren(QMessageBox))
196-
# message_box = function_plotter.centralWidget().findChildren(QMessageBox)[0]
197-
# assert "Min and Max values must be numbers." in message_box.text()
198-
199-
200-
# def test_empty_min_max_values(function_plotter, qtbot):
201-
# function_plotter.function_input.setText("x^2")
202-
# function_plotter.min_input.setText("")
203-
# function_plotter.max_input.setText("")
204-
# qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
205-
# qtbot.waitUntil(lambda: function_plotter.centralWidget().findChildren(QMessageBox))
206-
# message_box = function_plotter.centralWidget().findChildren(QMessageBox)[0]
207-
# assert "Min and Max values cannot be empty." in message_box.text()
162+
def test_invalid_function_input_characters(function_plotter, qtbot):
163+
with qtbot.wait_signal(
164+
function_plotter.error_message_signal, timeout=5000
165+
) as blocker:
166+
function_plotter.function_input.setText("5*x^3 + 2*x + !")
167+
function_plotter.min_input.setText("0")
168+
function_plotter.max_input.setText("10")
169+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
170+
assert blocker.args[0] == "Function contains invalid characters."
171+
172+
173+
def test_empty_function_input(function_plotter, qtbot):
174+
with qtbot.wait_signal(
175+
function_plotter.error_message_signal, timeout=5000
176+
) as blocker:
177+
function_plotter.function_input.setText("")
178+
function_plotter.min_input.setText("0")
179+
function_plotter.max_input.setText("10")
180+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
181+
assert blocker.args[0] == "Function cannot be empty."
182+
183+
184+
def test_invalid_min_max_values(function_plotter, qtbot):
185+
with qtbot.wait_signal(
186+
function_plotter.error_message_signal, timeout=5000
187+
) as blocker:
188+
function_plotter.function_input.setText("5*x^3 + 2*x")
189+
function_plotter.min_input.setText("10")
190+
function_plotter.max_input.setText("0")
191+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
192+
assert blocker.args[0] == "Min value must be less than Max value."
193+
194+
195+
def test_non_numeric_min_max_values(function_plotter, qtbot):
196+
with qtbot.wait_signal(
197+
function_plotter.error_message_signal, timeout=5000
198+
) as blocker:
199+
function_plotter.function_input.setText("5*x^3 + 2*x")
200+
function_plotter.min_input.setText("a")
201+
function_plotter.max_input.setText("b")
202+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
203+
assert blocker.args[0] == "Min and Max values must be numbers."
204+
205+
206+
def test_empty_min_max_values(function_plotter, qtbot):
207+
with qtbot.wait_signal(
208+
function_plotter.error_message_signal, timeout=5000
209+
) as blocker:
210+
function_plotter.function_input.setText("x^2")
211+
function_plotter.min_input.setText("")
212+
function_plotter.max_input.setText("")
213+
qtbot.mouseClick(function_plotter.plot_button, Qt.LeftButton)
214+
assert blocker.args[0] == "Min and Max values cannot be empty."
215+
216+

0 commit comments

Comments
 (0)