Skip to content

Commit

Permalink
[CO] Adding test on draw_FEMM button
Browse files Browse the repository at this point in the history
  • Loading branch information
BonneelP committed Jan 27, 2022
1 parent 485d8b7 commit bcff412
Showing 1 changed file with 48 additions and 17 deletions.
65 changes: 48 additions & 17 deletions Tests/GUI/DMachineSetup/test_SPreview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from random import uniform
from os.path import join, isfile
from os import makedirs
from os.path import join, isfile, isdir
import mock

import pytest
Expand All @@ -10,7 +11,7 @@

from pyleecan.GUI.Dialog.DMachineSetup.DMachineSetup import DMachineSetup
from pyleecan.GUI.Dialog.DMachineSetup.SPreview.SPreview import SPreview
from Tests import TEST_DATA_DIR as data_test
from Tests import TEST_DATA_DIR as data_test, save_gui_path
from pyleecan.definitions import MAIN_DIR
from pyleecan.Functions.load import load_matlib

Expand Down Expand Up @@ -48,25 +49,29 @@


class TestSPreview(object):
@pytest.fixture
def setup(self):
"""Run at the begining of every test to setup the gui"""

@classmethod
def setup_class(cls):
"""Start the app for the test"""
print("\nStart Test TestSPreview")
if not QtWidgets.QApplication.instance():
self.app = QtWidgets.QApplication(sys.argv)
cls.app = QtWidgets.QApplication(sys.argv)
else:
self.app = QtWidgets.QApplication.instance()
cls.app = QtWidgets.QApplication.instance()

def setup_method(self):
"""Run at the begining of every test to setup the gui"""
# MatLib widget
material_dict = load_matlib(matlib_path=matlib_path)
widget = DMachineSetup(material_dict=material_dict, machine_path=machine_path)
self.widget = DMachineSetup(material_dict=material_dict, machine_path=machine_path)

yield {"widget": widget}

self.app.quit()
@classmethod
def teardown_class(cls):
"""Exit the app after the test"""
cls.app.quit()

@pytest.mark.parametrize("test_dict", load_preview_test)
def test_load(self, setup, test_dict):
def test_load(self, test_dict):
"""Check that you can load a machine"""
assert isfile(test_dict["file_path"])

Expand All @@ -75,20 +80,46 @@ def test_load(self, setup, test_dict):
"PySide2.QtWidgets.QFileDialog.getOpenFileName", return_value=return_value
):
# To trigger the slot
setup["widget"].b_load.clicked.emit()
self.widget.b_load.clicked.emit()

# Check load MachineType
assert type(setup["widget"].w_step) is SPreview
assert type(self.widget.w_step) is SPreview
# Check the table
assert (
setup["widget"].w_step.tab_machine.tab_param.rowCount() == test_dict["Nrow"]
self.widget.w_step.tab_machine.tab_param.rowCount() == test_dict["Nrow"]
)
for ii, content in enumerate(test_dict["table"]):
assert (
setup["widget"].w_step.tab_machine.tab_param.item(ii, 0).text()
self.widget.w_step.tab_machine.tab_param.item(ii, 0).text()
== content[0]
)
assert (
setup["widget"].w_step.tab_machine.tab_param.item(ii, 1).text()
self.widget.w_step.tab_machine.tab_param.item(ii, 1).text()
== content[1]
)
# Check Draw FEMM
FEMM_dir = join(save_gui_path, "Draw_FEMM")
if not isdir(FEMM_dir):
makedirs(FEMM_dir)
femm_path = join(FEMM_dir, self.widget.machine.name+".fem")
assert not isfile(femm_path)

return_value = (
femm_path,
"FEMM (*.fem)",
)
with mock.patch(
"PySide2.QtWidgets.QFileDialog.getSaveFileName", return_value=return_value
):
self.widget.w_step.tab_machine.b_FEMM.clicked.emit()
assert isfile(femm_path)

if __name__ == "__main__":
a = TestSPreview()
a.setup_class()
a.setup_method()
for ii, test_dict in enumerate(load_preview_test):
print(ii)
a.test_load(test_dict)
# a.test_load(load_preview_test[0])
print("Done")

0 comments on commit bcff412

Please sign in to comment.