コード例 #1
0
    def setExecutablePath(self, app_path):
        """
        The user select a new executable path.
        Input:
            app_path: The path of the executable.
        """
        if not app_path:
            return

        self._loading_dialog.setInformativeText(app_path)
        self._loading_dialog.show()
        self._loading_dialog.raise_()
        QApplication.processEvents()

        app_info = ExecutableInfo()
        app_info.setPath(app_path, self.test_checkbox.isChecked())

        QApplication.processEvents()

        if app_info.valid():
            self.exe_line.setText(app_path)
            self.executableInfoChanged.emit(app_info)
            self.executableChanged.emit(app_path)
            files = self._exe_watcher.files()
            if files:
                self._exe_watcher.removePaths(files)
            self._exe_watcher.addPath(app_path)
        self._updateRecentExe(app_path, not app_info.valid())
        self._loading_dialog.hide()
コード例 #2
0
 def newWidget(self):
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     w = InputFileEditor()
     w.executableInfoChanged(app_info)
     w.setInputFile(self.test_input_file)
     return w
コード例 #3
0
 def newWidget(self):
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     w = InputFileEditor()
     w.executableInfoChanged(app_info)
     w.setInputFile(self.test_input_file)
     return w
コード例 #4
0
    def setExecutablePath(self, exe_path):
        self.exe_path = exe_path
        self.exe_info = ExecutableInfo()
        self.exe_info.setPath(self.exe_path)
        self.fillFluidProperties()

        for tab in range(self.ctlSinglePhaseWidget.count()):
            self.ctlSinglePhaseWidget.widget(tab).setExecutablePath(exe_path)
        for tab in range(self.ctlTwoPhaseWidget.count()):
            self.ctlTwoPhaseWidget.widget(tab).setExecutablePath(exe_path)
コード例 #5
0
    def testIncompatible(self):
        t = InputTree(ExecutableInfo())
        app_info = ExecutableInfo()
        # The original tree wasn't set, any new changes
        # are not incompatible
        self.assertFalse(t.incompatibleChanges(app_info))
        app_info.json_data = {"bad_block": None}
        self.assertFalse(t.incompatibleChanges(app_info))

        # Current tree is good, new one is not
        app_info.json_data = None
        t = self.createTree(input_file=self.simple_diffusion)
        self.assertTrue(t.incompatibleChanges(app_info))
        app_info.json_data = {"bad_block": None}
        self.assertFalse(app_info.valid())
        self.assertTrue(t.incompatibleChanges(app_info))
        app_info.path = "foo"
        self.assertTrue(app_info.valid())
        self.assertTrue(
            t.incompatibleChanges(app_info))  # No / which causes an exception
        app_info.path_map = t.app_info.path_map.copy()
        self.assertFalse(
            t.incompatibleChanges(app_info))  # Should be the same, no problems

        # Simulate removing /BCs/*/<types>/DirichletBC/boundary
        # This should be fine since users can have extra parameters
        # in their input file
        root = app_info.path_map["/"]
        bcs = root.children["BCs"]
        pname = "boundary"
        tmp = bcs.star_node.types["DirichletBC"]
        p = tmp.parameters[pname]
        p.user_added = True
        tmp.removeUserParam(pname)
        p = bcs.star_node.parameters[pname]
        p.user_added = True
        bcs.star_node.removeUserParam(pname)
        tmp_tree = InputTree(app_info)

        tmp_tree.setInputFileData(t.getInputFileString())
        left = tmp_tree.getBlockInfo("/BCs/left")
        self.assertTrue(left.user_added)
        boundary = left.parameters["boundary"]
        self.assertTrue(boundary.user_added)
        self.assertTrue(boundary.set_in_input_file)
        self.assertFalse(t.incompatibleChanges(app_info))

        # Simulate removing /BCs syntax
        # This should cause a problem
        del app_info.path_map["/BCs"]
        root.children_list.remove("BCs")
        del root.children["BCs"]
        self.assertTrue(t.incompatibleChanges(
            app_info))  # Errors when reading the input file
コード例 #6
0
 def testPickle(self):
     exe_path = Testing.find_moose_test_exe()
     e = ExecutableInfo()
     e.clearCache()
     e.setPath(exe_path)
     p = e.toPickle()
     e2 = ExecutableInfo()
     e2.fromPickle(p)
     self.assertEqual(e2.path_map, e.path_map)
