Skip to content

Commit

Permalink
Merge pull request #140 from Pinzia/master
Browse files Browse the repository at this point in the history
Working 'DataToTarallo' tests, close #134
  • Loading branch information
lvps authored Dec 9, 2021
2 parents 37a4af5 + 8c98687 commit dc6666a
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 3 deletions.
12 changes: 9 additions & 3 deletions main_with_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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.")
Expand Down
Empty file added tests/main_with_gui/__init__.py
Empty file.
146 changes: 146 additions & 0 deletions tests/main_with_gui/test_gui.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit dc6666a

Please sign in to comment.