Beispiel #1
0
class test_Workflow_DMatLib(TestCase):
    """Test that the widget DMatLib behave like it should when called from a Widget
    """
    def setUp(self):
        """Run at the begining of every test to create the workspace
        """
        self.work_path = join(save_path, "Material Workflow")
        # Delete old test if needed
        if isdir(self.work_path):
            rmtree(self.work_path)
        mkdir(self.work_path)
        copyfile(
            join(DATA_DIR, "Material", "Magnet1.json"),
            join(self.work_path, "Magnet1.json"),
        )
        copyfile(
            join(DATA_DIR, "Material", "Copper1.json"),
            join(self.work_path, "Copper1.json"),
        )
        copyfile(
            join(DATA_DIR, "Material", "Insulator1.json"),
            join(self.work_path, "Insulator1.json"),
        )
        copyfile(
            join(DATA_DIR, "Material", "M400-50A.json"),
            join(self.work_path, "M400-50A.json"),
        )
        self.matlib = load_matlib(self.work_path)

    def teardown(self):
        """Delete the workspace at the end of the tests
        """
        if is_clean_result:
            rmtree(self.work_path)

    @classmethod
    def setUpClass(cls):
        """Start the app for the test"""
        print("\nStart Test Workflow MatLib")
        cls.app = QtWidgets.QApplication(sys.argv)

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

    def test_init_empty(self):
        """Check that the widget can open with an unknown material
        """
        self.machine = MachineIPMSM()
        self.machine.stator = LamSlotWind()
        self.machine.rotor = LamHole()
        self.machine._set_None()
        self.machine.stator.winding.p = 4
        self.machine.type_machine = 8
        self.machine.rotor.hole = [HoleM50()]
        self.machine.rotor.hole[
            0].magnet_0.mat_type.name = "Magnet_doesnot_exist"
        self.widget = SMHoleMag(machine=self.machine,
                                matlib=self.matlib,
                                is_stator=False)

        # Check default material
        self.assertEqual(self.widget.w_mat.c_mat_type.count(), 4)
        self.assertEqual(self.widget.w_mat.c_mat_type.currentText(), "")
        self.assertEqual(self.widget.w_mat.c_mat_type.currentIndex(), -1)
        # Click to open matlib
        self.assertFalse(hasattr(self.widget, "mat_win"))
        self.widget.w_mat.b_matlib.clicked.emit()
        self.assertEqual(type(self.widget.w_mat.mat_win), DMatLib)
        # Check Matlib init
        self.assertEqual(self.widget.w_mat.mat_win.nav_mat.count(), 4)
        self.assertEqual(
            self.widget.w_mat.mat_win.nav_mat.currentItem().text(),
            "001 - Copper1")

    def test_init(self):
        """Check that the Widget spinbox initialise to the lamination value
        """
        self.machine = MachineIPMSM()
        self.machine.stator = LamSlotWind()
        self.machine.rotor = LamHole()
        self.machine._set_None()
        self.machine.stator.winding.p = 4
        self.machine.type_machine = 8
        self.widget = SMHoleMag(machine=self.machine,
                                matlib=self.matlib,
                                is_stator=False)

        # Check default (hole is set to type 50)
        self.assertEqual(self.widget.w_mat.c_mat_type.count(), 4)
        self.assertEqual(self.widget.w_mat.c_mat_type.currentText(), "Magnet1")
        self.assertEqual(self.widget.w_mat.c_mat_type.currentIndex(), 3)
        # Click to open matlib
        self.assertFalse(hasattr(self.widget, "mat_win"))
        self.widget.w_mat.b_matlib.clicked.emit()
        self.assertEqual(type(self.widget.w_mat.mat_win), DMatLib)
        # Check Matlib init
        self.assertEqual(self.widget.w_mat.mat_win.nav_mat.count(), 4)
        self.assertEqual(
            self.widget.w_mat.mat_win.nav_mat.currentItem().text(),
            "004 - Magnet1")
        # Duplicate Magnet1
        self.assertFalse(hasattr(self.widget.w_mat.mat_win, "mat_win"))
        self.widget.w_mat.mat_win.b_duplicate.clicked.emit()
        self.assertEqual(type(self.widget.w_mat.mat_win.mat_win), DMatSetup)
        # Edit Magnet1 to Magnet_test
        self.widget.w_mat.mat_win.mat_win.le_name.setText("Magnet_test_python")
        self.widget.w_mat.mat_win.mat_win.le_name.editingFinished.emit()
        self.assertEqual(self.widget.w_mat.mat_win.mat_win.mat.name,
                         "Magnet_test_python")

        self.widget.w_mat.mat_win.mat_win.lf_rho_elec.setText("1234.56789")
        self.widget.w_mat.mat_win.mat_win.lf_rho_elec.editingFinished.emit()
        self.assertEqual(self.widget.w_mat.mat_win.mat_win.mat.elec.rho,
                         1234.56789)
Beispiel #2
0
machine6.rotor.slot.magnet = [MagnetType11()]
machine6._set_None()  # Empty machine
machine6.type_machine = 6
machine6.stator.is_stator = True
machine6.rotor.is_stator = False

machine7 = MachineSIPMSM(init_dict=machine6.as_dict())
machine7.type_machine = 7

machine8 = MachineIPMSM()
machine8.stator = LamSlotWind()
machine8.stator.winding = WindingDW2L()
machine8.rotor = LamHole()
machine8.rotor.hole = list()
machine8.rotor.hole.append(HoleM50())
machine8._set_None()  # Empty machine
machine8.type_machine = 8
machine8.stator.is_stator = True
machine8.rotor.is_stator = False

machine9 = MachineWRSM()
machine9.stator = LamSlotWind()
machine9.stator.winding = WindingDW2L()
machine9.rotor = LamSlotWind()
machine9.rotor.winding = WindingCW2LT()
machine9._set_None()  # Empty machine
machine9.type_machine = 9
machine9.stator.is_stator = True
machine9.rotor.is_stator = False

machine10 = MachineSRM()