コード例 #7
0
 def testCombined(self):
     e = ExecutableInfo()
     e.setPath(Testing.find_moose_test_exe(dirname="modules/combined", exe_base="combined"))
     self.checkPath(e, "/Preconditioning", True, True)
     self.checkPath(e, "/BCs", True, True)
     self.checkPath(e, "/BCs/Pressure", True, True)
     self.checkPath(e, "/Adaptivity", False, True)
     self.checkPath(e, "/Adaptivity/Markers", True, True)
     self.checkPath(e, "/GlobalParams", False, True)
     self.checkPath(e, "/Mesh", True, True)
     self.checkPath(e, "/AuxVariables", True, True)
     self.checkPath(e, "/AuxVariables/*/InitialCondition", False, False)
     self.checkPath(e, "/Variables/*/InitialCondition", False, False)
コード例 #8
0
 def testCombined(self):
     e = ExecutableInfo()
     e.setPath(Testing.find_moose_test_exe(dirname="modules/combined", exe_base="combined"))
     self.checkPath(e, "/Preconditioning", True, True)
     self.checkPath(e, "/BCs", True, True)
     self.checkPath(e, "/BCs/Pressure", True, True)
     self.checkPath(e, "/SolidMechanics", True, True)
     self.checkPath(e, "/Adaptivity", False, True)
     self.checkPath(e, "/Adaptivity/Markers", True, True)
     self.checkPath(e, "/GlobalParams", False, True)
     self.checkPath(e, "/Mesh", False, True)
     self.checkPath(e, "/AuxVariables", True, True)
     self.checkPath(e, "/AuxVariables/*/InitialCondition", False, False)
     self.checkPath(e, "/Variables/*/InitialCondition", False, False)
コード例 #9
0
 def newWidget(self):
     main_win = QMainWindow()
     w = InputFileEditorWithMesh(size=[640,640])
     main_win.setCentralWidget(w)
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     w.onExecutableInfoChanged(app_info)
     menubar = main_win.menuBar()
     menubar.setNativeMenuBar(False)
     w.addToMainMenu(menubar)
     w.setEnabled(True)
     main_win.show()
     w.numTimeStepsChanged.connect(self.timeStepChanged)
     return main_win, w
コード例 #10
0
 def newWidget(self):
     main_win = QMainWindow()
     w = InputFileEditorWithMesh(size=[640,640])
     main_win.setCentralWidget(w)
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     w.onExecutableInfoChanged(app_info)
     menubar = main_win.menuBar()
     menubar.setNativeMenuBar(False)
     w.addToMainMenu(menubar)
     w.setEnabled(True)
     main_win.show()
     w.numTimeStepsChanged.connect(self.timeStepChanged)
     return main_win, w
コード例 #11
0
 def setUp(self):
     super(Tests, self).setUp()
     self.test_input_file = "../../common/fsp_test.i"
     self.app_info = ExecutableInfo()
     self.app_info.setPath(Testing.find_moose_test_exe())
     self.tree = InputTree(self.app_info)
     self.tree.setInputFile(self.test_input_file)
     self.assertTrue(self.app_info.valid())
     self.block_list_requested = 0
     self.block_removed_count = 0
     self.last_block_removed = 0
     self.block_cloned_count = 0
     self.last_block_cloned = 0
     self.editing_finished = False
     self.block_changed_count = 0
     self.last_block_changed = 0
コード例 #12
0
 def createWidget(self, args=[], csv_enabled=False):
     w = ExecuteRunnerPlugin()
     exe_info = ExecutableInfo()
     exe_info.setPath(self.test_exe)
     tree = InputTree(exe_info)
     tree.setInputFile(self.test_input_file)
     num_steps = TimeStepEstimate.findTimeSteps(tree)
     w.onNumTimeStepsChanged(num_steps)
     self.assertEqual(w._total_steps, 8)
     w.needCommand.connect(lambda: self.needCommand(w, args, csv_enabled))
     w.needInputFile.connect(self.needInputFile)
     w.outputAdded.connect(self.outputAdded)
     w.runProgress.connect(self.runProgress)
     w.startJob.connect(self.startJob)
     w.setEnabled(True)
     return w
