def _test_remove(browser): #projects_page, project_info_page, project_dict, workspace_page = startup(browser) project_dict, workspace_page = startup(browser) # Show assembly information. # Lots of futzing here to handle short screens (EC2 Windows). workspace_page.select_object('top') workspace_page.show_dataflow('top') workspace_page.hide_left() top = workspace_page.get_dataflow_figure('top', '') editor = top.editor_page(double_click=False) editor.move(100, 200) connections = top.connections_page() properties = top.properties_page() eq(editor.is_visible, True) eq(connections.is_visible, True) eq(properties.is_visible, True) # Remove component. top.remove() time.sleep(1) eq(editor.is_visible, False) eq(connections.is_visible, False) eq(properties.is_visible, False) # Clean up. # closeout(projects_page, project_info_page, project_dict, workspace_page) closeout(project_dict, workspace_page)
def _test_drop_on_component_editor_grid(browser): project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') top = workspace_page.get_dataflow_figure('top', '') workspace_page.set_library_filter('Assembly') # put Assembly at top of lib assembly = workspace_page.find_library_button('Assembly') editor = top.editor_page(double_click=False, base_type='Assembly') editor.show_dataflow() editor_top = workspace_page.get_dataflow_fig_in_globals('top') # sort through these to find the correct 'top' chain = ActionChains(browser) chain.click_and_hold(assembly) chain.move_to_element(editor_top('header').find_element_by_xpath("..")).perform() chain.move_by_offset(200, 1).perform() chain.release(None).perform() # don't bother checking to see if it appeared, # the UI box will appear and screw the test if it did closeout(project_dict, workspace_page)
def _test_editfile(browser): # Check ability to open code editor by double clicking on file in workspace. projects_page, project_info_page, project_dict, workspace_page = startup(browser) # create a couple of files file1 = "test1.py" workspace_page.new_file(file1) file2 = "test2.py" workspace_page.new_file(file2) # verify file is opened in code editor by double clicking workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(file1) eq(str(editor_page.get_tab_label()), "/" + file1) # verify different file is opened in code editor by double clicking browser.switch_to_window(workspace_window) editor_page = workspace_page.edit_file(file2) eq(str(editor_page.get_tab_label()), "/" + file2) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # verify code editor can be re-opened by double clicking on file workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(file1) eq(str(editor_page.get_tab_label()), "/" + file1) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_remove(browser): projects_page, project_info_page, project_dict, workspace_page = startup( browser) # Show assembly information. workspace_page.select_object('top') top = workspace_page.get_dataflow_figure('top', '') editor = top.editor_page(double_click=False) editor.move(-100, 100) # Move it away from context menu. connections = top.connections_page() properties = top.properties_page() eq(editor.is_visible, True) eq(connections.is_visible, True) eq(properties.is_visible, True) # Remove component. top.remove() time.sleep(1) eq(editor.is_visible, False) eq(connections.is_visible, False) eq(properties.is_visible, False) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_display_differentiator(browser): # Verify that we can display a differentiator (based on Container). project_dict, workspace_page = startup(browser) eq(len(workspace_page.get_dataflow_figures()), 1) # Create assembly with an SLSQPdriver. workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.replace_driver('top', 'SLSQPdriver') driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor.move(-400, 0) # Display & verify differentiator. editor.show_slots() diff = find_slot_figure(workspace_page, 'differentiator', prefix='top.driver') diff_editor = diff.edit() inputs = diff_editor.get_inputs() expected = [ ['', 'default_stepsize', '0.000001', '', 'Default finite difference step size.'], ['', 'form', 'central', '', 'Finite difference form (central, forward, backward).'], ] for i, row in enumerate(inputs.value): eq(row, expected[i]) # Clean up. diff_editor.close() editor.close() closeout(project_dict, workspace_page)
def _test_component_tree(browser): project_dict, workspace_page = startup(browser) workspace_page.select_objects_view('Components') # Add maxmin.py to project file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/maxmin.py') workspace_page.add_file(file_path) # Add MaxMin to 'top'. workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow('maxmin.MaxMin', 'maxmin') # Maximize 'top' and 'top.maxmin' visible = workspace_page.get_objects_attribute('path', True) eq(visible, ['top']) workspace_page.expand_object('top') time.sleep(0.5) visible = workspace_page.get_objects_attribute('path', True) eq(visible, ['top', 'top.driver', 'top.maxmin']) workspace_page.expand_object('top.maxmin') time.sleep(0.5) visible = workspace_page.get_objects_attribute('path', True) eq(visible, ['top', 'top.driver', 'top.maxmin', 'top.maxmin.driver', 'top.maxmin.sub']) workspace_page.add_library_item_to_dataflow('maxmin.MaxMin', 'maxmin2') visible = workspace_page.get_objects_attribute('path', True) eq(visible, ['top', 'top.driver', 'top.maxmin', 'top.maxmin.driver', 'top.maxmin.sub', 'top.maxmin2']) # Clean up. closeout(project_dict, workspace_page)
def _test_objtree(browser): # Toggles maxmimize/minimize button on assemblies. projects_page, project_info_page, project_dict, workspace_page = startup(browser) # Add maxmin.py to project file_path = pkg_resources.resource_filename("openmdao.gui.test.functional", "maxmin.py") workspace_page.add_file(file_path) # Add MaxMin to 'top'. workspace_page.show_dataflow("top") workspace_page.add_library_item_to_dataflow("maxmin.MaxMin", "maxmin") # Maximize 'top' and 'top.maxmin' visible = workspace_page.get_objects_attribute("path", True) eq(visible, ["top"]) workspace_page.expand_object("top") time.sleep(0.5) visible = workspace_page.get_objects_attribute("path", True) eq(visible, ["top", "top.driver", "top.maxmin"]) workspace_page.expand_object("top.maxmin") time.sleep(0.5) visible = workspace_page.get_objects_attribute("path", True) eq(visible, ["top", "top.driver", "top.maxmin", "top.maxmin.driver", "top.maxmin.sub"]) workspace_page.add_library_item_to_dataflow("maxmin.MaxMin", "maxmin2") visible = workspace_page.get_objects_attribute("path", True) eq(visible, ["top", "top.driver", "top.maxmin", "top.maxmin.driver", "top.maxmin.sub", "top.maxmin2"]) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_crlf(browser): # Test ability to handle a file with Windows-style CR/LF line terminations project_dict, workspace_page = startup(browser) # add a Windows notepad generated python file filename = 'notepad.py' filepath = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/notepad.py') workspace_page.add_file(filepath) # open file in code editor workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(filename) eq(str(editor_page.get_tab_label()), '/' + filename) # add a comment and save comment = '# a comment' editor_page.append_text_to_file(comment) editor_page.save_document() # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # re-open file and verify comment was successfully added workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(filename) assert editor_page.get_code().endswith(comment) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Clean up. closeout(project_dict, workspace_page)
def _test_remove(browser): projects_page, project_info_page, project_dict, workspace_page = startup(browser) # Show assembly information. workspace_page.select_object("top") top = workspace_page.get_dataflow_figure("top", "") editor = top.editor_page(double_click=False) editor.move(-100, 100) # Move it away from context menu. connections = top.connections_page() properties = top.properties_page() eq(editor.is_visible, True) eq(connections.is_visible, True) eq(properties.is_visible, True) # Remove component. top.remove() time.sleep(1) eq(editor.is_visible, False) eq(connections.is_visible, False) eq(properties.is_visible, False) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_drop_on_grid(browser): project_dict, workspace_page = startup(browser) #other tests also need to put an assembly on the grid, so put in seperate method put_assembly_on_grid(workspace_page) closeout(project_dict, workspace_page)
def _test_evaluate(browser): project_dict, workspace_page = startup(browser) # create an assembly with an implicit component in it's workflow filename = pkg_resources.resource_filename('openmdao.main.test', 'test_implicit_component.py') workspace_page.add_file(filename) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow( 'test_implicit_component.MyComp_Deriv', 'comp', prefix='top') workspace_page.add_object_to_workflow('top.comp', 'top') # Verify that the evaluate menu option has the expected effect (header, inputs, outputs) = workspace_page.get_properties('comp') eq(outputs.value, [['y_out', '0'], ['derivative_exec_count', '0'], ['exec_count', '0'], ['itername', '']]) workspace_page('workflow_tab').click() comp = workspace_page.get_workflow_component_figure('comp') comp.evaluate() (header, inputs, outputs) = workspace_page.get_properties('comp') eq(outputs.value, [['y_out', '2'], ['derivative_exec_count', '0'], ['exec_count', '0'], ['itername', '']]) # Clean up. closeout(project_dict, workspace_page)
def _test_logviewer(browser): # Verify log viewer functionality. # Note that by default the logging level is set to WARNING. projects_page, project_info_page, project_dict, workspace_page = startup( browser) viewer = workspace_page.show_log() # Incremental display. workspace_page.do_command("import logging") workspace_page.do_command("logging.error('1 Hello World')") msgs = viewer.get_messages() while "Shouldn't have handled a send event" in msgs[-1]: msgs = msgs[:-1] eq(msgs[-1][-13:], '1 Hello World') # Exercise pausing the display. Since there's room on-screen, # the lack of scrollbar update isn't noticable. text = viewer.pause() eq(text, 'Pause') for i in range(2, 4): workspace_page.do_command("logging.error('%d Hello World')" % i) text = viewer.pause() # Toggle-back. eq(text, 'Resume') # Clear display. viewer.clear() msgs = viewer.get_messages() eq(msgs, ['']) # Exercise filtering. logger = pkg_resources.resource_filename('openmdao.gui.test.functional', 'logger.py') workspace_page.add_file(logger) msgs = viewer.get_messages() # Remove any spurious errors and drop timestamp. initial = [ msg[16:] for msg in msgs if "Shouldn't have handled a send event" not in msg ] eq(initial, [ 'W root: warning 1', 'E root: error 1', 'C root: critical 1', 'W root: warning 2', 'E root: error 2', 'C root: critical 2', 'W root: warning 3', 'E root: error 3', 'C root: critical 3' ]) # Turn off errors. dialog = viewer.filter() dialog('error_button').click() dialog('ok_button').click() msgs = viewer.get_messages() filtered = [msg[16:] for msg in msgs] # Drop timestamp. eq(filtered, [ 'W root: warning 1', 'C root: critical 1', 'W root: warning 2', 'C root: critical 2', 'W root: warning 3', 'C root: critical 3' ]) # Clean up. viewer.close() closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_remove(browser): project_dict, workspace_page = startup(browser) # Show assembly information. top = workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.select_object('top') workspace_page.show_dataflow('top') workspace_page.hide_left() # open various views on the top assembly top = workspace_page.get_dataflow_figure('top', '') editor = top.editor_page(double_click=False) editor.move(100, 200) connections = top.connections_page() properties = top.properties_page() eq(editor.is_visible, True) eq(connections.is_visible, True) eq(properties.is_visible, True) # Remove component. top.remove() # make sure all the views on the top assembly go away time.sleep(1) eq(editor.is_visible, False) eq(connections.is_visible, False) eq(properties.is_visible, False) # Clean up. closeout(project_dict, workspace_page)
def _test_parameter_auto(browser): # Test auto-filling the min and max for a parameter. project_dict, workspace_page = startup(browser) file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/connect.py') workspace_page.add_file(file_path) workspace_page.add_library_item_to_dataflow('connect.Conn_Assy', 'top') # Add parameter to driver. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'comp.x' dialog('ok').click() parameters = editor.get_parameters() expected = [['', 'comp.x', '0', '299', '1', '0', '', 'comp.x']] eq(len(parameters.value), len(expected)) for i, row in enumerate(parameters.value): eq(row, expected[i]) editor.close() closeout(project_dict, workspace_page)
def _test_libsearch(browser): # Verify library search functionality. projects_page, project_info_page, project_dict, workspace_page = startup( browser) # Get default objects. def_objects = workspace_page.get_object_types() def_searches = workspace_page.get_library_searches() # Get 'doe' search results. workspace_page.set_library_filter('doe') objects = workspace_page.get_object_types() eq(objects, [ 'CentralComposite', 'CSVFile', 'DOEdriver', 'FullFactorial', 'NeighborhoodDOEdriver', 'OptLatinHypercube', 'Uniform' ]) doe_searches = workspace_page.get_library_searches() eq(doe_searches, def_searches + ['doe']) # Clear search, now back to default objects. workspace_page.clear_library_filter() objects = workspace_page.get_object_types() eq(objects, def_objects) # Get 'xyzzy' search results. workspace_page.set_library_filter('xyzzy') objects = workspace_page.get_object_types() eq(objects, ['No matching records found']) searches = workspace_page.get_library_searches() eq(searches, doe_searches) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_remove(browser): project_dict, workspace_page = startup(browser) # Show assembly information. top = workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') workspace_page.select_object('top') workspace_page.show_dataflow('top') workspace_page.hide_left() # open various views on the top assembly top = workspace_page.get_dataflow_figure('top', '') editor = top.editor_page(double_click=False) editor.move(100, 200) connections = top.connections_page() properties = top.properties_page() eq(editor.is_visible, True) eq(connections.is_visible, True) eq(properties.is_visible, True) # Remove component. top.remove() # make sure all the views on the top assembly go away time.sleep(1) eq(editor.is_visible, False) eq(connections.is_visible, False) eq(properties.is_visible, False) # Clean up. closeout(project_dict, workspace_page)
def _test_parameter_auto(browser): # Test auto-filling the min and max for a parameter. project_dict, workspace_page = startup(browser) file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/connect.py') workspace_page.add_file(file_path) top = workspace_page.get_dataflow_figure('top') top.remove() workspace_page.add_library_item_to_dataflow('connect.Conn_Assy', 'top') # Add parameter to driver. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'comp.x' dialog('ok').click() parameters = editor.get_parameters() expected = [['', 'comp.x', '0', '299', '', '', '', 'comp.x']] eq(len(parameters.value), len(expected)) for i, row in enumerate(parameters.value): eq(row, expected[i]) editor.close() closeout(project_dict, workspace_page)
def _test_editfile(browser): # Check ability to open code editor by double clicking on file in workspace. project_dict, workspace_page = startup(browser) # create a couple of files file1 = 'test1.py' workspace_page.new_file(file1) file2 = 'test2.py' workspace_page.new_file(file2) # verify file is opened in code editor by double clicking workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(file1) eq(str(editor_page.get_tab_label()), '/' + file1) # verify different file is opened in code editor by double clicking browser.switch_to_window(workspace_window) editor_page = workspace_page.edit_file(file2) eq(str(editor_page.get_tab_label()), '/' + file2) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # verify code editor can be re-opened by double clicking on file workspace_window = browser.current_window_handle editor_page = workspace_page.edit_file(file1) eq(str(editor_page.get_tab_label()), '/' + file1) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Clean up. closeout(project_dict, workspace_page)
def _test_update(browser): # Adding a parameter to a driver should update the driver's workflow. project_dict, workspace_page = startup(browser) # Create model with CONMIN and ExecComp. workspace_page.show_dataflow('top') workspace_page.replace('driver', 'openmdao.lib.drivers.conmindriver.CONMINdriver') workspace_page.add_library_item_to_dataflow( 'openmdao.test.execcomp.ExecComp', 'exe', args=["('z = x * y',)"]) # Add parameter to CONMIN. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'exe.x' dialog.low = '-1' dialog.high = '1' dialog('ok').click() editor.close() # Verify workflow contains ExecComp. workspace_page('workflow_tab').click() eq(len(workspace_page.get_workflow_figures()), 1) eq(len(workspace_page.get_workflow_component_figures()), 2) # Clean up. closeout(project_dict, workspace_page)
def _test_remove_tla(browser): # verify that adding, removing, and adding a top level assembly works. project_dict, workspace_page = startup(browser) eq(len(workspace_page.get_dataflow_figures()), 1) # create a top assembly and check number of figures workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top1') eq(len(workspace_page.get_dataflow_figures()), 3) # add component to top assembly and check for additional figure workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.external_code.ExternalCode', 'ext', target_name='top1') eq(len(workspace_page.get_dataflow_figures()), 4) # remove top and check that it and it's child figures are gone top = workspace_page.get_dataflow_figure('top1') top.remove() eq(len(workspace_page.get_dataflow_figures()), 1) # add a new top, verify on screen. workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top2') eq(len(workspace_page.get_dataflow_figures()), 3) # clean up closeout(project_dict, workspace_page)
def _test_ordering(browser): # Verify that adding parameter to driver moves it ahead of target. project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow("openmdao.main.assembly.Assembly", "top") # Add ExternalCode and SLSQP. workspace_page.show_dataflow("top") ext = workspace_page.add_library_item_to_dataflow( "openmdao.lib.components.external_code.ExternalCode", "ext", prefix="top" ) opt = workspace_page.add_library_item_to_dataflow( "openmdao.lib.drivers.slsqpdriver.SLSQPdriver", "opt", prefix="top" ) # Add parameter to SLSQP. editor = opt.editor_page(base_type="Driver") editor("parameters_tab").click() editor.move(-100, -100) dialog = editor.new_parameter() dialog.target = "ext.timeout" dialog.low = "0" dialog.high = "1" dialog.name = "tmo" dialog("ok").click() # Check that SLSQP is above and to the left of ExternalCode ext = workspace_page.get_dataflow_figure("ext", "top") opt = workspace_page.get_dataflow_figure("opt", "top") assert ext.coords[0] > opt.coords[0] assert ext.coords[1] > opt.coords[1] # Clean up. editor.close() closeout(project_dict, workspace_page)
def _test_ordering(browser): # Verify that adding parameter to driver moves it ahead of target. project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') # Add ExternalCode and SLSQP. workspace_page.show_dataflow('top') ext = workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.external_code.ExternalCode', 'ext', prefix='top') opt = workspace_page.add_library_item_to_dataflow( 'openmdao.lib.drivers.slsqpdriver.SLSQPdriver', 'opt', prefix='top') # Add parameter to SLSQP. editor = opt.editor_page(base_type='Driver') editor('parameters_tab').click() editor.move(-100, -100) dialog = editor.new_parameter() dialog.target = 'ext.timeout' dialog.low = '0' dialog.high = '1' dialog.name = 'tmo' dialog('ok').click() # Check that SLSQP is above and to the left of ExternalCode ext = workspace_page.get_dataflow_figure('ext', 'top') opt = workspace_page.get_dataflow_figure('opt', 'top') assert ext.coords[0] > opt.coords[0] assert ext.coords[1] > opt.coords[1] # Clean up. editor.close() closeout(project_dict, workspace_page)
def _test_update(browser): # Adding a parameter to a driver should update the driver's workflow. project_dict, workspace_page = startup(browser) # Create model with CONMIN and ExecComp. workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.replace_driver('top', 'CONMINdriver') workspace_page.add_library_item_to_dataflow( 'openmdao.test.execcomp.ExecComp', 'exe', args=["('z = x * y',)"]) # Add parameter to CONMIN. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'exe.x' dialog.low = '-1' dialog.high = '1' dialog('ok').click() editor.close() # Verify workflow contains ExecComp. workspace_page('workflow_tab').click() eq(len(workspace_page.get_workflow_figures()), 1) eq(len(workspace_page.get_workflow_component_figures()), 2) # Clean up. closeout(project_dict, workspace_page)
def _test_addfiles(browser): # Adds multiple files to the project. projects_page, project_info_page, project_dict, workspace_page = startup( browser) # Get path to paraboloid file. paraboloidPath = pkg_resources.resource_filename( 'openmdao.examples.simple', 'paraboloid.py') # Get path to optimization_unconstrained file. optPath = pkg_resources.resource_filename('openmdao.examples.simple', 'optimization_unconstrained.py') # Add the files # would like to test adding multiple files but Selenium doesn't support it #workspace_page.add_files(paraboloidPath, optPath) workspace_page.add_file(paraboloidPath) workspace_page.add_file(optPath) # Check to make sure the files were added. time.sleep(0.5) file_names = workspace_page.get_files() expected_file_names = ['optimization_unconstrained.py', 'paraboloid.py'] if sorted(file_names) != sorted(expected_file_names): raise TestCase.failureException( "Expected file names, '%s', should match existing file names, '%s'" % (expected_file_names, file_names)) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_loading_docs(browser): project_dict, workspace_page = startup(browser) # Check that the docs are viewable workspace_page('help_menu').click() time.sleep(0.5) eq(workspace_page('doc_button').get_attribute('id'), 'help-doc') workspace_window = browser.current_window_handle current_windows = set(browser.window_handles) workspace_page('doc_button').click() new_windows = set(browser.window_handles) - current_windows docs_window = list(new_windows)[0] browser.switch_to_window(docs_window) time.sleep(0.5) eq("OpenMDAO User Guide" in browser.title, True) eq("OpenMDAO Documentation" in browser.title, True) browser.close() browser.switch_to_window(workspace_window) workspace_page.show_library() browser.switch_to_window( workspace_page.view_library_item_docs( "openmdao.main.assembly.Assembly")) # Just check to see if a Traceback 404 message was sent. try: browser.find_element((By.XPATH, "/html/head/body/pre[1]")) assert False except: pass browser.close() browser.switch_to_window(workspace_window) closeout(project_dict, workspace_page)
def _test_loading_docs(browser): project_dict, workspace_page = startup(browser) # Check that the docs are viewable workspace_page('help_menu').click() time.sleep(0.5) eq(workspace_page('doc_button').get_attribute('id'), 'help-doc') workspace_window = browser.current_window_handle current_windows = set(browser.window_handles) workspace_page('doc_button').click() new_windows = set(browser.window_handles) - current_windows docs_window = list(new_windows)[0] browser.switch_to_window(docs_window) time.sleep(0.5) eq("OpenMDAO User Guide" in browser.title, True) eq("OpenMDAO Documentation" in browser.title, True) browser.close() browser.switch_to_window(workspace_window) workspace_page.show_library() browser.switch_to_window(workspace_page.view_library_item_docs("openmdao.main.assembly.Assembly")) # Just check to see if a Traceback 404 message was sent. try: browser.find_element((By.XPATH, "/html/head/body/pre[1]")) assert False except: pass browser.close() browser.switch_to_window(workspace_window) closeout(project_dict, workspace_page)
def _test_addfiles(browser): # Adds multiple files to the project. projects_page, project_info_page, project_dict, workspace_page = startup(browser) # Get path to paraboloid file. paraboloidPath = pkg_resources.resource_filename("openmdao.examples.simple", "paraboloid.py") # Get path to optimization_unconstrained file. optPath = pkg_resources.resource_filename("openmdao.examples.simple", "optimization_unconstrained.py") # Add the files # would like to test adding multiple files but Selenium doesn't support it # workspace_page.add_files(paraboloidPath, optPath) workspace_page.add_file(paraboloidPath) workspace_page.add_file(optPath) # Check to make sure the files were added. time.sleep(0.5) file_names = workspace_page.get_files() expected_file_names = ["optimization_unconstrained.py", "paraboloid.py"] if sorted(file_names) != sorted(expected_file_names): raise TestCase.failureException( "Expected file names, '%s', should match existing file names, '%s'" % (expected_file_names, file_names) ) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_ordering(browser): # Verify that adding parameter to driver moves it ahead of target. project_dict, workspace_page = startup(browser) # Add ExternalCode and SLSQP. workspace_page.show_dataflow('top') ext = workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.external_code.ExternalCode', 'ext', prefix='top') opt = workspace_page.add_library_item_to_dataflow( 'openmdao.lib.drivers.slsqpdriver.SLSQPdriver', 'opt', prefix='top') # Check that ExternalCode is before SLSQP. assert ext.coords[0] < opt.coords[0] # Add parameter to SLSQP. editor = opt.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'ext.timeout' dialog.low = '0' dialog.high = '1' dialog.name = 'tmo' dialog('ok').click() # Check that SLSQP is now ahead of ExternalCode. ext = workspace_page.get_dataflow_figure('ext', 'top') opt = workspace_page.get_dataflow_figure('opt', 'top') assert ext.coords[0] > opt.coords[0] # Clean up. closeout(project_dict, workspace_page)
def _test_drop_on_grid(browser): projects_page, project_info_page, project_dict, workspace_page = startup(browser) #other tests also need to put an assembly on the grid, so put in seperate method put_assembly_on_grid(workspace_page) closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_newfile(browser): # Creates a file in the GUI. projects_page, project_info_page, project_dict, workspace_page = startup(browser) # Open code editor. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() # test the 'ok' and 'cancel' buttons on the new file dialog dlg = editor_page.new_file_dialog() dlg.set_text("ok_file1") dlg.click_ok() NotifierPage.wait(editor_page) dlg = editor_page.new_file_dialog() dlg.set_text("cancel_file") dlg.click_cancel() dlg = editor_page.new_file_dialog() dlg.set_text("ok_file2") dlg.click_ok() NotifierPage.wait(editor_page) file_names = editor_page.get_files() expected_file_names = ["ok_file1", "ok_file2"] if sorted(file_names) != sorted(expected_file_names): raise TestCase.failureException( "Expected file names, '%s', should match existing file names, '%s'" % (expected_file_names, file_names) ) # Create the file (code editor automatically indents). editor_page.new_file( "plane.py", """ from openmdao.main.api import Component from openmdao.lib.datatypes.api import Float # lines will be auto-indented by ace editor class Plane(Component): x1 = Float(0.0, iotype='in') x2 = Float(0.0, iotype='in') x3 = Float(0.0, iotype='in') f_x = Float(0.0, iotype='out') """, ) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Drag over Plane. workspace_page.show_dataflow("top") workspace_page.set_library_filter("In Project") workspace_page.add_library_item_to_dataflow("plane.Plane", "plane") # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_console_errors(browser): #projects_page, project_info_page, project_dict, workspace_page = startup(browser) project_dict, workspace_page = startup(browser) # Set input to illegal value. top = workspace_page.get_dataflow_figure('driver', 'top') editor = top.editor_page(double_click=False, base_type='Driver') inputs = editor.get_inputs() inputs.rows[2].cells[1].click() inputs[2][2] = '42' # printvars message = NotifierPage.wait(editor) eq( message, "TraitError: The 'printvars' trait of a " "Run_Once instance must be a list of items " "which are a legal value, but a value of 42 " "<type 'int'> was specified.") editor.close() # Attempt to save file with syntax error. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() editor_page.new_file('bug.py', """ from openmdao.main.api import Component class Bug(Component): def execute(self) pass """, check=False) message = NotifierPage.wait(editor_page, base_id='file-error') browser.close() browser.switch_to_window(workspace_window) eq(message, 'invalid syntax (bug.py, line 6)\n def execute(self)') # Load file with instantiation error. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() editor_page.new_file( 'bug2.py', """ from openmdao.main.api import Component class Bug2(Component): def __init__(self): raise RuntimeError("__init__ failed") """) browser.close() browser.switch_to_window(workspace_window) workspace_page.add_library_item_to_dataflow('bug2.Bug2', 'bug', check=False) message = NotifierPage.wait(workspace_page) eq( message, "NameError: unable to create object of type 'bug2.Bug2': __init__ failed" ) # Clean up. #closeout(projects_page, project_info_page, project_dict, workspace_page) closeout(project_dict, workspace_page)
def _test_slots(browser): project_dict, workspace_page = startup(browser) editor, metamodel, caseiter, caserec, comp, meta_name = slot_reset(workspace_page) execcomp = workspace_page.find_library_button('ExecComp') # drop ExecComp onto MetaModel 'recorder' slot. This should fail. workspace_page.drag_and_drop(execcomp, caserec, False, 'Component') time.sleep(1.0) # give it a second to update the figure caserec = find_slot_figure(workspace_page, 'recorder', prefix=meta_name) eq(False, caserec.filled, "Component dropped into CaseRecorder (should not have)") # drop ExecComp onto the MetaModel 'model' slot. This should succeed. comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) workspace_page.fill_slot_from_library(comp, 'ExecComp') time.sleep(1.0) # give it a second to update the figure comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) eq(True, comp.filled, "Component did not drop into Component slot") # remove ExecComp from the MetaModel 'model' slot. This should succeed. comp.remove() time.sleep(1.0) # give it a second to update the figure comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) eq(False, comp.filled, "Component slot was not emptied") #for the future: """ # get the objects we need for the test # setup a data structure explaining which things can be dropped where # element, dropOnCaseIter, dropOnCaseRec, dropOnComp dropdata = [('CSVCaseIterator', True, False, False),\ ('CSVCaseRecorder', False, True, False),\ ('ExecComp', False, False, True),\ ('Assembly', False, False, True)] drop_elements = [(workspace_page.find_library_button(ele[0]), ele[1], ele[2], ele[3]) for ele in dropdata] #now loop through each dropable item, and see what happens when it lands on the target for ele in drop_elements: #drop on caseiter drag_and_drop(browser, ele[0].element, caseiter, ele[1], 'CaseIterator') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR #drop on caserec drag_and_drop(browser, ele[0].element, caserec, ele[2], 'CaseRecorder') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR #drop on comp drag_and_drop(browser, ele[0].element, comp, ele[3], 'Component') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR editor, metamodel, caseiter, caserec, comp = slot_reset(workspace_page, editor, metamodel, True) """ editor.close() closeout(project_dict, workspace_page)
def _test_arguments(browser): # Check that objects requiring constructor arguments are handled. project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.metamodel.MetaModel', 'mm') mm_figure = workspace_page.get_dataflow_figure('mm', 'top') mm_editor = mm_figure.editor_page() mm_editor.show_slots() mm_editor.move(-200, 0) # Plug ListCaseIterator into warm_start_data. slot = find_slot_figure(workspace_page, 'warm_start_data', prefix='top.mm') args = ['[]'] workspace_page.fill_slot_from_library(slot, 'ListCaseIterator', args) # Plug ListCaseRecorder into recorder. slot = find_slot_figure(workspace_page, 'recorder', prefix='top.mm') workspace_page.fill_slot_from_library(slot, 'ListCaseRecorder') # Plug ExecComp into model. slot = find_slot_figure(workspace_page, 'model', prefix='top.mm') args = ["('z = x * y',)"] workspace_page.fill_slot_from_library(slot, 'ExecComp', args) # Check that inputs were created from expression. slot = find_slot_figure(workspace_page, 'model', prefix='top.mm') exe_editor = slot.editor_page() exe_editor.move(-100, 0) inputs = exe_editor.get_inputs() expected = [ ['', 'x', '0', '', ''], ['', 'y', '0', '', ''], [ '', 'directory', '', '', 'If non-blank, the directory to execute in.' ], [ '', 'force_execute', 'False', '', 'If True, always execute even if all IO traits are valid.' ], [ '', 'force_fd', 'False', '', 'If True, always finite difference this component.' ], [ '', 'missing_deriv_policy', 'error', '', 'Determines behavior when some analytical derivatives are provided but some are missing' ] ] for i, row in enumerate(inputs.value): eq(row, expected[i]) exe_editor.close() mm_editor.close() closeout(project_dict, workspace_page)
def _test_standard_library(browser): project_dict, workspace_page = startup(browser) workspace_page.set_library_filter('optproblems') objects = workspace_page.get_object_types() eq(objects, ['BraninProblem', 'PolyScalableProblem', 'SellarProblem']) closeout(project_dict, workspace_page)
def _test_drop_on_component_editor(browser): project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') top = workspace_page.get_dataflow_figure('top', '') workspace_page.set_library_filter('Assembly') # put Assembly at top of lib assembly = workspace_page.find_library_button('Assembly') editor = top.editor_page(double_click=False, base_type='Assembly') editor.show_dataflow() # move the editor window down and to the left, away from the library editor.move(-200, 200) # in order to get the elements in the editor dataflow, we must # distinguish them from the elements in the main dataflow editor_top = workspace_page.get_dataflow_fig_in_globals('top') # sort through these to find the correct 'top' names = [] for div in editor_top.get_drop_targets()[:-1]: chain = workspace_page.drag_element_to(assembly, div, False) time.sleep(1) workspace_page.check_highlighting( editor_top('content_area').element, True, "Top in component editor's content_area") workspace_page.release(chain) #deal with the modal dialog name = NameInstanceDialog(workspace_page).create_and_dismiss() names.append(name) workspace_page.ensure_names_in_workspace( names, "Dragging 'assembly' to 'top' (in component editor) in one of the " "drop areas did not produce a new element on page") #now test to see if all the new elements are children of 'top' #generate what the pathnames SHOULD be guess_pathnames = ["top." + name for name in names] #get the actual pathnames figs = workspace_page.get_dataflow_figures() pathnames = [fig.get_pathname() for fig in figs] # see if they match up! (keeping in mind that there are more elements # we have pathnames for than we put there) for path in guess_pathnames: eq( path in pathnames, True, "An element did not drop into 'top' (in component editor) when " "dragged onto one of its drop areas.\nIt was created somewhere else" ) closeout(project_dict, workspace_page)
def _test_slots(browser): project_dict, workspace_page = startup(browser) editor, metamodel, caseiter, caserec, comp, meta_name = slot_reset( workspace_page) execcomp = workspace_page.find_library_button('ExecComp') # drop ExecComp onto MetaModel 'recorder' slot. This should fail. workspace_page.drag_and_drop(execcomp, caserec, False, 'Component') time.sleep(1.0) # give it a second to update the figure caserec = find_slot_figure(workspace_page, 'recorder', prefix=meta_name) eq(False, caserec.filled, "Component dropped into CaseRecorder (should not have)") # drop ExecComp onto the MetaModel 'model' slot. This should succeed. comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) workspace_page.fill_slot_from_library(comp, 'ExecComp') time.sleep(1.0) # give it a second to update the figure comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) eq(True, comp.filled, "Component did not drop into Component slot") # remove ExecComp from the MetaModel 'model' slot. This should succeed. comp.remove() time.sleep(1.0) # give it a second to update the figure comp = find_slot_figure(workspace_page, 'model', prefix=meta_name) eq(False, comp.filled, "Component slot was not emptied") #for the future: """ # get the objects we need for the test # setup a data structure explaining which things can be dropped where # element, dropOnCaseIter, dropOnCaseRec, dropOnComp dropdata = [('CSVCaseIterator', True, False, False),\ ('CSVCaseRecorder', False, True, False),\ ('ExecComp', False, False, True),\ ('Assembly', False, False, True)] drop_elements = [(workspace_page.find_library_button(ele[0]), ele[1], ele[2], ele[3]) for ele in dropdata] #now loop through each dropable item, and see what happens when it lands on the target for ele in drop_elements: #drop on caseiter drag_and_drop(browser, ele[0].element, caseiter, ele[1], 'CaseIterator') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR #drop on caserec drag_and_drop(browser, ele[0].element, caserec, ele[2], 'CaseRecorder') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR #drop on comp drag_and_drop(browser, ele[0].element, comp, ele[3], 'Component') #TODO: REFRESH THE SLOTS, CHECK THEIR FONT COLOR editor, metamodel, caseiter, caserec, comp = slot_reset(workspace_page, editor, metamodel, True) """ editor.close() closeout(project_dict, workspace_page)
def _test_console_errors(browser): projects_page, project_info_page, project_dict, workspace_page = startup(browser) # Set input to illegal value. top = workspace_page.get_dataflow_figure("driver", "top") editor = top.editor_page(double_click=False, base_type="Driver") inputs = editor.get_inputs() inputs[2][2] = "42" # printvars message = NotifierPage.wait(editor) eq( message, "TraitError: The 'printvars' trait of a " "Run_Once instance must be a list of items " "which are a legal value, but a value of 42 " "<type 'int'> was specified.", ) editor.close() # Attempt to save file with syntax error. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() editor_page.new_file( "bug.py", """ from openmdao.main.api import Component class Bug(Component): def execute(self) pass """, check=False, ) message = NotifierPage.wait(editor_page, base_id="file-error") eq(message, "invalid syntax (bug.py, line 6)") browser.close() browser.switch_to_window(workspace_window) # Load file with instantiation error. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() editor_page.new_file( "bug2.py", """ from openmdao.main.api import Component class Bug2(Component): def __init__(self): raise RuntimeError("__init__ failed") """, ) browser.close() browser.switch_to_window(workspace_window) workspace_page.add_library_item_to_dataflow("bug2.Bug2", "bug", check=False) message = NotifierPage.wait(workspace_page) eq(message, "NameError: unable to create object of type 'bug2.Bug2': __init__ failed") # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_newfile(browser): # Creates a file in the GUI. projects_page, project_info_page, project_dict, workspace_page = startup( browser) # Open code editor. workspace_window = browser.current_window_handle editor_page = workspace_page.open_editor() # test the 'ok' and 'cancel' buttons on the new file dialog dlg = editor_page.new_file_dialog() dlg.set_text('ok_file1') dlg.click_ok() NotifierPage.wait(editor_page) dlg = editor_page.new_file_dialog() dlg.set_text('cancel_file') dlg.click_cancel() dlg = editor_page.new_file_dialog() dlg.set_text('ok_file2') dlg.click_ok() NotifierPage.wait(editor_page) file_names = editor_page.get_files() expected_file_names = ['ok_file1', 'ok_file2'] if sorted(file_names) != sorted(expected_file_names): raise TestCase.failureException( "Expected file names, '%s', should match existing file names, '%s'" % (expected_file_names, file_names)) # Create the file (code editor automatically indents). editor_page.new_file( 'plane.py', """ from openmdao.main.api import Component from openmdao.lib.datatypes.api import Float # lines will be auto-indented by ace editor class Plane(Component): x1 = Float(0.0, iotype='in') x2 = Float(0.0, iotype='in') x3 = Float(0.0, iotype='in') f_x = Float(0.0, iotype='out') """) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Drag over Plane. workspace_page.show_dataflow('top') workspace_page.set_library_filter('In Project') workspace_page.add_library_item_to_dataflow('plane.Plane', 'plane') # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_sorting(browser): # Check that inputs and outputs are sorted alphanumerically. project_dict, workspace_page = startup(browser) path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/sorting_test.py') workspace_page.add_file(path) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow('sorting_test.SortingComp', 'comp') comp = workspace_page.get_dataflow_figure('comp', 'top') editor = comp.editor_page() # Check order of inputs. inputs = editor.get_inputs() expected = [ ['', 'stress_i1', '0', '', ''], ['', 'stress_i2', '0', '', ''], ['', 'stress_i10', '0', '', ''], [ '', 'directory', '', '', 'If non-blank, the directory to execute in.' ], [ '', 'force_execute', 'False', '', 'If True, always execute even if all IO traits are valid.' ], ] for i, row in enumerate(inputs.value): eq(row, expected[i]) # Check order of outputs. inputs = editor.get_outputs() expected = [ ['', 'stress_o1', '0', '', ''], ['', 'stress_o2', '0', '', ''], ['', 'stress_o10', '0', '', ''], [ '', 'derivative_exec_count', '0', '', "Number of times this Component's derivative function has been executed." ], [ '', 'exec_count', '0', '', 'Number of times this Component has been executed.' ], ['', 'itername', '', '', 'Iteration coordinates.'], ] for i, row in enumerate(inputs.value): eq(row, expected[i]) editor.close() closeout(project_dict, workspace_page)
def _test_slot_subclass(browser): # test that a slot will accept subclasses project_dict, workspace_page = startup(browser) file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/slot_test.py') workspace_page.add_file(file_path) name = workspace_page.put_element_on_grid("AutoAssemb") aa = workspace_page.get_dataflow_figure(name) editor = aa.editor_page(double_click=False) editor.move(-200, 200) inputs = editor.get_inputs() expected = [ ['', 'input', '0', '', ''], ['', 'directory', '', '', 'If non-blank, the directory to execute in.'], ['', 'force_execute', 'False', '', 'If True, always execute even if all IO traits are valid.'], ] for i, row in enumerate(inputs.value): eq(row, expected[i]) inputs[0][2] = "10" aa.run() message = NotifierPage.wait(workspace_page) eq(message, 'Run complete: success') outputs = editor.get_outputs() expected = [ ['', 'output', '80', '', ''], ['', 'derivative_exec_count', '0', '', "Number of times this Component's derivative function has been executed."], ['', 'exec_count', '1', '', 'Number of times this Component has been executed.'], ['', 'itername', '', '', 'Iteration coordinates.'], ] for i, row in enumerate(outputs.value): eq(row, expected[i]) editor.show_slots() recorders_slot = find_slot_figure(workspace_page, 'd2', prefix=name) workspace_page.fill_slot_from_library(recorders_slot, 'Dummy2') aa.run() message = NotifierPage.wait(workspace_page) eq(message, 'Run complete: success') outputs = editor.get_outputs() expected = [ ['', 'output', '160', '', ''], ['', 'derivative_exec_count', '0', '', "Number of times this Component's derivative function has been executed."], ['', 'exec_count', '2', '', 'Number of times this Component has been executed.'], ['', 'itername', '', '', 'Iteration coordinates.'], ] for i, row in enumerate(outputs.value): eq(row, expected[i]) # Clean up. closeout(project_dict, workspace_page)
def _test_casefilters(browser): # Verify that CaseFilter objects are listed in the library. project_dict, workspace_page = startup(browser) for classname in ('ExprCaseFilter', 'IteratorCaseFilter', 'SequenceCaseFilter', 'SliceCaseFilter'): workspace_page.find_library_button(classname) closeout(project_dict, workspace_page)
def _test_drop_on_component_editor(browser): project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') top = workspace_page.get_dataflow_figure('top', '') workspace_page.set_library_filter('Assembly') # put Assembly at top of lib assembly = workspace_page.find_library_button('Assembly') editor = top.editor_page(double_click=False, base_type='Assembly') editor.show_dataflow() # move the editor window down and to the left, away from the library editor.move(-200, 200) # in order to get the elements in the editor dataflow, we must # distinguish them from the elements in the main dataflow editor_top = workspace_page.get_dataflow_fig_in_globals('top') # sort through these to find the correct 'top' names = [] for div in editor_top.get_drop_targets()[:-1]: time.sleep(1) chain = workspace_page.drag_element_to(assembly, div, False) time.sleep(1) workspace_page.check_highlighting(editor_top('content_area').element, True, "Top in component editor's content_area") workspace_page.release(chain) #deal with the modal dialog name = NameInstanceDialog(workspace_page).create_and_dismiss() names.append(name) workspace_page.ensure_names_in_workspace(names, "Dragging 'assembly' to 'top' (in component editor) in one of the " "drop areas did not produce a new element on page") #now test to see if all the new elements are children of 'top' #generate what the pathnames SHOULD be guess_pathnames = ["top." + name for name in names] #get the actual pathnames figs = workspace_page.get_dataflow_figures() pathnames = [fig.get_pathname() for fig in figs] # see if they match up! (keeping in mind that there are more elements # we have pathnames for than we put there) for path in guess_pathnames: eq(path in pathnames, True, "An element did not drop into 'top' (in component editor) when " "dragged onto one of its drop areas.\nIt was created somewhere else") closeout(project_dict, workspace_page)
def _test_array_parameter(browser): # Test adding an array parameter. project_dict, workspace_page = startup(browser) file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/array_parameters.py') workspace_page.add_file(file_path) workspace_page.add_library_item_to_dataflow( 'array_parameters.ArrayParameters', 'top') # Add parameter to driver. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'paraboloid.x' dialog.low = '-50' dialog.high = '[40, 50]' dialog.scaler = '[[1., 1]]' dialog('ok').click() parameters = editor.get_parameters() expected = [[ '', 'paraboloid.x', '-50', '40,50', '1,1', '0', '', 'paraboloid.x' ]] eq(len(parameters.value), len(expected)) for i, row in enumerate(parameters.value): eq(row, expected[i]) editor.close() time.sleep(1) # Run optimization. top = workspace_page.get_dataflow_figure('top') top.run() message = NotifierPage.wait(workspace_page) eq(message, 'Run complete: success') # Check results. workspace_page.do_command("top.paraboloid.x[0][0]") x00 = workspace_page.history.split("\n")[-1] workspace_page.do_command("top.paraboloid.x[0][1]") x01 = workspace_page.history.split("\n")[-1] if abs(float(x00) - 6.6667) > 0.01: raise TestCase.failureException( "Parameter x[0][0] did not reach correct value, but instead is %s" % x00) if abs(float(x01) - -7.3333) > 0.01: raise TestCase.failureException( "Parameter x[0][1] did not reach correct value, but instead is %s" % x01) closeout(project_dict, workspace_page)
def _test_standard_library(browser): project_dict, workspace_page = startup(browser) workspace_page.set_library_filter('optproblems') objects = workspace_page.get_object_types() eq(objects, [ 'BraninProblem', 'PolyScalableProblem', 'SellarProblem',]) closeout(project_dict, workspace_page)
def _test_arguments(browser): # Check that objects requiring constructor arguments are handled. #projects_page, project_info_page, project_dict, workspace_page = startup(browser) project_dict, workspace_page = startup(browser) workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.metamodel.MetaModel', 'mm') mm_figure = workspace_page.get_dataflow_figure('mm', 'top') mm_editor = mm_figure.editor_page() mm_editor.show_slots() mm_editor.move(-200, 0) # Plug ListCaseIterator into warm_start_data. slot = SlotFigure(workspace_page, 'top.mm.warm_start_data') slot.fill_from_library('ListCaseIterator') args_page = ArgsPrompt(workspace_page.browser, workspace_page.port) args_page.set_argument(0, '[]') args_page.click_ok() # Plug ListCaseRecorder into recorder. slot = SlotFigure(workspace_page, 'top.mm.recorder') slot.fill_from_library('ListCaseRecorder') # Plug ExecComp into model. slot = SlotFigure(workspace_page, 'top.mm.model') slot.fill_from_library('ExecComp') args_page = ArgsPrompt(workspace_page.browser, workspace_page.port) args_page.set_argument(0, "('z = x * y',)") args_page.click_ok() # Check that inputs were created from expression. exe_editor = slot.editor_page() exe_editor.move(-100, 0) inputs = exe_editor.get_inputs() expected = [ [ 'directory', 'str', '', '', 'true', 'If non-blank, the directory to execute in.', '', '' ], [ 'force_execute', 'bool', 'False', '', 'true', 'If True, always execute even if all IO traits are valid.', '', '' ], ['x', 'float', '0', '', 'true', '', '', ''], ['y', 'float', '0', '', 'true', '', '', ''], ] for i, row in enumerate(inputs.value): eq(row, expected[i]) exe_editor.close() mm_editor.close() #closeout(projects_page, project_info_page, project_dict, workspace_page) closeout(project_dict, workspace_page)
def _test_driverflows(browser): # Excercises display of driver flows (parameters, constraints, objectives). projects_page, project_info_page, project_dict, workspace_page = startup( browser) filename = pkg_resources.resource_filename('openmdao.gui.test.functional', 'rosen_suzuki.py') workspace_page.add_file(filename) # Replace 'top' with Simulation. top = workspace_page.get_dataflow_figure('top') top.remove() workspace_page.add_library_item_to_dataflow('rosen_suzuki.Simulation', 'top') # Show dataflow for Simulation. workspace_page.show_dataflow('top') workspace_page.hide_left() # Select different displays. top = workspace_page.get_dataflow_figure('top') top.display_dataflows(False) time.sleep(0.5) # While only driver flows are displayed, check on context menu. preproc = workspace_page.get_dataflow_figure('preproc', 'top') editor = preproc.input_edit_driver('top.driver') editor.move(-100, 0) eq(editor.dialog_title, 'CONMINdriver: top.driver') outputs = editor.get_parameters() expected = [ [ '', "('preproc.x_in[0]', 'preproc.x_in[1]', 'preproc.x_in[2]', 'preproc.x_in[3]')", '-10', '99', '', '', '', "('preproc.x_in[0]', 'preproc.x_in[1]', 'preproc.x_in[2]', 'preproc.x_in[3]')" ], ] for i, row in enumerate(outputs.value): eq(row, expected[i]) editor.close() #FIXME: can't seem to do context-click on output port. top.display_driverflows(False) time.sleep(0.5) top.display_dataflows(True) time.sleep(0.5) top.display_driverflows(True) time.sleep(0.5) # Clean up. closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_drop_on_driver(browser): projects_page, project_info_page, project_dict, workspace_page = startup(browser) # replace the 'top' assembly driver with a CONMINdriver replace_driver(workspace_page, 'top', 'CONMINdriver') # Check to see that the content area for the driver is now CONMINdriver driver_element = workspace_page.get_dataflow_figure('driver') eq(driver_element('content_area').find_element_by_xpath('center/i').text, 'CONMINdriver', "Dropping CONMINdriver onto existing driver did not replace it") closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_sorting(browser): # Check that inputs and outputs are sorted alphanumerically. project_dict, workspace_page = startup(browser) path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/sorting_test.py') workspace_page.add_file(path) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow( 'sorting_test.SortingComp', 'comp') comp = workspace_page.get_dataflow_figure('comp', 'top') editor = comp.editor_page() # Check order of inputs. inputs = editor.get_inputs() expected = [ ['', 'stress_i1', '0', '', ''], ['', 'stress_i2', '0', '', ''], ['', 'stress_i10', '0', '', ''], ['', 'directory', '', '', 'If non-blank, the directory to execute in.'], ['', 'force_execute', 'False', '', 'If True, always execute even if all IO traits are valid.'], ['', 'force_fd', 'False', '', 'If True, always finite difference this component.'], ['', 'missing_deriv_policy', 'error', '', 'Determines behavior when some analytical derivatives are provided but some are missing'] ] for i, row in enumerate(inputs.value): eq(row, expected[i]) # Check order of outputs. outputs = editor.get_outputs() expected = [ ['', 'stress_o1', '0', '', ''], ['', 'stress_o2', '0', '', ''], ['', 'stress_o10', '0', '', ''], ['', 'derivative_exec_count', '0', '', "Number of times this Component's derivative function has been executed."], ['', 'exec_count', '0', '', 'Number of times this Component has been executed.'], ['', 'itername', '', '', 'Iteration coordinates.'], ] for i, row in enumerate(outputs.value): eq(row, expected[i]) editor.close() closeout(project_dict, workspace_page)
def _test_array_parameter(browser): # Test adding an array parameter. project_dict, workspace_page = startup(browser) file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/array_parameters.py') workspace_page.add_file(file_path) workspace_page.add_library_item_to_dataflow('array_parameters.ArrayParameters', 'top') # Add parameter to driver. driver = workspace_page.get_dataflow_figure('driver', 'top') editor = driver.editor_page(base_type='Driver') editor('parameters_tab').click() dialog = editor.new_parameter() dialog.target = 'paraboloid.x' dialog.low = '-50' dialog.high = '[40, 50]' dialog.scaler = '[[1., 1]]' dialog('ok').click() parameters = editor.get_parameters() expected = [['', 'paraboloid.x', '-50', '40,50', '1,1', '0', '', 'paraboloid.x']] eq(len(parameters.value), len(expected)) for i, row in enumerate(parameters.value): eq(row, expected[i]) editor.close() time.sleep(1) # Run optimization. top = workspace_page.get_dataflow_figure('top') top.run() message = NotifierPage.wait(workspace_page) eq(message, 'Run complete: success') # Check results. workspace_page.do_command("top.paraboloid.x[0][0]") x00 = workspace_page.history.split("\n")[-1] workspace_page.do_command("top.paraboloid.x[0][1]") x01 = workspace_page.history.split("\n")[-1] if abs(float(x00) - 6.6667) > 0.01: raise TestCase.failureException( "Parameter x[0][0] did not reach correct value, but instead is %s" % x00) if abs(float(x01) - -7.3333) > 0.01: raise TestCase.failureException( "Parameter x[0][1] did not reach correct value, but instead is %s" % x01) closeout(project_dict, workspace_page)
def _test_view_file(browser): project_dict, workspace_page = startup(browser) workspace_window = browser.current_window_handle # add an image file file_name = 'Engine_Example_Process_Diagram.png' file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/' + file_name) workspace_page.add_file(file_path) time.sleep(2) # view the image file new_page = workspace_page.view_file(file_name) time.sleep(2) # the new page should have an img tag with the selected file name images = new_page.browser.find_elements_by_css_selector('img') eq(len(images), 1) eq(images[0].get_attribute('src').strip().endswith(file_name), True) # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # add a pdf file file_name = 'sample.pdf' file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/' + file_name) workspace_page.add_file(file_path) time.sleep(2) # view the pdf file new_page = workspace_page.view_file(file_name) time.sleep(2) # the new page should have an embed tag with the selected file name embeds = new_page.browser.find_elements_by_css_selector('embed') eq(len(embeds), 1) eq(embeds[0].get_attribute('src').strip().endswith(file_name), True) eq(embeds[0].get_attribute('type'), 'application/pdf') # Back to workspace. browser.close() browser.switch_to_window(workspace_window) # Clean up. closeout(project_dict, workspace_page)
def _test_implicit_component(browser): project_dict, workspace_page = startup(browser) # create an assembly with an implicit component in it's workflow filename = pkg_resources.resource_filename('openmdao.main.test', 'test_implicit_component.py') workspace_page.add_file(filename) workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow('test_implicit_component.MyComp_Deriv', 'comp', prefix='top') workspace_page.add_object_to_workflow('top.comp', 'top') # Verify that the evaluate menu option has the expected effect comp = workspace_page.get_dataflow_figure('comp', 'top') comp_editor = comp.editor_page(base_type='ImplicitComponent') states = comp_editor.get_states() eq(states.value, [ ['', 'x', '0', '', ''], ['', 'y', '0', '', ''], ['', 'z', '0', '', ''], ]) residuals = comp_editor.get_residuals() eq(residuals.value, [ ['', 'res', '[0.0, 0.0, 0.0]', '', ''] ]) comp_editor.set_state('x', '1') comp_editor.set_state('y', '2') comp_editor.set_state('z', '3') comp.evaluate() states = comp_editor.get_states() eq(states.value, [ ['', 'x', '1', '', ''], ['', 'y', '2', '', ''], ['', 'z', '3', '', ''], ]) residuals = comp_editor.get_residuals() eq(residuals.value, [ ['', 'res', '[7.0, 12.0, -3.0]', '', ''] ]) # Clean up. closeout(project_dict, workspace_page)
def _test_arguments(browser): # Check that objects requiring constructor arguments are handled. project_dict, workspace_page = startup(browser) workspace_page.add_library_item_to_dataflow( 'openmdao.main.assembly.Assembly', 'top') workspace_page.show_dataflow('top') workspace_page.add_library_item_to_dataflow( 'openmdao.lib.components.metamodel.MetaModel', 'mm') mm_figure = workspace_page.get_dataflow_figure('mm', 'top') mm_editor = mm_figure.editor_page() mm_editor.show_slots() mm_editor.move(-200, 0) # Plug ListCaseIterator into warm_start_data. slot = find_slot_figure(workspace_page, 'warm_start_data', prefix='top.mm') args = ['[]'] workspace_page.fill_slot_from_library(slot, 'ListCaseIterator', args) # Plug ListCaseRecorder into recorder. slot = find_slot_figure(workspace_page, 'recorder', prefix='top.mm') workspace_page.fill_slot_from_library(slot, 'ListCaseRecorder') # Plug ExecComp into model. slot = find_slot_figure(workspace_page, 'model', prefix='top.mm') args = ["('z = x * y',)"] workspace_page.fill_slot_from_library(slot, 'ExecComp', args) # Check that inputs were created from expression. slot = find_slot_figure(workspace_page, 'model', prefix='top.mm') exe_editor = slot.editor_page() exe_editor.move(-100, 0) inputs = exe_editor.get_inputs() expected = [ ['', 'x', '0', '', ''], ['', 'y', '0', '', ''], ['', 'directory', '', '', 'If non-blank, the directory to execute in.'], ['', 'force_execute', 'False', '', 'If True, always execute even if all IO traits are valid.'], ['', 'force_fd', 'False', '', 'If True, always finite difference this component.'], ['', 'missing_deriv_policy', 'error', '', 'Determines behavior when some analytical derivatives are provided but some are missing'] ] for i, row in enumerate(inputs.value): eq(row, expected[i]) exe_editor.close() mm_editor.close() closeout(project_dict, workspace_page)
def _test_drop_on_driver(browser): project_dict, workspace_page = startup(browser) # replace the 'top' assembly driver with a CONMINdriver workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top') workspace_page.replace_driver('top', 'CONMINdriver') # Check to see that the content area for the driver is now CONMINdriver driver_element = workspace_page.get_dataflow_figure('driver') eq(driver_element('content_area').find_element_by_xpath('center/i').text, 'CONMINdriver', "Dropping CONMINdriver onto existing driver did not replace it") closeout(project_dict, workspace_page)