Esempio n. 1
0
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_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)
Esempio n. 3
0
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_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_remove_folder(browser):
    # Adds multiple files to the project.
    project_dict, workspace_page = startup(browser)

    # Test deleting a folder, but cancel the confirmation
    workspace_page.new_folder('test_folder')
    time.sleep(1.0)

    paraboloidPath = pkg_resources.resource_filename('openmdao.examples.simple',
                                                     'paraboloid.py')
    workspace_page.add_file_to_folder('test_folder', paraboloidPath)
    time.sleep(2.0)
    workspace_page.expand_folder('test_folder')
    time.sleep(1.0)

    workspace_page.delete_files(['test_folder'], False)

    expected_file_names = ['paraboloid.py']

    # Check to make sure the folder was NOT deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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))

    # toggle hidden files on and off to reset selected/highlighted files
    workspace_page.toggle_files()
    workspace_page.toggle_files()

    # Test deleting a folder
    time.sleep(1.0)
    workspace_page.delete_files(['test_folder'])

    expected_file_names = []

    # Check to make sure the folder was deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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(project_dict, workspace_page)
Esempio n. 6
0
def _test_remove_folder(browser):
    # Adds multiple files to the project.
    project_dict, workspace_page = startup(browser)

    # Test deleting a folder, but cancel the confirmation
    workspace_page.new_folder('test_folder')
    time.sleep(1.0)

    paraboloidPath = pkg_resources.resource_filename(
        'openmdao.examples.simple', 'paraboloid.py')
    workspace_page.add_file_to_folder('test_folder', paraboloidPath)
    time.sleep(2.0)
    workspace_page.expand_folder('test_folder')
    time.sleep(1.0)

    workspace_page.delete_files(['test_folder'], False)

    expected_file_names = ['paraboloid.py']

    # Check to make sure the folder was NOT deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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))

    # toggle hidden files on and off to reset selected/highlighted files
    workspace_page.toggle_files()
    workspace_page.toggle_files()

    # Test deleting a folder
    time.sleep(1.0)
    workspace_page.delete_files(['test_folder'])

    expected_file_names = []

    # Check to make sure the folder was deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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(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_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)
Esempio n. 9
0
    class TestObjectFailed(BaseTest):
        to_raise = TestCase.failureException('My Exception')

        def test_failed(self):
            self.failed_step()

        @step
        def failed_step(self):
            raise self.to_raise
Esempio n. 10
0
def _test_addfiles(browser):
    print "running _test_addfiles..."
    # Adds multiple files to the project.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # Opens code editor
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    editor_window = browser.current_window_handle

    upload_page = editor_page.add_files()

    # 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
    upload_page.select_files((paraboloidPath, optPath))
    upload_page.upload_files()

    time.sleep(1.0)

    # Check to make sure the files were added.
    browser.switch_to_window(editor_window)
    time.sleep(1)
    file_names = editor_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.
    browser.switch_to_window(workspace_window)
    projects_page = workspace_page.close_workspace()
    project_info_page = projects_page.edit_project(project_dict['name'])
    project_info_page.delete_project()
    print "_test_addfiles complete."
Esempio n. 11
0
def _test_MDAO_MDF(browser):
    # Build the MDF model as per the tutorial.

    project_dict, workspace_page = startup(browser)

    # Import the files that contain the disciplines
    file_path = pkg_resources.resource_filename("openmdao.lib.optproblems", "sellar.py")
    workspace_page.add_file(file_path)

    # Add Disciplines to assembly.
    workspace_page.show_dataflow("top")
    workspace_page.add_library_item_to_dataflow("sellar.Discipline1", "dis1")
    workspace_page.add_library_item_to_dataflow("sellar.Discipline2", "dis2")

    # Replace Run_Once with SLSQP
    workspace_page.replace("driver", "openmdao.lib.drivers.slsqpdriver.SLSQPdriver")
    # Add Solver
    workspace_page.add_library_item_to_dataflow(
        "openmdao.lib.drivers.iterate.FixedPointIterator", "solver", offset=(150, 50)
    )

    # One data connection
    dis1 = workspace_page.get_dataflow_figure("dis1", "top")
    dis2 = workspace_page.get_dataflow_figure("dis2", "top")
    conn_page = workspace_page.connect(dis1, dis2)
    conn_page.move(-100, -100)
    conn_page.connect_vars("dis1.y1", "dis2.y1")
    conn_page.close()

    # Add solver to optimizer workflow
    workspace_page.add_object_to_workflow("top.solver", "top")

    # Add disciplines to solver workflow
    workspace_page.expand_object("top")
    workspace_page.add_object_to_workflow("top.dis1", "top.solver")
    workspace_page.add_object_to_workflow("top.dis2", "top.solver")

    workspace_page("dataflow_tab").click()

    # Configure Solver
    driver = workspace_page.get_dataflow_figure("solver", "top")
    editor = driver.editor_page(base_type="Driver")
    editor.move(-100, -100)

    editor("parameters_tab").click()
    dialog = editor.new_parameter()
    dialog.target = "dis1.y2"
    dialog.low = "-9.e99"
    dialog.high = "9.e99"
    dialog("ok").click()

    editor("constraints_tab").click()
    dialog = editor.new_constraint()
    dialog.expr = "dis2.y2 - dis1.y2 = 0"
    dialog("ok").click()
    editor.close()

    # Configure Optimizer
    driver = workspace_page.get_dataflow_figure("driver", "top")
    editor = driver.editor_page(base_type="Driver")
    editor.move(-100, -100)

    editor("parameters_tab").click()
    dialog = editor.new_parameter()
    dialog.target = "dis1.z1,dis2.z1"
    dialog.low = "-10.0"
    dialog.high = "10.0"
    dialog("ok").click()

    dialog = editor.new_parameter()
    dialog.target = "dis1.z2,dis2.z2"
    dialog.low = "0.0"
    dialog.high = "10.0"
    dialog("ok").click()

    dialog = editor.new_parameter()
    dialog.target = "dis1.x1"
    dialog.low = "0.0"
    dialog.high = "10.0"
    dialog("ok").click()

    editor("constraints_tab").click()
    dialog = editor.new_constraint()
    dialog.expr = "3.16 < dis1.y1"
    dialog("ok").click()

    dialog = editor.new_constraint()
    dialog.expr = "dis2.y2 < 24.0"
    dialog("ok").click()

    editor("objectives_tab").click()
    dialog = editor.new_objective()
    dialog.expr = "(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)"
    dialog("ok").click()
    editor.close()

    # Get an implicitly connected output before the run.
    dis1_fig = workspace_page.get_dataflow_figure("dis1", "top")
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[3][:3], ["y1", "float", "0"])
    editor.close()

    # Run the model
    workspace_page.run()

    # Verify implicitly connected output has been updated with valid result.
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[3][:2], ["y1", "float"])
    dis1_y1 = float(outputs.value[3][2])
    if abs(dis1_y1 - 3.16) > 0.01:
        raise TestCase.failureException("Output dis1.y1 did not reach correct value, but instead is %s" % dis1_y1)
    editor.close()

    # Check the objective
    workspace_page.do_command("top.dis1.z1")
    output1 = workspace_page.history.split("\n")[-1]
    workspace_page.do_command("top.dis1.z2")
    output2 = workspace_page.history.split("\n")[-1]

    if abs(float(output1) - 1.977657) > 0.01:
        raise TestCase.failureException("Parameter z1 did not reach correct value, but instead is %s" % output1)

    if abs(float(output2) - 0.0) > 0.0001:
        raise TestCase.failureException("Parameter z2 did not reach correct value, but instead is %s" % output2)

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 12
0
"""
declassified methods from unittest.TestCase
"""