コード例 #13
0
 def createWidget(self, args=[], csv_enabled=False):
     w = ExecuteRunnerPlugin()
     exe_info = ExecutableInfo()
     exe_info.setPath(self.test_exe)
     tree = InputTree(exe_info)
     tree.setInputFile(self.test_input_file)
     num_steps = TimeStepEstimate.findTimeSteps(tree)
     w.onNumTimeStepsChanged(num_steps)
     self.assertEqual(w._total_steps, 8)
     w.needCommand.connect(lambda: self.needCommand(w, args, csv_enabled))
     w.needInputFile.connect(self.needInputFile)
     w.outputAdded.connect(self.outputAdded)
     w.runProgress.connect(self.runProgress)
     w.startJob.connect(self.startJob)
     w.setEnabled(True)
     return w
コード例 #14
0
    def setExecutablePath(self, app_path):
        """
        The user select a new executable path.
        Input:
            app_path: The path of the executable.
        """
        if not app_path:
            return

        self._loading_dialog.setInformativeText(app_path)
        self._loading_dialog.show()
        self._loading_dialog.raise_()
        QApplication.processEvents()

        app_info = ExecutableInfo()
        app_info.setPath(app_path, self.test_checkbox.isChecked())

        QApplication.processEvents()

        if app_info.valid():
            self.exe_line.setText(app_path)
            self.executableInfoChanged.emit(app_info)
            self.executableChanged.emit(app_path)
            files = self._exe_watcher.files()
            if files:
                self._exe_watcher.removePaths(files)
            self._exe_watcher.addPath(app_path)
        if self._force_reload_action:
            self._force_reload_action.setEnabled(app_info.valid())
        self._updateRecentExe(app_path, not app_info.valid())
        self._loading_dialog.hide()
コード例 #15
0
ファイル: test_InputTree.py プロジェクト: mbairdphys/moose
 def createTree(self, valid=True, input_file=None):
     if valid:
         e = self.createExeInfo()
     else:
         e = ExecutableInfo()
     t = InputTree(e)
     if input_file:
         t.setInputFile(input_file)
     return t
コード例 #16
0
 def newWidget(self, app_init=True):
     main_win = QMainWindow()
     w = InputFileEditorPlugin()
     main_win.setCentralWidget(w)
     main_win.show()
     app_info = ExecutableInfo()
     if app_init:
         app_info.setPath(Testing.find_moose_test_exe())
         self.assertTrue(app_info.valid())
     menubar = main_win.menuBar()
     menubar.setNativeMenuBar(False)
     menu = menubar.addMenu("Input File")
     w.addToMenu(menu)
     w.clearRecentlyUsed()
     self.checkMenus(w, False)
     main_win.show()
     w.executableInfoChanged(app_info)
     w.blockChanged.connect(self.blockChanged)
     return main_win, w
コード例 #17
0
 def newWidget(self, app_init=True):
     main_win = QMainWindow()
     w = InputFileEditorPlugin()
     main_win.setCentralWidget(w)
     main_win.show()
     app_info = ExecutableInfo()
     if app_init:
         app_info.setPath(Testing.find_moose_test_exe())
         self.assertTrue(app_info.valid())
     menubar = main_win.menuBar()
     menubar.setNativeMenuBar(False)
     menu = menubar.addMenu("Input File")
     w.addToMenu(menu)
     w.clearRecentlyUsed()
     self.checkMenus(w, False)
     main_win.show()
     w.executableInfoChanged(app_info)
     w.blockChanged.connect(self.blockChanged)
     return main_win, w
