diff --git a/main_with_gui.py b/main_with_gui.py index 81948c1..f88620f 100755 --- a/main_with_gui.py +++ b/main_with_gui.py @@ -82,6 +82,11 @@ def init_ui(self): self.show() +def get_gpu_location(directory): + with open(os.path.join(directory, gpu_loc_file)) as f: + return GPU(f.read()) + + class Welcome(QWidget): def __init__(self, window: QMainWindow): # noinspection PyArgumentList @@ -674,7 +679,7 @@ def upload(self, system_info, checked, bulkid): btntar = mb_wentok.addButton( "See this PC on T.A.R.A.L.L.O.", QMessageBox.NoRole ) - mb_wentok.exec_() + mb_wentok.show() if mb_wentok.clickedButton() == btncnt: self.close() elif mb_wentok.clickedButton() == btnclose: @@ -689,8 +694,9 @@ def upload(self, system_info, checked, bulkid): "It seems there have been some problems or this PC is a duplicate. Please retry." ) btnclose = mb_notok.addButton("Back to JSON", QMessageBox.YesRole) - mb_notok.exec_() - self.close() + mb_notok.show() + if mb_notok.clickedButton(): + self.close() except NoInternetConnectionError: mb_notok = QMessageBox(self) mb_notok.setWindowTitle("Send data to T.A.R.A.L.L.O.") diff --git a/tests/main_with_gui/__init__.py b/tests/main_with_gui/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/main_with_gui/test_gui.py b/tests/main_with_gui/test_gui.py new file mode 100644 index 0000000..a826dbf --- /dev/null +++ b/tests/main_with_gui/test_gui.py @@ -0,0 +1,146 @@ +import pytest +import os +from PyQt5 import QtCore, QtTest, QtWidgets +from main import extract_and_collect_data_from_generated_files +from main_with_gui import Welcome, FilesGenerated, GPU, DataToTarallo + +gpu_loc_file = "gpu_location.txt" + +test_folders = [ + entries for entries in os.listdir("tests/") if os.path.isdir(f"tests/{entries}") +] +for fold in set(test_folders): + if "baseboard.txt" not in os.listdir(f"tests/{fold}"): + test_folders.remove(fold) + + +@pytest.fixture(params=test_folders) +def folders(request): + return request.param + + +@pytest.fixture +def open_welcome(qtbot): + def callback(window): + widget = window(QtWidgets.QMainWindow) + qtbot.addWidget(widget) + widget.show() + qtbot.wait_for_window_shown(widget) + return widget + + return callback + + +@pytest.fixture +def open_filesgen(qtbot): + def callback(window, gpu_loc: GPU): + widget = window(Welcome, gpu_loc) + qtbot.addWidget(widget) + widget.show() + qtbot.wait_for_window_shown(widget) + # QtTest.QTest.qWait(3 * 1000) + return widget + + return callback + + +def get_gpu_location(directory): + with open(os.path.join(directory, gpu_loc_file)) as f: + return GPU(f.read()) + + +class TestVisibleWindow: + def test_visible_welcome(self, open_welcome, qtbot): + widget = open_welcome(Welcome) + assert widget.isVisible() + + def test_visible_filesgen(self, open_filesgen, qtbot): + widget = open_filesgen(FilesGenerated, GPU.dec_gpu) + assert widget.isVisible() + + +class TestDataTarallo: + def press_upload(self, widget, qtbot): + qtbot.mouseClick(widget.btnupl, QtCore.Qt.LeftButton) + w = widget.focusWidget() + assert isinstance(w, QtWidgets.QPushButton) + name = w.text() + assert name == "Upload" + + def check_result(self): + messagebox = QtWidgets.QApplication.activeWindow() + text = messagebox.text() + assert text == "Everything went fine, what do you want to do?" + messagebox.close() + + def def_gpu_location(self, gpu_loc): + if gpu_loc == GPU.int_mobo: + has_dedicated_gpu = False + gpu_in_cpu = False + elif gpu_loc == GPU.int_cpu: + has_dedicated_gpu = False + gpu_in_cpu = True + elif gpu_loc == GPU.dec_gpu: + has_dedicated_gpu = True + gpu_in_cpu = False + return has_dedicated_gpu, gpu_in_cpu + + def test_no_pref(self, qtbot, folders): + gpu_loc = get_gpu_location(os.path.join(os.getcwd(), "tests", folders)) + has_dedicated_gpu, gpu_in_cpu = self.def_gpu_location(gpu_loc) + files_dir = os.path.join(os.getcwd(), "tests", folders) + system_info = extract_and_collect_data_from_generated_files( + files_dir, has_dedicated_gpu, gpu_in_cpu + ) + widget = DataToTarallo(system_info) + widget.show() + QtTest.QTest.qWait(100) + self.press_upload(widget, qtbot) + QtTest.QTest.qWait(100) + self.check_result() + + def test_id(self, qtbot, folders): + gpu_loc = get_gpu_location(os.path.join(os.getcwd(), "tests", folders)) + has_dedicated_gpu, gpu_in_cpu = self.def_gpu_location(gpu_loc) + files_dir = os.path.join(os.getcwd(), "tests", folders) + system_info = extract_and_collect_data_from_generated_files( + files_dir, has_dedicated_gpu, gpu_in_cpu + ) + widget = DataToTarallo(system_info) + widget.show() + widget.txtid.setText(folders) + QtTest.QTest.qWait(100) + self.press_upload(widget, qtbot) + QtTest.QTest.qWait(100) + self.check_result() + + def test_overwrite(self, qtbot, folders): + gpu_loc = get_gpu_location(os.path.join(os.getcwd(), "tests", folders)) + has_dedicated_gpu, gpu_in_cpu = self.def_gpu_location(gpu_loc) + files_dir = os.path.join(os.getcwd(), "tests", folders) + system_info = extract_and_collect_data_from_generated_files( + files_dir, has_dedicated_gpu, gpu_in_cpu + ) + widget = DataToTarallo(system_info) + widget.show() + widget.chbov.setChecked(True) + QtTest.QTest.qWait(100) + self.press_upload(widget, qtbot) + QtTest.QTest.qWait(100) + self.check_result() + + def test_over_id(self, qtbot, folders): + gpu_loc = get_gpu_location(os.path.join(os.getcwd(), "tests", folders)) + has_dedicated_gpu, gpu_in_cpu = self.def_gpu_location(gpu_loc) + files_dir = os.path.join(os.getcwd(), "tests", folders) + system_info = extract_and_collect_data_from_generated_files( + files_dir, has_dedicated_gpu, gpu_in_cpu + ) + widget = DataToTarallo(system_info) + widget.show() + widget.chbov.setChecked(True) + widget.txtid.setText(folders) + QtTest.QTest.qWait(100) + self.press_upload(widget, qtbot) + QtTest.QTest.qWait(100) + self.check_result()