def test_loading_non_existing_tools(self): self.assertEqual(self.tools_collection.count(), 0, "Tools collection was not empty") tool = getCmdTool('add') self.assertEqual(self.tools_collection.count(), 1, "Add tool was not added to Tools collection") tool = getCmdTool('add') self.assertLessEqual(self.tools_collection.count(), 1, "Add tool was added to Tools collection again") tool = getCmdTool('addList') self.assertEqual(self.tools_collection.count(), 2, "addlist tool was not added to Tools collection")
def test_paraview_disp_run(self): aWorkflow = caeml.common.workflow.Workflow() deckCreationTool = pvdispwarp.ParaviewDispWarpX3DTool() deckCreationStep = caeml.common.workflow.Step(name='step1', process=deckCreationTool, parent=aWorkflow) aWorkflow.steps['step1'] = deckCreationStep # set values deckCreationStep.inputPorts['mesh'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/', 'beam_output.rmed')) paraviewStep = caeml.common.workflow.Step(name='step2', process=getCmdTool('PvBatch'), parent=aWorkflow) aWorkflow.steps['step2'] = paraviewStep # set values paraviewStep.inputPorts['script_file'].setSource(deckCreationStep.outputPorts['script_file']) paraviewStep.inputPorts['mesh_file'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/', 'beam_output.rmed')) # set values state = caeml.runner.runner_local_pool.executeAsync(aWorkflow) res_file = state.findPortState(paraviewStep.outputPorts['results']).getEvaluation() self.assertTrue(True)
def test_code_aster_runner(self): aWorkflow = caeml.common.workflow.Workflow() codeAsterStep = caeml.common.workflow.Step( name='step1', process=getCmdTool('CodeAster'), parent=aWorkflow) aWorkflow.steps['step1'] = codeAsterStep # set values codeAsterStep.inputPorts['export_file'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/beam.export')) codeAsterStep.inputPorts['comm_file'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/beam.comm')) codeAsterStep.inputPorts['mesh_file'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/beam.med')) # set values state = caeml.runner.runner_local_pool.executeAsync(aWorkflow) res_file = state.findPortState( codeAsterStep.outputPorts['plain_mesh']).getEvaluation() res_stress = state.findPortState( codeAsterStep.outputPorts['resu_file']).getEvaluation() # binary res_file: only check that it exists self.assertTrue(os.path.exists(res_file.path)) with open(res_stress.path) as current_file: content = current_file.read() self.assertTrue('TOTAL_JOB' in content) self.assertTrue('VALEUR MAXIMALE DE INVA_2' in content) self.assertTrue(True)
def test_saved_dict_of_tool(self): tool = getCmdTool('post_processing/x3dexport_clip') loaded_tool = self.tools_collection.find_one( {'name': 'x3dExport_Clip'}) assert isinstance(tool, CommandLineTool) self.assertEqual(tool._id, loaded_tool['_id']) self.assertEqual(tool.name, loaded_tool['name']) self.assertEqual(tool.baseCommand, loaded_tool['baseCommand']) self.assertEqual(tool.processClass, loaded_tool['processClass']) tool_dict = tool.getCaemlDict_Recursive() self.assertTrue( tool_dict['inputParameters'] == loaded_tool['inputParameters']) self.assertTrue( tool_dict['outputParameters'] == loaded_tool['outputParameters'])
def test_whole_workflow(self): aWorkflow = caeml.common.workflow.Workflow() deckCreationTool = CodeAsterBeamDemoTool() deckCreationStep = caeml.common.workflow.Step(name='step1', process=deckCreationTool, parent=aWorkflow) aWorkflow.steps['step1'] = deckCreationStep # set values deckCreationStep.inputPorts['mesh'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/', 'beam.med')) deckCreationStep.inputPorts['youngs_modulus'].fixed_value = 2.1e+11 deckCreationStep.inputPorts['force'].fixed_value = 1200000001 codeAsterStep = caeml.common.workflow.Step( name='step2', process=getCmdTool('CodeAster'), parent=aWorkflow) aWorkflow.steps['step2'] = codeAsterStep codeAsterStep.inputPorts['export_file'].setSource( deckCreationStep.outputPorts['export_file']) codeAsterStep.inputPorts['comm_file'].setSource( deckCreationStep.outputPorts['comm_file']) codeAsterStep.inputPorts['mesh_file'].fixed_value = File( os.path.join(os.path.abspath(os.path.join(__file__, os.pardir)), 'test_data/beam/', 'beam.med')) stressExtractionTool = stress_tool.CodeAsterStressExtractionTool() stressExtractionStep = caeml.common.workflow.Step( name='step3', process=stressExtractionTool, parent=aWorkflow) aWorkflow.steps['step3'] = stressExtractionStep stressExtractionStep.inputPorts['resu_file'].setSource( codeAsterStep.outputPorts['resu_file']) state = caeml.runner.runner_local_pool.executeAsync(aWorkflow) # res_file = state.findPortState(codeAsterStep.outputPorts['results']).getEvaluation() stress = state.findPortState( stressExtractionStep.outputPorts['stress_value']).getEvaluation() print(str(stress)) self.assertLessEqual(abs(stress - 0.07716), 1e-6)
def test_saved_name_of_tool(self): tool = getCmdTool('multiply') loaded_tool = self.tools_collection.find_one({'name': 'multiply'}) self.assertEqual(loaded_tool['name'], tool.name)
def setUp(self): wf = workflowBuilder.createWorkflow('dummyWorkflow') self.sumStep1 = workflowBuilder.createStep( name='aStep', process=getCmdTool('multiply'), parent=wf) assert (isinstance(self.sumStep1, caeml.common.workflow.Step))
def getCmdTool(id: str) -> CommandLineTool: return tool_loader.getCmdTool(id)