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)
示例#2
0
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_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_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_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)

    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_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_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)
示例#10
0
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_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_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_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_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)
示例#15
0
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_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_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)
示例#18
0
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_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)

    # 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_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)
示例#22
0
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_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_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_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)
示例#28
0
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_slots_sorted_by_name(browser):
    project_dict, workspace_page = startup(browser)

    #drop 'metamodel' onto the grid
    meta_name = workspace_page.put_element_on_grid('MetaModel')
    #find it on the page
    metamodel = workspace_page.get_dataflow_figure(meta_name)

    #open the 'edit' dialog on metamodel
    editor = metamodel.editor_page(False)

    # see if the slot names are sorted
    slot_name_elements = editor.root.find_elements_by_css_selector('text#name')
    slot_names = [s.text for s in slot_name_elements]
    eq(slot_names, sorted(slot_names))

    closeout(project_dict, workspace_page)
def _test_console_history(browser):
    # Check up and down arrow navigation through the command history
    project_dict, workspace_page = startup(browser)

    command_elem = browser.find_element(By.ID, "cmdline")

    # Fill up the command history
    workspace_page.do_command("import sys")
    workspace_page.do_command("import os")
    workspace_page.do_command("import time")

    # Try out the up and down arrows
    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import time")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import os")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import sys")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import sys")

    command_elem.send_keys(Keys.ARROW_DOWN)
    eq(workspace_page.command, "import os")

    command_elem.send_keys(Keys.ARROW_DOWN)
    eq(workspace_page.command, "import time")

    command_elem.send_keys(Keys.ARROW_DOWN)
    eq(workspace_page.command, "import time")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import os")

    workspace_page.do_command("import traceback")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import traceback")

    command_elem.send_keys(Keys.ARROW_UP)
    eq(workspace_page.command, "import time")

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_driverflows(browser):
    # Excercises display of driver flows (parameters, constraints, objectives).
    project_dict, workspace_page = startup(browser)

    filename = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                               'files/rosen_suzuki.py')
    workspace_page.add_file(filename)

    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', '1', '0', '',
         "('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(project_dict, workspace_page)
def _test_console(browser):
    # Check basic console functionality.
    #projects_page, project_info_page, project_dict, workspace_page = startup(browser)
    project_dict, workspace_page = startup(browser)

    workspace_page.do_command("print 'blah'")
    expected = ">>> print 'blah'\nblah"
    eq(workspace_page.history, expected)

    # Check that browser title contains project name.
    title = browser.title
    expected = 'OpenMDAO: ' + project_dict['name'] + ' - '
    eq(title[:len(expected)], expected)

    # Clean up.
    #closeout(projects_page, project_info_page, project_dict, workspace_page)
    closeout(project_dict, workspace_page)
def _test_drop_on_existing_assembly(browser):
    project_dict, workspace_page = startup(browser)

    assembly = workspace_page.find_library_button('Assembly')

    outer_name = put_assembly_on_grid(workspace_page)
    outer_figure = workspace_page.get_dataflow_figure(outer_name)
    outer_path = outer_figure.pathname

    eq(outer_path, outer_name,
       "Assembly did not produce an instance on the grid")

    div = getDropableElements(outer_figure)[0]
    chain = drag_element_to(browser, assembly, div, False)
    check_highlighting(
        outer_figure('content_area').element, True, "Assembly's content_area")
    release(chain)

    middle_name = NameInstanceDialog(workspace_page).create_and_dismiss()
    middle_figure = workspace_page.get_dataflow_figure(middle_name)
    middle_path = middle_figure.pathname

    eq(middle_path, outer_path + '.' + middle_name,
       "Assembly did not produce an instance inside outer Assembly")

    div = getDropableElements(middle_figure)[0]
    chain = drag_element_to(browser, assembly, div, True)
    check_highlighting(
        middle_figure('content_area').element, True, "Assembly's content_area")
    release(chain)

    inner_name = NameInstanceDialog(workspace_page).create_and_dismiss()
    #expand the middle div so that the inner one shows up in the workspace.
    middle_figure('top_right').element.click()
    inner_figure = workspace_page.get_dataflow_figure(inner_name)
    inner_path = inner_figure.pathname

    eq(inner_path, middle_path + '.' + inner_name,
       "Assembly did not produce an instance inside of the middle Assembly")

    ensure_names_in_workspace(
        workspace_page, [outer_name, middle_name, inner_name],
        "Dragging Assembly onto Assembly did not create a new instance on page"
    )

    closeout(project_dict, workspace_page)