from unittest import TestCase

from .general import WooperAssertionError

assertions = TestCase()
assertions.failureException = WooperAssertionError
assertions._diffThreshold = 2**16
assertions._maxDiff = None
assertions.DIFF_OMITTED = ('\nDiff is %s characters long. '
                           'Set self.maxDiff to None to see it.')
assertions._MAX_LENGTH = 80
assertions._PLACEHOLDER_LEN = 12
assertions._MIN_BEGIN_LEN = 5
assertions._MIN_END_LEN = 5
assertions._MIN_COMMON_LEN = 5

# def assert_is_instance(obj, cls, msg=None):
#     """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
#     default message."""
#     return assertions.assertIsInstance(obj, cls, msg)


def assert_equal(first, second, msg=None):
    """Fail if the two objects are unequal as determined by the '=='
       operator.
    """
    return assertions.assertEqual(first, second, msg=None)
Esempio n. 13
0
def _test_import(browser):
    print "running _test_import..."
    # Import some files and add components from them.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # View the Workflow Pane.
    workspace_page('workflow_tab').click()
    time.sleep(0.5)  # Just so we can see it.

    # View dataflow.
    workspace_page('dataflow_tab').click()

    # Open code editor.
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()

    # Add paraboloid file.
    file_path = pkg_resources.resource_filename('openmdao.examples.simple',
                                                'paraboloid.py')
    editor_page.add_file(file_path)

    # Add optimization_unconstrained file.
    file_path = pkg_resources.resource_filename(
        'openmdao.examples.simple', 'optimization_unconstrained.py')
    editor_page.add_file(file_path)

    time.sleep(1.0)

    # Check to make sure the files were added.
    file_names = editor_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))

    # Back to workspace.
    browser.close()
    browser.switch_to_window(workspace_window)

    # Go into Libraries/working section.
    workspace_page('libraries_tab').click()
    time.sleep(1)
    workspace_page.find_palette_button('Paraboloid').click()

    # Make sure there are only two dataflow figures (top & driver)
    workspace_page.show_dataflow('top')
    time.sleep(1)
    eq(len(workspace_page.get_dataflow_figures()), 2)

    # Drag element into workspace.
    paraboloid_name = 'parab'
    workspace_page.add_library_item_to_dataflow('paraboloid.Paraboloid',
                                                paraboloid_name)
    # Now there should be three.
    eq(len(workspace_page.get_dataflow_figures()), 3)

    # Make sure the item added is there with the name we gave it.
    component_names = workspace_page.get_dataflow_component_names()
    if paraboloid_name not in component_names:
        raise TestCase.failureException(
            "Expected component name, '%s', to be in list of existing"
            " component names, '%s'" % (paraboloid_name, component_names))

    workspace_page.save_project()
    projects_page = workspace_page.close_workspace()

    # Now try to re-open that project to see if items are still there.
    project_info_page = projects_page.edit_project(project_dict['name'])
    workspace_page = project_info_page.load_project()

    # Check to see that the added files are still there.
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    editor_page('files_tab').click()
    file_names = editor_page.get_files()
    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))
    browser.close()
    browser.switch_to_window(workspace_window)

    # Clean up.
    projects_page = workspace_page.close_workspace()
    project_info_page = projects_page.edit_project(project_dict['name'])
    project_info_page.delete_project()
    print "_test_import complete."
Esempio n. 14
0
def _test_newfile(browser):
    print "running _test_newfile..."
    # Creates a file in the GUI.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # 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()
    time.sleep(1.0)

    dlg = editor_page.new_file_dialog()
    dlg.set_text('cancel_file')
    dlg.click_cancel()
    time.sleep(1.0)

    dlg = editor_page.new_file_dialog()
    dlg.set_text('ok_file2')
    dlg.click_ok()
    time.sleep(1.0)

    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

class Plane(Component):

    x1 = Float(0.0, iotype='in')
# subsequent lines will be auto-indented by ace editor
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('libraries_tab').click()
    workspace_page.libraries_search = 'In Project\n'
    time.sleep(2)
    workspace_page.find_palette_button('Plane').click()
    workspace_page.add_library_item_to_dataflow('plane.Plane', 'plane')

    # Clean up.
    projects_page = workspace_page.close_workspace()
    project_info_page = projects_page.edit_project(project_dict['name'])
    project_info_page.delete_project()
    print "_test_newfile complete."
