|
2 | 2 |
|
3 | 3 | import sys |
4 | 4 | from os import mkdir |
5 | | -from os.path import join, isdir |
| 5 | +from os.path import join, isdir, isfile |
| 6 | +import mock |
6 | 7 | from shutil import rmtree, copyfile |
7 | 8 | from random import uniform |
8 | | - |
| 9 | +from numpy import array |
9 | 10 | from PySide2 import QtWidgets |
10 | 11 | from PySide2.QtCore import Qt |
11 | 12 | from PySide2.QtTest import QTest |
12 | 13 |
|
13 | 14 | from pyleecan.Classes.MatMagnetics import MatMagnetics |
14 | 15 | from pyleecan.Classes.Material import Material |
| 16 | +from pyleecan.Classes.ImportMatrixVal import ImportMatrixVal |
15 | 17 | from pyleecan.GUI.Dialog.DMatLib.DMatSetup.DMatSetup import DMatSetup |
16 | 18 | from Tests import save_load_path as save_path, TEST_DATA_DIR |
17 | 19 |
|
@@ -46,6 +48,9 @@ def setup(self): |
46 | 48 | test_obj.is_isotropic = True |
47 | 49 | test_obj.elec.rho = 0.11 |
48 | 50 | test_obj.mag = MatMagnetics(mur_lin=0.12, Wlam=0.13) |
| 51 | + test_obj.mag.BH_curve = ImportMatrixVal( |
| 52 | + value=array([[0, 1], [2, 100], [3, 300], [4, 450]]) |
| 53 | + ) |
49 | 54 | test_obj.struct.rho = 0.14 |
50 | 55 | test_obj.struct.Ex = 0.15 |
51 | 56 | test_obj.struct.Ey = 0.152 |
@@ -87,6 +92,9 @@ def test_init(self, setup): |
87 | 92 | assert setup["widget"].lf_Cp.value() == 0.19 |
88 | 93 | assert setup["widget"].lf_alpha.value() == 0.2 |
89 | 94 | assert setup["widget"].lf_cost_unit.value() == 0.21 |
| 95 | + assert setup["widget"].w_BH_import.w_import.in_matrix.text() == ( |
| 96 | + "Matrix size: (4, 2)" |
| 97 | + ) |
90 | 98 |
|
91 | 99 | # Test Raw Material |
92 | 100 | setup["test_obj"].mag = None |
@@ -429,3 +437,65 @@ def test_set_lambda_x_y_z(self, setup): |
429 | 437 | setup["widget"].lf_Lz.editingFinished.emit() |
430 | 438 |
|
431 | 439 | assert setup["widget"].mat.HT.lambda_z == value |
| 440 | + |
| 441 | + def test_BH_setup(self, setup): |
| 442 | + """Check that the BH curve behave have expected""" |
| 443 | + w_imp = setup["widget"].w_BH_import.w_import |
| 444 | + assert setup["widget"].w_BH_import.c_type_import.currentIndex() == 1 |
| 445 | + setup["widget"].w_BH_import.w_import.in_matrix.text() |
| 446 | + # Open table to check BH values |
| 447 | + assert w_imp.tab_window is None |
| 448 | + w_imp.b_tab.clicked.emit() |
| 449 | + w_imp.tab_window.si_row.value() == 4 |
| 450 | + w_imp.tab_window.si_col.value() == 2 |
| 451 | + w_imp.tab_window.w_tab.cellWidget(0, 0).value() == 0 |
| 452 | + w_imp.tab_window.w_tab.cellWidget(0, 1).value() == 1 |
| 453 | + w_imp.tab_window.w_tab.cellWidget(1, 0).value() == 2 |
| 454 | + w_imp.tab_window.w_tab.cellWidget(1, 1).value() == 100 |
| 455 | + w_imp.tab_window.w_tab.cellWidget(2, 0).value() == 3 |
| 456 | + w_imp.tab_window.w_tab.cellWidget(2, 1).value() == 300 |
| 457 | + w_imp.tab_window.w_tab.cellWidget(3, 0).value() == 4 |
| 458 | + w_imp.tab_window.w_tab.cellWidget(3, 1).value() == 450 |
| 459 | + # Edit table |
| 460 | + w_imp.tab_window.w_tab.cellWidget(3, 0).setValue(5) |
| 461 | + w_imp.tab_window.w_tab.cellWidget(3, 1).setValue(800) |
| 462 | + w_imp.tab_window.b_close.accepted.emit() |
| 463 | + w_imp.tab_window.close() |
| 464 | + setup["widget"].mat.mag.BH_curve.value[3, 0] == 5 |
| 465 | + setup["widget"].mat.mag.BH_curve.value[3, 0] == 800 |
| 466 | + # Export to excel |
| 467 | + excel_path = join(save_path, "DMatSetup_excel_export.xls").replace("\\", "/") |
| 468 | + assert not isfile(excel_path) |
| 469 | + with mock.patch( |
| 470 | + "PySide2.QtWidgets.QFileDialog.getSaveFileName", |
| 471 | + return_value=(excel_path, "Excel file (*.xls .*xlsx)"), |
| 472 | + ): |
| 473 | + w_imp.b_convert.clicked.emit() |
| 474 | + assert isfile(excel_path) |
| 475 | + # Convert to excel import |
| 476 | + setup["widget"].w_BH_import.c_type_import.setCurrentIndex(0) |
| 477 | + assert ( |
| 478 | + setup["widget"].w_BH_import.c_type_import.currentText() |
| 479 | + == "Import from Excel" |
| 480 | + ) |
| 481 | + w_imp = setup["widget"].w_BH_import.w_import |
| 482 | + # Import the excel file |
| 483 | + with mock.patch( |
| 484 | + "PySide2.QtWidgets.QFileDialog.getOpenFileName", |
| 485 | + return_value=(excel_path, "Excel file (*.xls .*xlsx)"), |
| 486 | + ): |
| 487 | + w_imp.w_file_path.b_path.clicked.emit() |
| 488 | + assert w_imp.w_file_path.le_path.text() == excel_path |
| 489 | + # Check table |
| 490 | + assert w_imp.tab_window is None |
| 491 | + w_imp.b_tab.clicked.emit() |
| 492 | + w_imp.tab_window.si_row.value() == 4 |
| 493 | + w_imp.tab_window.si_col.value() == 2 |
| 494 | + w_imp.tab_window.w_tab.cellWidget(0, 0).value() == 0 |
| 495 | + w_imp.tab_window.w_tab.cellWidget(0, 1).value() == 1 |
| 496 | + w_imp.tab_window.w_tab.cellWidget(1, 0).value() == 2 |
| 497 | + w_imp.tab_window.w_tab.cellWidget(1, 1).value() == 100 |
| 498 | + w_imp.tab_window.w_tab.cellWidget(2, 0).value() == 3 |
| 499 | + w_imp.tab_window.w_tab.cellWidget(2, 1).value() == 300 |
| 500 | + w_imp.tab_window.w_tab.cellWidget(3, 0).value() == 5 |
| 501 | + w_imp.tab_window.w_tab.cellWidget(3, 1).value() == 800 |
0 commit comments