コード例 #18
0
ファイル: test_InputTree.py プロジェクト: zachmprince/moose
    def testIncompatible(self):
        t = InputTree(ExecutableInfo())
        app_info = ExecutableInfo()
        # The original tree wasn't set, any new changes
        # are not incompatible
        self.assertFalse(t.incompatibleChanges(app_info))
        app_info.json_data = {"bad_block": None}
        self.assertFalse(t.incompatibleChanges(app_info))

        # Current tree is good, new one is not
        app_info.json_data = None
        t = self.createTree(input_file=self.simple_diffusion)
        self.assertTrue(t.incompatibleChanges(app_info))
        app_info.json_data = {"bad_block": None}
        self.assertFalse(app_info.valid())
        self.assertTrue(t.incompatibleChanges(app_info))
        app_info.path ="foo"
        self.assertTrue(app_info.valid())
        self.assertTrue(t.incompatibleChanges(app_info)) # No / which causes an exception
        app_info.path_map = t.app_info.path_map.copy()
        self.assertFalse(t.incompatibleChanges(app_info)) # Should be the same, no problems

        # Simulate removing /BCs/*/<types>/DirichletBC/boundary
        # This should be fine since users can have extra parameters
        # in their input file
        root = app_info.path_map["/"]
        bcs = root.children["BCs"]
        pname = "boundary"
        tmp = bcs.star_node.types["DirichletBC"]
        p = tmp.parameters[pname]
        p.user_added = True
        tmp.removeUserParam(pname)
        p = bcs.star_node.parameters[pname]
        p.user_added = True
        bcs.star_node.removeUserParam(pname)
        tmp_tree = InputTree(app_info)

        tmp_tree.setInputFileData(t.getInputFileString())
        left = tmp_tree.getBlockInfo("/BCs/left")
        self.assertTrue(left.user_added)
        boundary = left.parameters["boundary"]
        self.assertTrue(boundary.user_added)
        self.assertTrue(boundary.set_in_input_file)
        self.assertFalse(t.incompatibleChanges(app_info))

        # Simulate removing /BCs syntax
        # This should cause a problem
        del app_info.path_map["/BCs"]
        root.children_list.remove("BCs")
        del root.children["BCs"]
        self.assertTrue(t.incompatibleChanges(app_info)) # Errors when reading the input file
コード例 #19
0
    def testTree(self):
        e = ExecutableInfo()
        e.clearCache()
        exe_path = Testing.find_moose_test_exe()
        e.setPath(exe_path)
        root = e.path_map["/"]
        self.assertIn("Mesh", root.children_list)
        m = root.children["Mesh"]
        self.assertEqual(m.hard, True)
        self.assertEqual(e.path_map["/Mesh"], m)

        out = e.dumpDefaultTree(hard_only=False)
        self.assertIn("Partitioner", out)
        self.assertIn("Partitioner", out)
        self.assertIn("ScalarKernels", out)
        self.assertNotIn("DirichletBC", out)
コード例 #20
0
 def newWidget(self, modules=False):
     app_info = ExecutableInfo()
     if modules:
         app_info.setPath(Testing.find_moose_test_exe(dirname="modules/combined", exe_base="combined"))
     else:
         app_info.setPath(Testing.find_moose_test_exe())
     tree = InputTree(app_info)
     tree.setInputFile(self.test_input_file)
     w = BlockTree(tree)
     w.changed.connect(self.changed)
     w.blockSelected.connect(self.blockSelected)
     w.blockClicked.connect(self.blockClicked)
     w.blockDoubleClicked.connect(self.blockDoubleClicked)
     #w.show()
     #w.raise_()
     return w
コード例 #21
0
    def testTree(self):
        e = ExecutableInfo()
        e.clearCache()
        exe_path = Testing.find_moose_test_exe()
        e.setPath(exe_path)
        root = e.path_map["/"]
        self.assertIn("Mesh", root.children_list)
        m = root.children["Mesh"]
        self.assertEqual(m.hard, True)
        self.assertEqual(e.path_map["/Mesh"], m)

        out = e.dumpDefaultTree(hard_only=False)
        self.assertIn("Partitioner", out)
        self.assertIn("Partitioner", out)
        self.assertIn("ScalarKernels", out)
        self.assertNotIn("DirichletBC", out)
コード例 #22
0
ファイル: ExecuteOptionsPlugin.py プロジェクト: cuiwm/moose
    def setExecutablePath(self, app_path):
        """
        The user select a new executable path.
        Input:
            app_path: The path of the executable.
        """
        if not app_path:
            return

        app_info = ExecutableInfo()
        app_info.setPath(app_path)
        if app_info.valid():
            self.exe_line.setText(app_path)
            self.executableInfoChanged.emit(app_info)
            self.executableChanged.emit(app_path)
        self._updateRecentExe(app_path, not app_info.valid())
コード例 #23
0
ファイル: test_InputTree.py プロジェクト: mbairdphys/moose
 def createExeInfo(self):
     e = ExecutableInfo()
     e.setPath(Testing.find_moose_test_exe(dirname="modules/combined", exe_base="combined"))
     return e
コード例 #24
0
    def testInfo(self):
        e = ExecutableInfo()
        e.clearCache()
        e.setPath("")
        self.assertFalse(e.valid())
        e.setPath("no_exist")
        self.assertFalse(e.valid())

        exe_path = Testing.find_moose_test_exe()
        e.setPath(exe_path)
        self.assertTrue(e.valid())

        e.setPath(exe_path)
        self.assertTrue(e.valid())

        e.setPath("")
        self.assertTrue(e.valid())

        e.setPath("no_exist")
        self.assertFalse(e.valid())

        # this should hit the cache
        e.setPath(exe_path)
        self.assertTrue(e.valid())