def _test_Avartrees(browser):
    project_dict, workspace_page = startup(browser)

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

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

    comp = workspace_page.get_dataflow_figure('p1', "top")
    editor = comp.editor_page()
    editor.move(-100, 0)
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '', '', ''],
        [
            '', 'directory', '', '',
            'If non-blank, the directory to execute in.'
        ],
        [
            '', '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])

    # Expand first vartree
    inputs.rows[0].cells[1].click()
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '', '', ''], ['', 'v1', '1', '', 'vv1'],
        ['', 'v2', '2', '', 'vv2'], ['', ' vt2', '', '', ''],
        [
            '', 'directory', '', '',
            'If non-blank, the directory to execute in.'
        ],
        [
            '', '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])

    # While expanded, verify that 'v1' is editable.
    inputs.rows[1].cells[2].click()
    inputs = editor.get_inputs()
    inputs[1][2] = "42"
    expected[1][2] = "42"

    time.sleep(0.5)
    inputs = editor.get_inputs()
    #FIXME sometimes row 2 gets a value of '' because slickgrid is editing it.
    #    for i, row in enumerate(inputs.value):
    #        eq(row, expected[i])
    eq(inputs.value[1], expected[1])

    # While expanded, verify that cell that became the 2nd vartree is now
    # uneditable
    inputs.rows[3].cells[1].click()
    inputs = editor.get_inputs()
    try:
        inputs[3][2] = "abcd"
    except IndexError:
        pass
    else:
        raise TestCase.failureException(
            'Exception expected: VarTree value should not be settable on inputs.'
        )

    # Contract first vartree
    inputs.rows[0].cells[1].click()
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '', '', ''],
        [
            '', 'directory', '', '',
            'If non-blank, the directory to execute in.'
        ],
        [
            '', '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])

    editor.close()

    # Now, do it all again on the Properties Pane
    workspace_page('properties_tab').click()
    obj = workspace_page.get_dataflow_figure('p1', 'top')
    chain = ActionChains(browser)
    chain.click(obj.root)
    chain.perform()
    inputs = workspace_page.props_inputs
    expected = [[' cont_in', ''], ['directory', ''], ['force_fd', 'False'],
                ['missing_deriv_policy', 'error']]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # Expand first vartree
    inputs.rows[0].cells[0].click()
    inputs = workspace_page.props_inputs
    expected = [[' cont_in', ''], ['v1', '42'], ['v2', '2'], [' vt2', ''],
                ['directory', ''], ['force_fd', 'False'],
                ['missing_deriv_policy', 'error']]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # While expanded, verify that 'v1' is editable.
    inputs.rows[1].cells[1].click()
    inputs = workspace_page.props_inputs
    inputs[1][1] = "43"
    expected[1][1] = "43"

    time.sleep(1)
    inputs = workspace_page.props_inputs
    #FIXME sometimes row 2 gets a value of '' because slickgrid is editing it.
    #    for i, row in enumerate(inputs.value):
    #        eq(row, expected[i])
    eq(inputs.value[1], expected[1])

    # Contract first vartree
    inputs.rows[0].cells[0].click()
    inputs = workspace_page.props_inputs
    expected = [[' cont_in', ''], ['directory', ''], ['force_fd', 'False'],
                ['missing_deriv_policy', 'error']]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_value_editors(browser):
    # Creates a file in the GUI.
    project_dict, workspace_page = startup(browser)

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

    workspace_page.add_library_item_to_dataflow('variable_editors.Topp', 'top')

    dummy_comp = workspace_page.get_dataflow_figure('p1', 'top')
    props = dummy_comp.properties_page()
    props.move(-100, -100)  # Ensure Project menu fully visible.
    inputs = props.inputs

    #edit dictionary - remove 'e', add 'phi', round down 'pi'
    #action_chain = ActionChains(browser)
    #action_chain.double_click(inputs.rows[0].cells[1]).perform()
    # Can't single click on an entry you are focused on, so focus on next line, then come back.
    inputs.rows[1].cells[1].click()
    inputs.rows[0].cells[1].click()

    pi_value_path = '//*[@id="d-editor"]/input[2]'
    pi_value = browser.find_element_by_xpath(pi_value_path)
    pi_value.clear()
    pi_value.send_keys("3.0")

    e_remove_btn = '//*[@id="e"]'
    browser.find_element_by_xpath(e_remove_btn).click()

    key_path = '//*[@id="d-dialog"]/input[1]'
    value_path = '//*[@id="d-dialog"]/input[2]'
    add_new_path = '//*[@id="d-dialog"]/button'
    submit_path = '//*[@id="dict-edit-d-submit"]'

    browser.find_element_by_xpath(key_path).send_keys("phi")
    browser.find_element_by_xpath(value_path).send_keys("1.61")
    browser.find_element_by_xpath(add_new_path).click()
    browser.find_element_by_xpath(submit_path).click()
    time.sleep(0.5)
    inputs = props.inputs

    # string editor - set to "abcd"
    inputs.rows[9].cells[1].click()
    inputs[9][1] = "abcd"
    time.sleep(1)

    #enum editor - set to 3
    inputs = props.inputs
    inputs.rows[1].cells[1].click()
    selection_path = '//*[@id="editor-enum-e"]/option[4]'
    browser.find_element_by_xpath(selection_path).click()
    time.sleep(0.5)

    # float editor - set to 2.71
    inputs = props.inputs
    inputs.rows[2].cells[1].click()
    inputs[2][1] = '2.71'
    time.sleep(0.5)

    #bool editor - set to true
    inputs = props.inputs
    inputs.rows[10].cells[1].click()
    selection_path = '//*[@id="bool-editor-force_fd"]/option[1]'
    browser.find_element_by_xpath(selection_path).click()
    time.sleep(0.5)

    #array 1d editor - add element, set to 4
    inputs = props.inputs
    inputs.rows[3].cells[1].click()
    add_path = '//*[@id="array-edit-add-X"]'
    browser.find_element_by_xpath(add_path).click()
    new_cell_path = '//*[@id="array-editor-dialog-X"]/div/input[5]'
    new_cell = browser.find_element_by_xpath(new_cell_path)
    new_cell.clear()
    new_cell.send_keys("4.")
    submit_path = '//*[@id="array-edit-X-submit"]'
    browser.find_element_by_xpath(submit_path).click()
    time.sleep(0.5)

    #fixed array 1d editor - verify no add
    inputs = props.inputs
    inputs.rows[4].cells[1].click()
    add_path = '//*[@id="array-edit-add-Xfixed"]'
    browser.implicitly_wait(1)  # Not expecting to find anything.
    try:
        browser.find_element_by_xpath(add_path)
    except NoSuchElementException:
        pass
    else:
        raise TestCase.failureException('Expecting NoSuchElementException'
                                        ' for add-Xfixed')
    finally:
        browser.implicitly_wait(TMO)
    cancel_path = '//*[@id="array-edit-Xfixed-cancel"]'
    browser.find_element_by_xpath(cancel_path).click()
    time.sleep(0.5)

    # array 2d editor - set to [[1, 4],[9, 16]]
    inputs = props.inputs
    inputs.rows[5].cells[1].click()
    for i in range(1, 5):
        cell_path = '//*[@id="array-editor-dialog-Y"]/div/input[' + str(
            i) + ']'
        cell_input = browser.find_element_by_xpath(cell_path)
        cell_input.clear()
        cell_input.send_keys(str(i**2))
    submit_path = '//*[@id="array-edit-Y-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    # array 2d editor - special case for a bug - set to [[5],[7]]
    inputs = props.inputs
    inputs.rows[6].cells[1].click()
    cell_path = '//*[@id="array-editor-dialog-Y2"]/div/input[2]'
    cell_input = browser.find_element_by_xpath(cell_path)
    cell_input.clear()
    cell_input.send_keys(str(7))
    submit_path = '//*[@id="array-edit-Y2-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    # array 2d editor - special case for a bug - set to [[99]]
    inputs = props.inputs
    inputs.rows[7].cells[1].click()
    cell_path = '//*[@id="array-editor-dialog-Y3"]/div/input[1]'
    cell_input = browser.find_element_by_xpath(cell_path)
    cell_input.clear()
    cell_input.send_keys(str(99))
    submit_path = '//*[@id="array-edit-Y3-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    #list editor - set to [1, 2, 3, 4, 5]
    inputs = props.inputs
    eq(inputs[8][1].startswith("["), True)
    eq(inputs[8][1].endswith("]"), True)
    values = [
        int(value.strip()) for value in inputs[8][1].strip("[]").split(",")
    ]
    eq(len(values), 4)
    eq(values, [1, 2, 3, 4])

    values.append(5)
    values = str([value for value in values])
    inputs[8][1] = values

    props.close()

    #check that all values were set correctly by the editors
    commands = [
        "top.p1.d['pi']", "top.p1.d['phi']", "top.p1.e", "top.p1.x",
        "top.p1.X", "top.p1.directory", "top.p1.Z"
    ]
    values = [
        "3.0", "1.61", "3", "2.71", "[ 0.  1.  2.  3.  4.]", "abcd",
        "[1, 2, 3, 4, 5]"
    ]

    for cmd_str, check_val in zip(commands, values):
        workspace_page.do_command(cmd_str)
        output = workspace_page.history.split("\n")[-1]
        eq(output, check_val)

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y")
    output = workspace_page.history.split("\n")
    eq(output[-2], "[[ 1  4]")
    eq(output[-1], " [ 9 16]]")

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y2")
    output = workspace_page.history.split("\n")
    eq(output[-2], "[[5]")
    eq(output[-1], " [7]]")

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y3")
    output = workspace_page.history.split("\n")
    eq(output[-1], "[[99]]")

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_value_editors(browser):
    # Creates a file in the GUI.
    project_dict, workspace_page = startup(browser)

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

    workspace_page.add_library_item_to_dataflow('variable_editors.Topp', 'top')

    dummy_comp = workspace_page.get_dataflow_figure('p1', 'top')
    props = dummy_comp.properties_page()
    props.move(-100, -100)  # Ensure Project menu fully visible.
    inputs = props.inputs

    #edit dictionary - remove 'e', add 'phi', round down 'pi'
    #action_chain = ActionChains(browser)
    #action_chain.double_click(inputs.rows[0].cells[1]).perform()
    # Can't single click on an entry you are focused on, so focus on next line, then come back.
    inputs.rows[1].cells[1].click()
    inputs.rows[0].cells[1].click()

    pi_value_path = '//*[@id="d-editor"]/input[2]'
    pi_value = browser.find_element_by_xpath(pi_value_path)
    pi_value.clear()
    pi_value.send_keys("3.0")

    e_remove_btn = '//*[@id="e"]'
    browser.find_element_by_xpath(e_remove_btn).click()

    key_path = '//*[@id="d-dialog"]/input[1]'
    value_path = '//*[@id="d-dialog"]/input[2]'
    add_new_path = '//*[@id="d-dialog"]/button'
    submit_path = '//*[@id="dict-edit-d-submit"]'

    browser.find_element_by_xpath(key_path).send_keys("phi")
    browser.find_element_by_xpath(value_path).send_keys("1.61")
    browser.find_element_by_xpath(add_new_path).click()
    browser.find_element_by_xpath(submit_path).click()
    time.sleep(0.5)
    inputs = props.inputs

    # string editor - set to "abcd"
    inputs.rows[9].cells[1].click()
    inputs[9][1] = "abcd"
    time.sleep(1)

    #enum editor - set to 3
    inputs = props.inputs
    inputs.rows[1].cells[1].click()
    selection_path = '//*[@id="editor-enum-e"]/option[4]'
    browser.find_element_by_xpath(selection_path).click()
    time.sleep(0.5)

    # float editor - set to 2.71
    inputs = props.inputs
    inputs.rows[2].cells[1].click()
    inputs[2][1] = '2.71'
    time.sleep(0.5)

    #bool editor - set to true
    inputs = props.inputs
    inputs.rows[10].cells[1].click()
    selection_path = '//*[@id="bool-editor-force_fd"]/option[1]'
    browser.find_element_by_xpath(selection_path).click()
    time.sleep(0.5)

    #array 1d editor - add element, set to 4
    inputs = props.inputs
    inputs.rows[3].cells[1].click()
    add_path = '//*[@id="array-edit-add-X"]'
    browser.find_element_by_xpath(add_path).click()
    new_cell_path = '//*[@id="array-editor-dialog-X"]/div/input[5]'
    new_cell = browser.find_element_by_xpath(new_cell_path)
    new_cell.clear()
    new_cell.send_keys("4.")
    submit_path = '//*[@id="array-edit-X-submit"]'
    browser.find_element_by_xpath(submit_path).click()
    time.sleep(0.5)

    #fixed array 1d editor - verify no add
    inputs = props.inputs
    inputs.rows[4].cells[1].click()
    add_path = '//*[@id="array-edit-add-Xfixed"]'
    browser.implicitly_wait(1)  # Not expecting to find anything.
    try:
        browser.find_element_by_xpath(add_path)
    except NoSuchElementException:
        pass
    else:
        raise TestCase.failureException('Expecting NoSuchElementException'
                                        ' for add-Xfixed')
    finally:
        browser.implicitly_wait(TMO)
    cancel_path = '//*[@id="array-edit-Xfixed-cancel"]'
    browser.find_element_by_xpath(cancel_path).click()
    time.sleep(0.5)

    # array 2d editor - set to [[1, 4],[9, 16]]
    inputs = props.inputs
    inputs.rows[5].cells[1].click()
    for i in range(1, 5):
        cell_path = '//*[@id="array-editor-dialog-Y"]/div/input[' + str(i) + ']'
        cell_input = browser.find_element_by_xpath(cell_path)
        cell_input.clear()
        cell_input.send_keys(str(i**2))
    submit_path = '//*[@id="array-edit-Y-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    # array 2d editor - special case for a bug - set to [[5],[7]]
    inputs = props.inputs
    inputs.rows[6].cells[1].click()
    cell_path = '//*[@id="array-editor-dialog-Y2"]/div/input[2]'
    cell_input = browser.find_element_by_xpath(cell_path)
    cell_input.clear()
    cell_input.send_keys(str(7))
    submit_path = '//*[@id="array-edit-Y2-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    # array 2d editor - special case for a bug - set to [[99]]
    inputs = props.inputs
    inputs.rows[7].cells[1].click()
    cell_path = '//*[@id="array-editor-dialog-Y3"]/div/input[1]'
    cell_input = browser.find_element_by_xpath(cell_path)
    cell_input.clear()
    cell_input.send_keys(str(99))
    submit_path = '//*[@id="array-edit-Y3-submit"]'
    browser.find_element_by_xpath(submit_path).click()

    #list editor - set to [1, 2, 3, 4, 5]
    inputs = props.inputs
    eq(inputs[8][1].startswith("["), True)
    eq(inputs[8][1].endswith("]"), True)
    values = [int(value.strip()) for value in inputs[8][1].strip("[]").split(",")]
    eq(len(values), 4)
    eq(values, [1, 2, 3, 4])

    values.append(5)
    values = str([value for value in values])
    inputs[8][1] = values

    props.close()

    #check that all values were set correctly by the editors
    commands = ["top.p1.d['pi']",
                "top.p1.d['phi']",
                "top.p1.e",
                "top.p1.x",
                "top.p1.X",
                "top.p1.directory",
                "top.p1.Z"]
    values = ["3.0",
              "1.61",
              "3",
              "2.71",
              "[ 0.  1.  2.  3.  4.]",
              "abcd",
              "[1, 2, 3, 4, 5]"]

    for cmd_str, check_val in zip(commands, values):
        workspace_page.do_command(cmd_str)
        output = workspace_page.history.split("\n")[-1]
        eq(output, check_val)

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y")
    output = workspace_page.history.split("\n")
    eq(output[-2], "[[ 1  4]")
    eq(output[-1], " [ 9 16]]")

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y2")
    output = workspace_page.history.split("\n")
    eq(output[-2], "[[5]")
    eq(output[-1], " [7]]")

    #separate check for 2d arrays
    workspace_page.do_command("top.p1.Y3")
    output = workspace_page.history.split("\n")
    eq(output[-1], "[[99]]")

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 18
0
def _test_MDAO_MDF(browser):
    # Build the MDF model as per the tutorial.

    projects_page, project_info_page, project_dict, workspace_page = startup(
        browser)

    # Import the files that contain the disciplines
    file_path = pkg_resources.resource_filename('openmdao.lib.optproblems',
                                                'sellar.py')
    workspace_page.add_file(file_path)

    # Add Disciplines to assembly.
    workspace_page.show_dataflow('top')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline1', 'dis1')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline2', 'dis2')

    # Replace Run_Once with SLSQP
    workspace_page.replace('driver',
                           'openmdao.lib.drivers.slsqpdriver.SLSQPdriver')
    # Add Solver
    workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.drivers.iterate.FixedPointIterator',
        'solver',
        offset=(50, 50))

    # One data connection
    dis1 = workspace_page.get_dataflow_figure('dis1', 'top')
    dis2 = workspace_page.get_dataflow_figure('dis2', 'top')
    conn_page = workspace_page.connect(dis1, dis2)
    conn_page.connect_vars('dis1.y1', 'dis2.y1')
    conn_page.close()

    workspace_page('workflow_tab').click()
    workspace_page.show_workflow('top')

    # Add solver to optimizer workflow
    workspace_page.expand_object('top')
    workspace_page.add_object_to_workflow('top.solver', 'top')

    # Add disciplines to solver workflow
    workspace_page.expand_object('top.solver')
    workspace_page.add_object_to_workflow('top.dis1', 'solver')
    workspace_page.add_object_to_workflow('top.dis2', 'solver')

    workspace_page('dataflow_tab').click()

    # Configure Solver
    driver = workspace_page.get_dataflow_figure('solver', 'top')
    editor = driver.editor_page(base_type='Driver')

    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.y2'
    dialog.low = '-9.e99'
    dialog.high = '9.e99'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 - dis1.y2 = 0'
    dialog('ok').click()
    editor.close()

    # Configure Optimizer
    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 = 'dis1.z1,dis2.z1'
    dialog.low = '-10.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = 'dis1.z2,dis2.z2'
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = "dis1.x1"
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = '3.16 < dis1.y1'
    dialog('ok').click()

    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 < 24.0'
    dialog('ok').click()

    editor('objectives_tab').click()
    dialog = editor.new_objective()
    dialog.expr = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)'
    dialog('ok').click()
    editor.close()

    # Run the model
    workspace_page.run()

    # Check the objective
    workspace_page.do_command("top.dis1.z1")
    output1 = workspace_page.history.split("\n")[-1]
    workspace_page.do_command("top.dis1.z2")
    output2 = workspace_page.history.split("\n")[-1]

    if abs(float(output1) - 1.977657) > 0.01:
        raise TestCase.failureException(
            "Parameter z1 did not reach correct value, but instead is %s" %
            output1)

    if abs(float(output2) - 0.0) > 0.0001:
        raise TestCase.failureException(
            "Parameter z2 did not reach correct value, but instead is %s" %
            output2)

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

    # Check that adding a file enables commit.
    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()

    stl_path = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                               'files/box.stl')
    workspace_page.add_file(stl_path)
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names != ['box.stl']:
        raise TestCase.failureException('Expected box.stl, got %s' % file_names)

    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'), '')  # Enabled?
    workspace_page('project_menu').click()

    # Commit and check that commit is disabled but revert is enabled.
    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()                     # Disabled?

    # Remove file and check commit & revert enabled.
    workspace_page.delete_file('box.stl')
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names:
        raise TestCase.failureException('Unexpected files %s' % file_names)

    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()

    # revert back to version with file.
    workspace_page = workspace_page.revert_project()
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names != ['box.stl']:
        raise TestCase.failureException('Expected box.stl, got %s' % file_names)

    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()

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_MDAO_MDF(browser):
    # Build the MDF model as per the tutorial.
    
    projects_page, project_info_page, project_dict, workspace_page = startup(browser)
    
    # Import the files that contain the disciplines
    file_path = pkg_resources.resource_filename('openmdao.lib.optproblems',
                                                'sellar.py')
    workspace_page.add_file(file_path)
    
    # Add Disciplines to assembly.
    workspace_page.show_dataflow('top')
    workspace_page.add_library_item_to_dataflow(
        'sellar.Discipline1', 'dis1')
    workspace_page.add_library_item_to_dataflow(
        'sellar.Discipline2', 'dis2')

    # Replace Run_Once with SLSQP
    workspace_page.replace('driver',
                           'openmdao.lib.drivers.slsqpdriver.SLSQPdriver')
    # Add Solver
    workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.drivers.iterate.FixedPointIterator',
        'solver', offset=(50, 50))
    
    # One data connection
    dis1 = workspace_page.get_dataflow_figure('dis1', 'top')
    dis2 = workspace_page.get_dataflow_figure('dis2', 'top')
    conn_page = workspace_page.connect(dis1, dis2)
    conn_page.connect_vars('dis1.y1', 'dis2.y1')
    conn_page.close()
    
    workspace_page('workflow_tab').click()
    workspace_page.show_workflow('top')

    # Add solver to optimizer workflow
    workspace_page.expand_object('top')
    workspace_page.add_object_to_workflow('top.solver', 'top')
    
    # Add disciplines to solver workflow
    workspace_page.expand_object('top.solver')
    workspace_page.add_object_to_workflow('top.dis1', 'solver')
    workspace_page.add_object_to_workflow('top.dis2', 'solver')

    workspace_page('dataflow_tab').click()

    # Configure Solver
    driver = workspace_page.get_dataflow_figure('solver', 'top')
    editor = driver.editor_page(base_type='Driver')
    
    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.y2'
    dialog.low = '-9.e99'
    dialog.high = '9.e99'
    dialog('ok').click()
    
    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 - dis1.y2 = 0'
    dialog('ok').click()    
    editor.close()
    
    # Configure Optimizer
    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 = 'dis1.z1,dis2.z1'
    dialog.low = '-10.0'
    dialog.high = '10.0'
    dialog('ok').click()
    
    dialog = editor.new_parameter()
    dialog.target = 'dis1.z2,dis2.z2'
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()
    
    dialog = editor.new_parameter()
    dialog.target = "dis1.x1"
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()
    
    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = '3.16 < dis1.y1'
    dialog('ok').click()    
    
    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 < 24.0'
    dialog('ok').click()    
    
    editor('objectives_tab').click()
    dialog = editor.new_objective()
    dialog.expr = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)'
    dialog('ok').click()    
    editor.close()
    
    # Run the model
    workspace_page.run()
    
    # Check the objective
    workspace_page.do_command("top.dis1.z1")
    output1 = workspace_page.history.split("\n")[-1]
    workspace_page.do_command("top.dis1.z2")
    output2 = workspace_page.history.split("\n")[-1]

    if abs(float(output1) - 1.977657) > 0.01:
        raise TestCase.failureException(
            "Parameter z1 did not reach correct value, but instead is %s"
            % output1)

    if abs(float(output2) - 0.0) > 0.0001:
        raise TestCase.failureException(
            "Parameter z2 did not reach correct value, but instead is %s"
            % output2)

    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