def _test_menu(browser):
    project_dict, workspace_page = startup(browser)

    # Check enable/disable of commit/revert.
    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), 'omg-disabled')
    eq(workspace_page('revert_button').get_attribute('class'), 'omg-disabled')
    workspace_page('project_menu').click()

    workspace_page.replace('driver', 'openmdao.main.driver.Run_Once')
    args_page = ArgsPrompt(workspace_page.browser, workspace_page.port)
    args_page.click_ok()

    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), '')
    eq(workspace_page('revert_button').get_attribute('class'), '')
    workspace_page('project_menu').click()

    workspace_page.commit_project()

    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), 'omg-disabled')
    eq(workspace_page('revert_button').get_attribute('class'), 'omg-disabled')
    workspace_page('project_menu').click()

    # Project-Run.
    workspace_page.run()
    expected = ['Executing...', 'Execution complete.']
    eq(workspace_page.history.split('\n')[-2:], expected)
    top_figure = workspace_page.get_dataflow_figure('top')
    eq(top_figure.border, '1px solid rgb(0, 255, 0)')

    #FIXME: These need to verify that the request has been performed.
    # View menu.
    for item in ('console', 'library', 'objects', 'files', 'properties',
                 'workflow', 'dataflow', 'refresh'):
        workspace_page('view_menu').click()
        workspace_page('%s_button' % item).click()
        time.sleep(0.5)  # Just so we can see it.

    # Clean up.
    closeout(project_dict, workspace_page)
示例#37
0
def _test_duplicates(browser):
    # Duplicate unconnected components are legal in a workflow.
    project_dict, workspace_page = startup(browser)

    # Create model with multiple ExecComps.
    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.test.execcomp.ExecComp', 'exe', args=["('z = x * y',)"])
    workspace_page.expand_object('top')
    workspace_page.add_object_to_workflow('top.exe', 'top')
    workspace_page.add_object_to_workflow('top.exe', 'top')
    workspace_page('workflow_tab').click()
    eq(len(workspace_page.get_workflow_figures()), 1)
    eq(len(workspace_page.get_workflow_component_figures()), 3)

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_slots_sorted_by_name(browser):
    project_dict, workspace_page = startup(browser)

    # drop 'metamodel' onto the grid
    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')
    workspace_page.show_dataflow('top')
    args = ["('ratio1', 'ratio2')", "('torque_ratio', 'RPM')"]
    workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.components.metamodel.MetaModel', 'mm', args=args)
    # open the 'edit' dialog on metamodel
    metamodel = workspace_page.get_dataflow_figure('mm', 'top')
    mm_editor = metamodel.editor_page()

    # see if the slot names are sorted
    slot_name_elements = mm_editor.root.find_elements_by_css_selector('text#name')
    slot_names = [s.text for s in slot_name_elements]
    eq(slot_names, sorted(slot_names))

    closeout(project_dict, workspace_page)