コード例 #25
0
 def testPickle(self):
     exe_path = Testing.find_moose_test_exe()
     e = ExecutableInfo()
     e.clearCache()
     e.setPath(exe_path)
     p = e.toPickle()
     e2 = ExecutableInfo()
     e2.fromPickle(p)
     self.assertEqual(e2.path_map, e.path_map)
コード例 #26
0
 def create_tree(self):
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     input_tree = InputTree(app_info)
     return input_tree
コード例 #27
0
 def createBasic(self):
     e = ExecutableInfo()
     e.setPath(Testing.find_moose_test_exe())
     t = InputTree(e)
     t.setInputFile(self.basic_input)
     return t
コード例 #28
0
class FluidPropertyInterrogatorPlugin(QtWidgets.QWidget):
    """
    Fluid property interrogator GUI
    """

    SINGLE_PHASE = 1
    TWO_PHASE = 2
    TWO_PHASE_NCG = 3

    def __init__(self, **kwargs):
        super(FluidPropertyInterrogatorPlugin, self).__init__(**kwargs)

        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        self.layoutMain = QVBoxLayout(self)

        self.ctlFPType = QComboBox(self)
        self.layoutMain.addWidget(self.ctlFPType)

        self.layoutFPParams = QStackedLayout()
        self.ctlSinglePhaseWidget = self.setupSinglePhaseUI(self.layoutFPParams)
        self.ctlTwoPhaseWidget = self.setupTwoPhaseUI(self.layoutFPParams)
        self.layoutFPParams.addWidget(self.ctlSinglePhaseWidget)
        self.layoutFPParams.addWidget(self.ctlTwoPhaseWidget)
        self.layoutMain.addLayout(self.layoutFPParams)

        self.ctlFPType.currentIndexChanged.connect(self.onFluidPropertyChanged)

    def setupSinglePhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget1PhasePT(self), "p, T")
        widget.addTab(FluidPropertyWidget1PhaseRhoE(self), "rho, e")
        widget.addTab(FluidPropertyWidget1PhaseRhoP(self), "rho, p")
        return widget

    def setupTwoPhaseUI(self, layout):
        widget = QTabWidget(self)
        widget.addTab(FluidPropertyWidget2PhaseP(self), "p")
        widget.addTab(FluidPropertyWidget2PhaseT(self), "T")
        return widget

    def fillFluidProperties(self):
        """
        Fill the combo box with single phase fluid property classes
        """

        fp_classes = [
            {
                'name': 'Single phase',
                'classes': [],
                'data': self.SINGLE_PHASE
            },
            {
                'name': 'Two phase',
                'classes': [],
                'data': self.TWO_PHASE
            }
        ]

        json_fps = self.exe_info.json_data.json_data["blocks"]['Modules']['subblocks']['FluidProperties']['star']['subblock_types']

        for class_name, vals in json_fps.items():
            params = vals['parameters']
            if 'fp_type' in params:
                fp_type = params['fp_type']['default']
                if fp_type == 'single-phase-fp':
                    fp_classes[0]['classes'].append(class_name)
                elif fp_type == 'two-phase-fp':
                    fp_classes[1]['classes'].append(class_name)

        for fpc in fp_classes:
            fpc['classes'].sort()

        sep_indices = []
        model = QStandardItemModel()
        for fpc in fp_classes:
            parent = QStandardItem(fpc['name'])
            parent.setEnabled(False)
            model.appendRow(parent)
            for c in fpc['classes']:
                item = QStandardItem(c)
                item.setData(fpc['data'])
                model.appendRow(item)
            sep_indices.append(model.rowCount())

        self.ctlFPType.setModel(model)
        for idx in sep_indices[:-1]:
            self.ctlFPType.insertSeparator(idx)

    def onFluidPropertyChanged(self, index):
        fp_type = self.ctlFPType.model().item(index).data()
        if fp_type == self.SINGLE_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlSinglePhaseWidget)
            self.ctlSinglePhaseWidget.currentWidget().updateWidgets()
        elif fp_type == self.TWO_PHASE:
            self.layoutFPParams.setCurrentWidget(self.ctlTwoPhaseWidget)
            self.ctlTwoPhaseWidget.currentWidget().updateWidgets()
        else:
            raise SystemExit("Unknown fp_type")

    def fluidPropertyInputFileBlock(self):
        str = ""
        str += "[./fp]\n"
        str += "type = {}\n".format(self.ctlFPType.currentText())
        str += "[../]\n"
        return str

    def setExecutablePath(self, exe_path):
        self.exe_path = exe_path
        self.exe_info = ExecutableInfo()
        self.exe_info.setPath(self.exe_path)
        self.fillFluidProperties()

        for tab in range(self.ctlSinglePhaseWidget.count()):
            self.ctlSinglePhaseWidget.widget(tab).setExecutablePath(exe_path)
        for tab in range(self.ctlTwoPhaseWidget.count()):
            self.ctlTwoPhaseWidget.widget(tab).setExecutablePath(exe_path)