Esempio n. 21
0
def _test_remove_files(browser):
    # Adds multiple files to the project.
    project_dict, workspace_page = startup(browser)

    # Add some files
    paraboloidPath = pkg_resources.resource_filename('openmdao.examples.simple',
                                                     'paraboloid.py')
    optPath = pkg_resources.resource_filename('openmdao.examples.simple',
                                              'optimization_unconstrained.py')
    workspace_page.add_file(paraboloidPath)
    workspace_page.add_file(optPath)

    expected_file_names = ['optimization_unconstrained.py', 'paraboloid.py']

    # Check to make sure the files were added.
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    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))

    # test delete file using context menu, but cancel the confirmation
    workspace_page.delete_file('paraboloid.py', False)

    # Check to make sure the file was NOT deleted
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    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))

    # test delete file using context menu
    workspace_page.delete_file('paraboloid.py')

    expected_file_names = ['optimization_unconstrained.py', ]

    # Check to make sure the file was deleted
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    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))

    # add more files
    file_path_one = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                                    'files/basic_model.py')
    file_path_two = pkg_resources.resource_filename('openmdao.examples.enginedesign',
                                                    'vehicle_singlesim.py')
    workspace_page.add_file(file_path_one)
    workspace_page.add_file(file_path_two)

    expected_file_names = ['optimization_unconstrained.py', 'basic_model.py', 'vehicle_singlesim.py']

    # Test deleting multiple files using the delete files pick
    #   on the Files menu, but cancel the confirmation
    workspace_page.delete_files(['vehicle_singlesim.py', 'optimization_unconstrained.py'], False)

    # toggle hidden files on and off to reset selected/highlighted files
    workspace_page.toggle_files()
    workspace_page.toggle_files()

    # Check to make sure the files were NOT deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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))

    # Test deleting multiple files using the delete files pick
    #   on the Files menu
    workspace_page.delete_files(['vehicle_singlesim.py', 'optimization_unconstrained.py'])

    expected_file_names = ['basic_model.py']

    # Check to make sure the files were deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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))

    # Test deleting a file in a folder
    workspace_page.new_folder('test_folder')
    time.sleep(1.0)
    workspace_page.add_file_to_folder('test_folder', paraboloidPath)
    time.sleep(2.0)
    workspace_page.expand_folder('test_folder')
    time.sleep(1.0)
    workspace_page.delete_files(['test_folder/paraboloid.py', ])

    expected_file_names = ['basic_model.py']

    # Check to make sure the file was deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    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(project_dict, workspace_page)
