Exemplo n.º 1
0
 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
 def testBasic(self):
     main_win, w = self.newWidget()
     w.ExecuteOptionsPlugin.setExecutablePath(self.test_exe)
     self.assertEqual(w.ExecuteRunnerPlugin.run_button.isEnabled(), True)
     self.assertEqual(self.exe_info.valid(), True)
     self.assertEqual(w.ConsoleOutputViewerPlugin.toPlainText(), "")
     w.ExecuteRunnerPlugin.runClicked()
     self.assertEqual(self.start_input_file, self.input_file)
     self.assertEqual(self.start_csv, True)
     w.ExecuteRunnerPlugin.runner.process.waitForFinished(-1)
     self.assertNotEqual(w.ConsoleOutputViewerPlugin.toPlainText(), "")
     tree = InputTree(self.exe_info)
     tree.setInputFile(self.test_input_file)
     num_steps = TimeStepEstimate.findTimeSteps(tree)
     w.onNumTimeStepsChanged(num_steps)
Exemplo n.º 3
0
 def testBasic(self):
     main_win, w = self.newWidget()
     w.ExecuteOptionsPlugin.setExecutablePath(self.test_exe)
     self.assertEqual(w.ExecuteRunnerPlugin.run_button.isEnabled(), True)
     self.assertEqual(self.exe_info.valid(), True)
     self.assertEqual(w.ConsoleOutputViewerPlugin.toPlainText(), "")
     w.ExecuteRunnerPlugin.runClicked()
     self.assertEqual(self.start_input_file, self.input_file)
     self.assertEqual(self.start_csv, True)
     w.ExecuteRunnerPlugin.runner.process.waitForFinished(-1)
     self.assertNotEqual(w.ConsoleOutputViewerPlugin.toPlainText(), "")
     tree = InputTree(self.exe_info)
     tree.setInputFile(self.test_input_file)
     num_steps = TimeStepEstimate.findTimeSteps(tree)
     w.onNumTimeStepsChanged(num_steps)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
 def testOptions(self):
     main_win, w = self.newWidget()
     w.ExecuteOptionsPlugin.setExecutablePath(self.test_exe)
     self.assertEqual(w.ExecuteRunnerPlugin.run_button.isEnabled(), True)
     self.assertEqual(self.exe_info.valid(), True)
     self.assertEqual(w.ConsoleOutputViewerPlugin.toPlainText(), "")
     QTest.mouseClick(w.ExecuteOptionsPlugin.mpi_checkbox, Qt.LeftButton)
     QTest.mouseClick(w.ExecuteOptionsPlugin.threads_checkbox, Qt.LeftButton)
     w.ExecuteRunnerPlugin.runClicked()
     self.assertEqual(self.start_input_file, self.input_file)
     self.assertEqual(self.start_csv, True)
     w.ExecuteRunnerPlugin.runner.process.waitForFinished(-1)
     output = w.ConsoleOutputViewerPlugin.toPlainText()
     self.assertNotEqual(output, "")
     m = re.search("Num Processors:\s*2", output)
     self.assertIsNotNone(m)
     m = re.search("Num Threads:\s*2", output)
     self.assertIsNotNone(m)
     tree = InputTree(self.exe_info)
     tree.setInputFile(self.test_input_file)
     num_steps = TimeStepEstimate.findTimeSteps(tree)
     w.onNumTimeStepsChanged(num_steps)
Exemplo n.º 9
0
 def createBasic(self):
     e = ExecutableInfo()
     e.setPath(Testing.find_moose_test_exe())
     t = InputTree(e)
     t.setInputFile(self.basic_input)
     return t
Exemplo n.º 10
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)
Exemplo n.º 11
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
Exemplo n.º 12
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