示例#39
0
def _test_basic(browser):
    project_dict, workspace_page = startup(browser)

    filename = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                               'files/rosen_suzuki.py')
    workspace_page.add_file(filename)

    # Add a NestedSimulation.
    workspace_page.add_library_item_to_dataflow(
        'rosen_suzuki.NestedSimulation', 'nested', offset=(300, 300))
    # Verify full workflow shown.
    workspace_page('workflow_tab').click()
    eq(len(workspace_page.get_workflow_figures()), 2)
    eq(len(workspace_page.get_workflow_component_figures()), 5)

    # Verify flow layout is horizontal and can be switched to vertical
    sim = workspace_page.get_workflow_figure('sim.driver')
    assert sim.horizontal
    sim.flip()
    assert not sim.horizontal

    # Verify workflow can be collapsed and expanded
    sim.collapse()
    assert sim.collapsed
    sim.expand()
    assert sim.expanded

    # Verify that component state is represented properly
    driver = workspace_page.get_workflow_component_figure('sim.driver')
    assert driver.state == 'INVALID'
    driver.run()
    time.sleep(2.0)
    message = NotifierPage.wait(workspace_page)
    eq(message, 'Run complete: success')
    assert driver.state == 'VALID'

    # Verify workflow can be cleared
    nested = workspace_page.get_workflow_figure('nested.driver')
    nested.clear()
    eq(len(workspace_page.get_workflow_component_figures()), 1)

    # Clean up.
    closeout(project_dict, workspace_page)
示例#40
0
def _test_taborder(browser):
    project_dict, workspace_page = startup(browser)
    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')

    # Replace driver with an SLSQPdriver.
    workspace_page.replace_driver('top', 'SLSQPdriver')
    driver = workspace_page.get_dataflow_figure('driver', 'top')
    editor = driver.editor_page(base_type='Driver')
    editor.move(-100, 0)

    # verify that expected tabs appear in expected order
    eq(editor.get_tab_labels(),
       ['Inputs', 'Outputs', 'Parameters', 'Objectives', 'Constraints',
        'Triggers', 'Workflow', 'Slots'])

    editor.close()

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_workspace_dragdrop(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')

    assembly = workspace_page.find_library_button('Assembly')

    names = []
    for div in top.get_drop_targets():
        chain = workspace_page.drag_element_to(assembly, div, False)
        workspace_page.check_highlighting(
            top('content_area').element, True, "Top'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 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' when "
            "dragged onto one of its drop areas.\nIt was created somewhere else"
        )

    closeout(project_dict, workspace_page)
示例#42
0
def _test_global(browser):
    # 'global' view should be populated (originally was blank).
    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)

    # Add a NestedSimulation.
    workspace_page.set_library_filter('In Project')
    workspace_page.add_library_item_to_dataflow(
        'rosen_suzuki.NestedSimulation', 'nested', offset=(300, 300))
    # Verify full workflow shown.
    workspace_page('workflow_tab').click()
    eq(len(workspace_page.get_workflow_figures()), 3)
    eq(len(workspace_page.get_workflow_component_figures()), 6)

    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_properties(browser):
    # Checks right-hand side properties display.
    #projects_page, project_info_page, project_dict, workspace_page = startup(browser)
    project_dict, workspace_page = startup(browser)

    # Check default 'top.driver'.
    workspace_page('properties_tab').click()
    obj = workspace_page.get_dataflow_figure('top')
    chain = ActionChains(browser)
    chain.click(obj.root)
    chain.perform()
    time.sleep(0.5)
    eq(workspace_page.props_header, 'Run_Once: top.driver')
    inputs = workspace_page.props_inputs
    eq(inputs.value,
       [['directory', ''], ['force_execute', 'True'], ['printvars', '']
        ])  # FIXME: printvars is really an empty list...
    # Clean up.
    #closeout(projects_page, project_info_page, project_dict, workspace_page)
    closeout(project_dict, workspace_page)
示例#44
0
def _test_rename_file(browser):
    # Rename a file in the project.
    project_dict, workspace_page = startup(browser)

    # Add paraboloid.py
    paraboloidPath = pkg_resources.resource_filename(
        'openmdao.examples.simple', 'paraboloid.py')
    workspace_page.add_file(paraboloidPath)
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    eq(file_names, ['paraboloid.py'])

    workspace_page.rename_file('paraboloid.py', 'xyzzy.py')
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    eq(file_names, ['xyzzy.py'])

    # Clean up.
    #closeout(projects_page, project_info_page, project_dict, workspace_page)
    closeout(project_dict, workspace_page)