Esempio n. 22
0
def _test_Avartrees(browser):
    project_dict, workspace_page = startup(browser)

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

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

    comp = workspace_page.get_dataflow_figure('p1', "top")
    editor = comp.editor_page()
    editor.move(-100, 0)
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '',  '', ''],
        ['', '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])

    # Expand first vartree
    inputs.rows[0].cells[1].click()
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '',  '', ''],
        ['', 'v1', '1',  '', 'vv1'],
        ['', 'v2', '2',  '', 'vv2'],
        ['', ' vt2', '',  '', ''],
        ['', '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])

    # While expanded, verify that 'v1' is editable.
    inputs.rows[1].cells[2].click()
    inputs = editor.get_inputs()
    inputs[1][2] = "42"
    expected[1][2] = "42"

    time.sleep(0.5)
    inputs = editor.get_inputs()
#FIXME sometimes row 2 gets a value of '' because slickgrid is editing it.
#    for i, row in enumerate(inputs.value):
#        eq(row, expected[i])
    eq(inputs.value[1], expected[1])

    # While expanded, verify that cell that became the 2nd vartree is now
    # uneditable
    inputs.rows[3].cells[1].click()
    inputs = editor.get_inputs()
    try:
        inputs[3][2] = "abcd"
    except IndexError:
        pass
    else:
        raise TestCase.failureException(
            'Exception expected: VarTree value should not be settable on inputs.')

    # Contract first vartree
    inputs.rows[0].cells[1].click()
    inputs = editor.get_inputs()
    expected = [
        ['', ' cont_in', '',  '', ''],
        ['', '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])

    editor.close()

    # Now, do it all again on the Properties Pane
    workspace_page('properties_tab').click()
    obj = workspace_page.get_dataflow_figure('p1', 'top')
    chain = ActionChains(browser)
    chain.click(obj.root)
    chain.perform()
    inputs = workspace_page.props_inputs
    expected = [
        [' cont_in',      ''],
        ['directory',     ''],
        ['force_execute', 'False'],
    ]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # Expand first vartree
    inputs.rows[0].cells[0].click()
    inputs = workspace_page.props_inputs
    expected = [
        [' cont_in',      ''],
        ['v1', '42'],
        ['v2', '2'],
        [' vt2', ''],
        ['directory',     ''],
        ['force_execute', 'False'],
    ]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # While expanded, verify that 'v1' is editable.
    inputs.rows[1].cells[1].click()
    inputs = workspace_page.props_inputs
    inputs[1][1] = "43"
    expected[1][1] = "43"

    time.sleep(1)
    inputs = workspace_page.props_inputs
#FIXME sometimes row 2 gets a value of '' because slickgrid is editing it.
#    for i, row in enumerate(inputs.value):
#        eq(row, expected[i])
    eq(inputs.value[1], expected[1])

    # Contract first vartree
    inputs.rows[0].cells[0].click()
    inputs = workspace_page.props_inputs
    expected = [
        [' cont_in',      ''],
        ['directory',     ''],
        ['force_execute', 'False'],
    ]

    for i, row in enumerate(inputs.value):
        eq(row, expected[i])

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 23
0
def _test_MDAO_MDF(browser):
    # Build the MDF model as per the tutorial.

    project_dict, workspace_page = startup(browser)

    # Import the files that contain the disciplines
    file_path = pkg_resources.resource_filename('openmdao.lib.optproblems',
                                                'sellar.py')
    workspace_page.add_file(file_path)

    # Add Disciplines to assembly.
    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')
    workspace_page.show_dataflow('top')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline1', 'dis1')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline2', 'dis2')

    # Replace Run_Once with SLSQP
    workspace_page.replace_driver('top', 'SLSQPdriver')

    # Add Solver
    workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.drivers.iterate.FixedPointIterator',
        'solver')

    # One data connection
    dis1 = workspace_page.get_dataflow_figure('dis1', 'top')
    dis2 = workspace_page.get_dataflow_figure('dis2', 'top')
    conn_page = workspace_page.connect(dis1, dis2)
    conn_page.move(-100, -100)
    conn_page.connect_vars('dis1.y1', 'dis2.y1')
    conn_page.close()

    # Add solver to optimizer workflow
    workspace_page.add_object_to_workflow('top.solver', 'top')

    # Add disciplines to solver workflow
    workspace_page.expand_object('top')
    workspace_page.add_object_to_workflow('top.dis1', 'top.solver')
    workspace_page.add_object_to_workflow('top.dis2', 'top.solver')

    workspace_page('dataflow_tab').click()

    # Configure Solver
    driver = workspace_page.get_dataflow_figure('solver', 'top')
    editor = driver.editor_page(base_type='Driver')
    editor.move(-100, -100)

    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.y2'
    dialog.low = '-9.e99'
    dialog.high = '9.e99'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 - dis1.y2 = 0'
    dialog('ok').click()
    editor.close()

    # Configure Optimizer
    driver = workspace_page.get_dataflow_figure('driver', 'top')
    editor = driver.editor_page(base_type='Driver')
    editor.move(-100, -100)

    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.z1,dis2.z1'
    dialog.low = '-10.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = 'dis1.z2,dis2.z2'
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = "dis1.x1"
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = '3.16 < dis1.y1'
    dialog('ok').click()

    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 < 24.0'
    dialog('ok').click()

    editor('objectives_tab').click()
    dialog = editor.new_objective()
    dialog.expr = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)'
    dialog('ok').click()
    editor.close()

    # Get an implicitly connected output before the run.
    dis1_fig = workspace_page.get_dataflow_figure('dis1', 'top')
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[0][1:3], ['y1', '0'])
    editor.close()

    # Run the model
    top = workspace_page.get_dataflow_figure('top')
    top.run()
    message = NotifierPage.wait(workspace_page)
    eq(message, 'Run complete: success')

    # Verify implicitly connected output has been updated with valid result.
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[0][1], 'y1')
    dis1_y1 = float(outputs.value[0][2])
    if abs(dis1_y1 - 3.16) > 0.01:
        raise TestCase.failureException(
            "Output dis1.y1 did not reach correct value, but instead is %s"
            % dis1_y1)
    editor.close()

    # Check the objective
    workspace_page.do_command("top.dis1.z1")
    output1 = workspace_page.history.split("\n")[-1]
    workspace_page.do_command("top.dis1.z2")
    output2 = workspace_page.history.split("\n")[-1]

    if abs(float(output1) - 1.977657) > 0.01:
        raise TestCase.failureException(
            "Parameter z1 did not reach correct value, but instead is %s"
            % output1)

    if abs(float(output2) - 0.0) > 0.0001:
        raise TestCase.failureException(
            "Parameter z2 did not reach correct value, but instead is %s"
            % output2)

    # Clean up.
    closeout(project_dict, workspace_page)