コード例 #29
0
class Tests(Testing.PeacockTester):
    qapp = QApplication([])

    def setUp(self):
        super(Tests, self).setUp()
        self.test_input_file = "../../common/fsp_test.i"
        self.app_info = ExecutableInfo()
        self.app_info.setPath(Testing.find_moose_test_exe())
        self.tree = InputTree(self.app_info)
        self.tree.setInputFile(self.test_input_file)
        self.assertTrue(self.app_info.valid())
        self.block_list_requested = 0
        self.block_removed_count = 0
        self.last_block_removed = 0
        self.block_cloned_count = 0
        self.last_block_cloned = 0
        self.editing_finished = False
        self.block_changed_count = 0
        self.last_block_changed = 0

    def newWidget(self, path):
        b = self.tree.getBlockInfo(path)
        e = BlockEditor(b, self.tree.app_info.type_to_block_map)
        e.needBlockList.connect(lambda paths: self.needBlockList(e, paths))
        e.removeBlock.connect(self.removeBlock)
        e.cloneBlock.connect(self.cloneBlock)
        e.blockChanged.connect(self.blockChanged)
        e.editingFinished.connect(self.editingFinished)
        self.editing_finished = False
        return e

    def blockChanged(self, block):
        self.block_changed_count += 1
        self.last_block_changed = block

    def editingFinished(self):
        self.editing_finished = True

    def removeBlock(self, block):
        self.block_removed_count += 1
        self.last_block_removed = block

    def cloneBlock(self, block):
        self.block_cloned_count += 1
        self.last_block_cloned = block

    def needBlockList(self, e, blocks):
        self.block_list_requested += 1
        for b in blocks:
            e.setWatchedBlockList(b, ["child0", "child1", "child2"])

    def newCounter(self, node):
        self.new_node = node
        self.new_node_counter += 1

    def checkParamEditor(self, e, has_params, has_types):
        if has_types:
            self.assertTrue(isinstance(e.param_editor, ParamsByType))
        elif has_params:
            self.assertTrue(isinstance(e.param_editor, ParamsByGroup))
        else:
            self.assertTrue(isinstance(e.param_editor, ParamsTable))

    def checkButton(self, button, exists, enabled):
        if button is None:
            self.assertTrue(button is None and not exists)
        else:
            self.assertTrue(button is not None and exists)
        if button:
            self.assertEqual(button.isEnabled(), enabled)

    def checkWidget(self,
            e,
            apply_button=True,
            apply_enabled=False,
            user_block=False,
            reset_button=True,
            reset_enabled=False,
            new_param_button=True,
            new_param_enabled=True,
            has_params=False,
            has_types=False,
            comments=""
            ):
        self.checkParamEditor(e, has_params, has_types)
        self.checkButton(e.clone_button, user_block, True)
        self.checkButton(e.apply_button, apply_button, apply_enabled)
        self.checkButton(e.remove_button, user_block, True)
        self.checkButton(e.reset_button, reset_button, reset_enabled)
        self.checkButton(e.new_parameter_button, new_param_button, new_param_enabled)
        self.assertEqual(e.comment_edit.getComments(), comments)

    def testBlockComments(self):
        b = BlockInfo(None, "/Foo", True, "")
        c = "some comments"
        e = BlockEditor(b, self.tree.app_info.type_to_block_map)
        self.checkWidget(e)
        self.assertEqual(b.comments, "")
        e.comment_edit.setComments(c)
        self.checkWidget(e, apply_enabled=True, reset_enabled=True, comments=c)
        # This should get updated after apply is pressed
        self.assertEqual(b.comments, "")
        e.applyChanges()
        self.assertEqual(b.comments, c)
        self.checkWidget(e, comments=c)

        e.resetChanges()
        self.checkWidget(e, comments=c)

        e.comment_edit.setComments("")
        self.checkWidget(e, apply_enabled=True, reset_enabled=True, comments="")
        self.assertEqual(b.comments, c)
        e.resetChanges()
        self.checkWidget(e, comments=c)
        self.assertEqual(b.comments, c)


    def testUserParams(self):
        b = BlockInfo(None, "/Foo", True, "")
        e = BlockEditor(b, self.tree.app_info.type_to_block_map)
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 0)
        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True)
        self.assertEqual(len(b.parameters_list), 0)

        e.applyChanges()
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 1)

        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True)
        self.assertEqual(len(b.parameters_list), 1)

        e.resetChanges()
        self.checkWidget(e)
        self.assertEqual(len(b.parameters_list), 1)

    def testClone(self):
        e = self.newWidget("/Kernels/diff_u")
        self.checkWidget(e, has_types=True, user_block=True)
        e._cloneBlock()
        self.assertEqual(self.block_cloned_count, 1)
        self.assertEqual(self.last_block_cloned, e.block)

    @patch.object(QMessageBox, "question")
    def testRemoveBlock(self, mock_box):
        mock_box.return_value = QMessageBox.No
        e = self.newWidget("/Kernels/diff_u")
        self.checkWidget(e, has_types=True, user_block=True)
        e._removeBlock()
        self.assertEqual(self.block_removed_count, 0)

        mock_box.return_value = QMessageBox.Yes
        self.assertEqual(self.editing_finished, False)
        e._removeBlock()
        self.assertEqual(self.block_removed_count, 1)
        self.assertEqual(self.last_block_removed, e.block)
        self.assertEqual(self.editing_finished, True)

    def checkAddParam(self, path, has_types, has_params, user=False):
        e = self.newWidget(path)
        b = e.block
        num_params = len(b.parameters_list)
        self.checkWidget(e, has_types=has_types, has_params=has_params, user_block=user)
        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True, has_types=has_types, has_params=has_params, user_block=user)
        self.assertEqual(len(b.parameters_list), num_params)

        e.applyChanges()
        self.checkWidget(e, has_types=has_types, has_params=has_params, user_block=user)
        self.assertEqual(len(b.parameters_list), num_params+1)
        p = b.getParamInfo(b.parameters_list[-1])
        self.assertNotEqual(p, None)
        self.assertEqual(p.value, "")

        e.addUserParamPressed()
        self.checkWidget(e, apply_enabled=True, reset_enabled=True, has_types=has_types, has_params=has_params, user_block=user)
        self.assertEqual(len(b.parameters_list), num_params+1)

        e.resetChanges()
        self.checkWidget(e, has_types=has_types, has_params=has_params, user_block=user)
        self.assertEqual(len(b.parameters_list), num_params+1)

        self.assertEqual(self.editing_finished, False)
        e.close()
        self.assertEqual(self.editing_finished, True)

    def testAddParams(self):
        # has no types, is not a star, and no default params
        self.checkAddParam("/GlobalParams", False, False)
        # Has types
        self.checkAddParam("/Mesh", True, True)
        # Is star node, had an 'active' parameter but we get rid of it
        self.checkAddParam("/Kernels", False, False)
        # Is user block
        self.checkAddParam("/Kernels/diff_u", True, True, True)
コード例 #30
0
 def create_tree(self):
     app_info = ExecutableInfo()
     app_info.setPath(Testing.find_moose_test_exe())
     self.assertTrue(app_info.valid())
     input_tree = InputTree(app_info)
     return input_tree
コード例 #31
0
    def testInfo(self):
        e = ExecutableInfo()
        e.clearCache()
        e.setPath("")
        self.assertFalse(e.valid())
        e.setPath("no_exist")
        self.assertFalse(e.valid())

        exe_path = Testing.find_moose_test_exe()
        e.setPath(exe_path)
        self.assertTrue(e.valid())

        e.setPath(exe_path)
        self.assertTrue(e.valid())

        e.setPath("")
        self.assertTrue(e.valid())

        e.setPath("no_exist")
        self.assertFalse(e.valid())

        # this should hit the cache
        e.setPath(exe_path)
        self.assertTrue(e.valid())