示例#45
0
def _test_noslots(browser):
    projects_page, project_info_page, project_dict, workspace_page = startup(
        browser)

    # Add ExternalCode to assembly.
    workspace_page.show_dataflow('top')
    ext = workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.components.external_code.ExternalCode',
        'ext',
        prefix='top')

    # Display editor and check that no 'Slots' tab exists.
    editor = ext.editor_page(double_click=False)
    eq(editor('inputs_tab').is_visible, True)  # This waits.
    eq(editor('inputs_tab').is_present, True)  # These are quick tests.
    eq(editor('slots_tab').is_present, False)
    eq(editor('outputs_tab').is_present, True)

    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
def _test_libsearch(browser):
    # Verify library search functionality.
    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',
        'ConnectableDOEdriver',
        'ConnectableNeighborhoodDOEdriver',
        'CSVFile',
        'DOEdriver',
        'DOEdriverBase',
        'FullFactorial',
        'NeighborhoodDOEdriver',
        'NeighborhoodDOEdriverBase',
        'OptLatinHypercube',
        'PlugNozzleGeometry',
        '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(project_dict, workspace_page)
def _test_properties(browser):
    # Checks right-hand side properties display.
    project_dict, workspace_page = startup(browser)

    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')

    (header, inputs, outputs) = workspace_page.get_properties('top')
    eq(header, 'Driver: top.driver')
    eq(inputs.value, [
        ['directory', ''],
        ['force_fd', 'False'],
        [' gradient_options', ''],  # vartree, has leading space after the [+]
    ])
    eq(outputs.value, [
        ['derivative_exec_count', '0'],
        ['exec_count', '0'],
        ['itername', '']
    ])

    # Clean up.
    closeout(project_dict, workspace_page)
示例#48
0
def _test_passthrough_editor(browser):
    project_dict, workspace_page = startup(browser)

    # Import variable_editor.py
    file_path = pkg_resources.resource_filename(
        'openmdao.gui.test.functional', 'files/passthrough_editors.py')
    workspace_page.add_file(file_path)

    top = workspace_page.get_dataflow_figure('top')
    top.remove()
    workspace_page.add_library_item_to_dataflow('passthrough_editors.Topp',
                                                "top")

    time.sleep(2)
    top = workspace_page.get_dataflow_figure("top")
    top._context_click('edit_passthroughs')

    y_box = '//*[@id="top-p1-y-cb"]'
    y_btn = browser.find_element_by_xpath(y_box)
    f_xy_box = '//*[@id="top-p1-f_xy-cb"]'
    f_xy_btn = browser.find_element_by_xpath(f_xy_box)

    eq(y_btn.is_selected(), True)  # check existing passthrough
    eq(f_xy_btn.is_selected(), False)  # verify passthrough doesn't exist yet

    time.sleep(3)
    y_btn.click()  # remove passthrough
    time.sleep(1)
    f_xy_btn = browser.find_element_by_xpath(f_xy_box)
    f_xy_btn.click()  # create passthrough
    time.sleep(3)

    workspace_page.do_command("top.list_connections()")
    time.sleep(.5)
    output = workspace_page.history.split("\n")[-1]
    eq("('p1.f_xy', 'f_xy')" in output, True)  # verify created passthrough
    eq("('y', 'p1.y')" in output, False)  # verify removed passthrough

    # Clean up.
    closeout(project_dict, workspace_page)
示例#49
0
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)
示例#50
0
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)
示例#51
0
def _test_menu(browser):
    # Just click on various main menu buttons.
    projects_page, project_info_page, project_dict, workspace_page = startup(
        browser)

    # Project-Run.
    workspace_page.run()
    expected = 'Executing...\nExecution complete.'
    eq(workspace_page.history, expected)
    top_figure = workspace_page.get_dataflow_figure('top')
    eq(top_figure.border, '1px solid rgb(0, 255, 0)')

    #FIXME: These need to verify that the request has been performed.
    # View menu.
    for item in ('console', 'library', 'objects', 'files', 'properties',
                 'workflow', 'dataflow', 'refresh'):
        workspace_page('view_menu').click()
        workspace_page('%s_button' % item).click()
        time.sleep(0.5)  # Just so we can see it.

    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