def _test_palette_update(browser):
    # Import some files and add components from them.
    project_dict, workspace_page = startup(browser)

    # View dataflow.
    workspace_page('dataflow_tab').click()

    # Get file paths
    file1_path = pkg_resources.resource_filename('openmdao.examples.simple',
                                                 'paraboloid.py')
    file2_path = pkg_resources.resource_filename('openmdao.examples.simple',
                                                 'optimization_unconstrained.py')

    # add first file from workspace
    workspace_page.add_file(file1_path)

    # Open code editor.and add second file from there
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    time.sleep(0.5)
    editor_page.add_file(file2_path)

    # Check code editor to make sure the files were added.
    time.sleep(0.5)
    file_names = editor_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))

    # Back to workspace.
    browser.close()
    browser.switch_to_window(workspace_window)

    # Check workspace to make sure the files also show up there.
    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))

    # Make sure there are only two dataflow figures (top & driver)
    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')
    workspace_page.show_dataflow('top')
    eq(len(workspace_page.get_dataflow_figures()), 2)

    # Drag element into workspace.
    paraboloid_name = 'parab'
    workspace_page.add_library_item_to_dataflow('paraboloid.Paraboloid',
                                                paraboloid_name)

    # Now there should be three.
    eq(len(workspace_page.get_dataflow_figures()), 3)

    # Make sure the item added is there with the name we gave it.
    component_names = workspace_page.get_dataflow_component_names()
    if paraboloid_name not in component_names:
        raise TestCase.failureException(
            "Expected component name, '%s', to be in list of existing"
            " component names, '%s'" % (paraboloid_name, component_names))

    workspace_page.commit_project('added paraboloid')
    projects_page = workspace_page.close_workspace()

    # Now try to re-open that project to see if items are still there.
    #project_info_page = projects_page.edit_project(project_dict['name'])
    workspace_page = projects_page.open_project(project_dict['name'])

    # Check to see that the added files are still there.
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    file_names = editor_page.get_files()
    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))
    browser.close()
    browser.switch_to_window(workspace_window)

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 25
0
"""
declassified methods from unittest.TestCase
"""