示例#52
0
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)
示例#53
0
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)
示例#54
0
def _test_menu(browser):
    project_dict, workspace_page = startup(browser)

    # Check enable/disable of commit/revert.
    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), 'omg-disabled')
    eq(workspace_page('revert_button').get_attribute('class'), 'omg-disabled')
    workspace_page('project_menu').click()

    workspace_page.add_library_item_to_dataflow(
        'openmdao.main.assembly.Assembly', 'top')
    workspace_page.replace_driver('top', 'Run_Once')

    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), '')
    eq(workspace_page('revert_button').get_attribute('class'), '')
    workspace_page('project_menu').click()

    workspace_page.commit_project()

    workspace_page('project_menu').click()
    time.sleep(0.5)
    eq(workspace_page('commit_button').get_attribute('class'), 'omg-disabled')
    eq(workspace_page('revert_button').get_attribute('class'), 'omg-disabled')
    workspace_page('project_menu').click()

    #FIXME: These need to verify that the request has been performed.
    # View menu.
    for item in ('console', 'library', 'objects', 'files', 'properties',
                 'workflow', 'dataflow', 'refresh'):
        workspace_page('view_menu').click()
        workspace_page('%s_button' % item).click()
        time.sleep(0.5)  # Just so we can see it.

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_passthrough_editor(browser):
    project_dict, workspace_page = startup(browser)

    # Import variable_editor.py
    file_path = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                                'files/passthrough_editors.py')
    workspace_page.add_file(file_path)

    workspace_page.add_library_item_to_dataflow('passthrough_editors.Topp', "top")

    time.sleep(2)
    top = workspace_page.get_dataflow_figure("top")
    top._context_click('edit_passthroughs')

    expand_i = '//*[@id="p1"]/ins'
    browser.find_element_by_xpath(expand_i).click()
    time.sleep(2)
    y_box = '//*[@id="check_y"]'
    y_btn = browser.find_element_by_xpath(y_box)
    eq(y_btn.is_selected(), True)  # check existing passthrough

    browser.find_element_by_xpath('//*[@id="y"]/a').click()  # remove passthrough
    time.sleep(1)

    workspace_page.do_command("top.list_connections()")
    time.sleep(.5)
    output = workspace_page.history.split("\n")[-1]
    eq("('y', 'p1.y')" in output, False)  # verify removed passthrough

    time.sleep(1)
    browser.find_element_by_xpath('//*[@id="y"]/a').click()
    time.sleep(2)
    workspace_page.do_command("top.list_connections()")
    output = workspace_page.history.split("\n")[-1]
    eq("('y', 'p1.y')" in output, True)  # verify added passthrough

    # Clean up.
    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)

    # Clean up.
    closeout(project_dict, workspace_page)
示例#57
0
def _test_properties(browser):
    # Checks right-hand side properties display.
    projects_page, project_info_page, project_dict, workspace_page = startup(
        browser)

    # Check default 'top'.
    workspace_page.select_object('top')
    workspace_page.show_properties()
    eq(workspace_page.props_header, 'Assembly: top')
    inputs = workspace_page.props_inputs
    eq(inputs.value, [['directory', ''], ['force_execute', 'False']])

    # Check default 'top.driver'.
    workspace_page.expand_object('top')
    workspace_page.select_object('top.driver')
    time.sleep(0.5)
    eq(workspace_page.props_header, 'Run_Once: top.driver')
    inputs = workspace_page.props_inputs
    eq(inputs.value,
       [['directory', ''], ['force_execute', 'True'], ['printvars', '']
        ])  # FIXME: printvars is really an empty list...
    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
示例#58
0
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
    if broken_chrome():
        raise SkipTest('Test broken for chrome/selenium combination')
    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)
示例#59
0
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
    if broken_chrome():
        raise SkipTest('Test broken for chrome/selenium combination')
    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)
示例#60
0
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')

    # 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()
    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 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.
    editor.close()
    closeout(project_dict, workspace_page)