from unittest import TestCase

from .general import WooperAssertionError


assertions = TestCase()
assertions.failureException = WooperAssertionError
assertions._diffThreshold = 2**16
assertions._maxDiff = None
assertions.DIFF_OMITTED = ('\nDiff is %s characters long. '
                           'Set self.maxDiff to None to see it.')
assertions._MAX_LENGTH = 80
assertions._PLACEHOLDER_LEN = 12
assertions._MIN_BEGIN_LEN = 5
assertions._MIN_END_LEN = 5
assertions._MIN_COMMON_LEN = 5


# def assert_is_instance(obj, cls, msg=None):
#     """Same as self.assertTrue(isinstance(obj, cls)), with a nicer
#     default message."""
#     return assertions.assertIsInstance(obj, cls, msg)


def assert_equal(first, second, msg=None):
    """Fail if the two objects are unequal as determined by the '=='
Esempio n. 26
0
def _test_remove_files(browser):
    # Adds multiple files to the project.
    project_dict, workspace_page = startup(browser)

    # Add some files
    paraboloidPath = pkg_resources.resource_filename(
        'openmdao.examples.simple', 'paraboloid.py')
    optPath = pkg_resources.resource_filename('openmdao.examples.simple',
                                              'optimization_unconstrained.py')
    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))

    # delete using context menu the file paraboloid.py
    workspace_page.delete_file('paraboloid.py')

    # Check to make sure the file was deleted
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    expected_file_names = [
        'optimization_unconstrained.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))

    # add more files
    file_path_one = pkg_resources.resource_filename(
        'openmdao.gui.test.functional', 'files/basic_model.py')
    file_path_two = pkg_resources.resource_filename(
        'openmdao.examples.enginedesign', 'vehicle_singlesim.py')
    workspace_page.add_file(file_path_one)
    workspace_page.add_file(file_path_two)

    # Test deleting the paraboloid and opt files at one time using the delete files pick
    #   on the Files menu
    workspace_page.delete_files(
        ['vehicle_singlesim.py', 'optimization_unconstrained.py'])

    # Check to make sure the files were deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    expected_file_names = ['basic_model.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))

    # Test deleting a file in a folder
    workspace_page.new_folder("test_folder")
    time.sleep(1.0)
    workspace_page.add_file_to_folder("test_folder", paraboloidPath)
    time.sleep(1.0)
    workspace_page.expand_folder('test_folder')
    time.sleep(1.0)
    workspace_page.delete_files([
        'test_folder/paraboloid.py',
    ])

    # Check to make sure the file was deleted
    time.sleep(1.5)
    file_names = workspace_page.get_files()
    expected_file_names = ['basic_model.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(project_dict, workspace_page)
Esempio n. 27
0
def _test_file_commit(browser):
    project_dict, workspace_page = startup(browser)

    # Check that adding a file enables commit.
    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()

    stl_path = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                               'files/box.stl')
    workspace_page.add_file(stl_path)
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names != ['box.stl']:
        raise TestCase.failureException('Expected box.stl, got %s' %
                                        file_names)

    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'), '')  # Enabled?
    workspace_page('project_menu').click()

    # Commit and check that commit is disabled but revert is enabled.
    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()  # Disabled?

    # Remove file and check commit & revert enabled.
    workspace_page.delete_file('box.stl')
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names:
        raise TestCase.failureException('Unexpected files %s' % file_names)

    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()

    # revert back to version with file.
    workspace_page = workspace_page.revert_project()
    time.sleep(0.5)
    file_names = workspace_page.get_files()
    if file_names != ['box.stl']:
        raise TestCase.failureException('Expected box.stl, got %s' %
                                        file_names)

    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()

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 28
0
def _test_palette_update(browser):
    # Import some files and add components from them.
    projects_page, project_info_page, project_dict, workspace_page = startup(
        browser)

    # View the Workflow Pane.
    workspace_page('workflow_tab').click()
    time.sleep(0.5)  # Just so we can see it.

    # View dataflow.
    workspace_page('dataflow_tab').click()

    # Get file paths
    file1_path = pkg_resources.resource_filename('openmdao.examples.simple',
                                                 'paraboloid.py')
    file2_path = pkg_resources.resource_filename(
        'openmdao.examples.simple', 'optimization_unconstrained.py')
    # add first file from workspace
    workspace_page.add_file(file1_path)

    # Open code editor.and add second file from there
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    time.sleep(0.5)
    editor_page.add_file(file2_path)

    # Check code editor to make sure the files were added.
    time.sleep(0.5)
    file_names = editor_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))

    # Back to workspace.
    browser.close()
    browser.switch_to_window(workspace_window)

    # Check workspace to make sure the files also show up there.
    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))

    # Make sure there are only two dataflow figures (top & driver)
    workspace_page.show_dataflow('top')
    eq(len(workspace_page.get_dataflow_figures()), 2)

    # Drag element into workspace.
    paraboloid_name = 'parab'
    workspace_page.add_library_item_to_dataflow('paraboloid.Paraboloid',
                                                paraboloid_name)
    # Now there should be three.
    eq(len(workspace_page.get_dataflow_figures()), 3)

    # Make sure the item added is there with the name we gave it.
    component_names = workspace_page.get_dataflow_component_names()
    if paraboloid_name not in component_names:
        raise TestCase.failureException(
            "Expected component name, '%s', to be in list of existing"
            " component names, '%s'" % (paraboloid_name, component_names))

    workspace_page.commit_project('added paraboloid')
    projects_page = workspace_page.close_workspace()

    # Now try to re-open that project to see if items are still there.
    project_info_page = projects_page.edit_project(project_dict['name'])
    workspace_page = project_info_page.load_project()

    # Check to see that the added files are still there.
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    file_names = editor_page.get_files()
    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))
    browser.close()
    browser.switch_to_window(workspace_window)

    # Clean up.
    closeout(projects_page, project_info_page, project_dict, workspace_page)
Esempio n. 29
0
from unittest import TestCase

from nose.tools import eq_

from grail import step
from tests.utils import validate_method_output

failure_exception = TestCase.failureException('Failure exception')
error_exception = Exception('Error exception')


@step
def passed_step():
    pass


@step
def failed_step():
    raise failure_exception


@step
def error_step():
    raise error_exception


def method_fail():
    passed_step()
    failed_step()
    raise Exception('we should not reach this')
def _test_MDAO_MDF(browser):
    # Build the MDF model as per the tutorial.

    project_dict, workspace_page = startup(browser)

    # Import the files that contain the disciplines
    file_path = pkg_resources.resource_filename('openmdao.lib.optproblems',
                                                'sellar.py')
    workspace_page.add_file(file_path)

    # Add Disciplines to assembly.
    workspace_page.add_library_item_to_dataflow('openmdao.main.assembly.Assembly', 'top')
    workspace_page.show_dataflow('top')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline1', 'dis1')
    workspace_page.add_library_item_to_dataflow('sellar.Discipline2', 'dis2')

    # Replace Run_Once with SLSQP
    workspace_page.replace_driver('top', 'SLSQPdriver')

    # Add Solver
    workspace_page.add_library_item_to_dataflow(
        'openmdao.lib.drivers.iterate.FixedPointIterator',
        'solver')

    # One data connection
    dis1 = workspace_page.get_dataflow_figure('dis1', 'top')
    dis2 = workspace_page.get_dataflow_figure('dis2', 'top')
    conn_page = workspace_page.connect(dis1, dis2)
    conn_page.move(-100, -100)
    conn_page.connect_vars('dis1.y1', 'dis2.y1')
    conn_page.close()

    # Add solver to optimizer workflow
    workspace_page.add_object_to_workflow('top.solver', 'top')

    # Add disciplines to solver workflow
    workspace_page.expand_object('top')
    workspace_page.add_object_to_workflow('top.dis1', 'top.solver')
    workspace_page.add_object_to_workflow('top.dis2', 'top.solver')

    workspace_page('dataflow_tab').click()

    # Configure Solver
    driver = workspace_page.get_dataflow_figure('solver', 'top')
    editor = driver.editor_page(base_type='Driver')
    editor.move(-100, -100)

    editor('inputs_tab').click()

    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.y2'
    dialog.low = '-9.e99'
    dialog.high = '9.e99'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 = dis1.y2'
    dialog('ok').click()
    editor.close()

    # Configure Optimizer
    driver = workspace_page.get_dataflow_figure('driver', 'top')
    editor = driver.editor_page(base_type='Driver')
    editor.move(-100, -100)

    editor('parameters_tab').click()
    dialog = editor.new_parameter()
    dialog.target = 'dis1.z1,dis2.z1'
    dialog.low = '-10.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = 'dis1.z2,dis2.z2'
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    dialog = editor.new_parameter()
    dialog.target = "dis1.x1"
    dialog.low = '0.0'
    dialog.high = '10.0'
    dialog('ok').click()

    editor('constraints_tab').click()
    dialog = editor.new_constraint()
    dialog.expr = '3.16 < dis1.y1'
    dialog('ok').click()

    dialog = editor.new_constraint()
    dialog.expr = 'dis2.y2 < 24.0'
    dialog('ok').click()

    editor('objectives_tab').click()
    dialog = editor.new_objective()
    dialog.expr = '(dis1.x1)**2 + dis1.z2 + dis1.y1 + math.exp(-dis2.y2)'
    dialog('ok').click()
    editor.close()

    # Set Initial Conditions
    workspace_page.do_command("top.dis1.z1 = top.dis2.z1 = 5.0")
    workspace_page.do_command("top.dis1.z2 = top.dis2.z2 = 2.0")
    workspace_page.do_command("top.dis1.x1 = 1.0")
    workspace_page.do_command("top.solver.tolerance = .00001")

    # Get an implicitly connected output before the run.
    dis1_fig = workspace_page.get_dataflow_figure('dis1', 'top')
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[0][1:3], ['y1', '0'])
    editor.close()

    # Run the model
    top = workspace_page.get_dataflow_figure('top')
    top.run()
    message = NotifierPage.wait(workspace_page)
    eq(message, 'Run complete: success')

    # Verify implicitly connected output has been updated with valid result.
    editor = dis1_fig.editor_page()
    outputs = editor.get_outputs()
    eq(outputs.value[0][1], 'y1')
    dis1_y1 = float(outputs.value[0][2])
    if abs(dis1_y1 - 3.16) > 0.01:
        raise TestCase.failureException(
            "Output dis1.y1 did not reach correct value, but instead is %s"
            % dis1_y1)
    editor.close()

    # Check the objective
    workspace_page.do_command("top.dis1.z1")
    output1 = workspace_page.history.split("\n")[-1]
    workspace_page.do_command("top.dis1.z2")
    output2 = workspace_page.history.split("\n")[-1]

    if abs(float(output1) - 1.977657) > 0.01:
        raise TestCase.failureException(
            "Parameter z1 did not reach correct value, but instead is %s"
            % output1)

    if abs(float(output2) - 0.0) > 0.0001:
        raise TestCase.failureException(
            "Parameter z2 did not reach correct value, but instead is %s"
            % output2)

    # Clean up.
    closeout(project_dict, workspace_page)
Esempio n. 31
0
from unittest import TestCase

from nose.tools import eq_

from grail import step
from tests.utils import validate_method_output


failure_exception = TestCase.failureException('Failure exception')
error_exception = Exception('Error exception')


@step
def passed_step():
    pass


@step
def failed_step():
    raise failure_exception


@step
def error_step():
    raise error_exception


def method_fail():
    passed_step()
    failed_step()
    raise Exception('we should not reach this')