コード例 #1
0
def _test_properties(browser):
    print "running _test_properties..."
    # Checks right-hand side properties display.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # Check default 'top'.
    workspace_page.select_object('top')
    time.sleep(0.5)
    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', '[]']])
    # 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_properties complete."
コード例 #2
0
def _test_menu(browser):
    print "running _test_menu..."
    # Just click on various main menu buttons.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # 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', 'libraries', 'objects', '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.
    projects_page = workspace_page.close_workspace()
    project_info_page = projects_page.edit_project(project_dict['name'])
    project_info_page.delete_project()
    print "_test_menu complete."
コード例 #3
0
def _test_new_project(browser):

    browser_download_location_path = get_browser_download_location_path(browser)

    projects_page = begin(browser)

    # Create a project.
    projects_page, project_dict = new_project(projects_page.new_project(),
                                              verify=True, load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'])  # maxlength

    # Edit the project meta data
    project_dict['description'] = "pony express"
    project_dict['version'] = "23432"

    projects_page = edit_project(edit_dialog,
                         project_dict['name'],
                         project_dict['description'],
                         project_dict['version'],
                         load_workspace=False)

    # Make sure all the new project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'][:5])  # maxlength
    edit_dialog.cancel()

    # Export the project
    projects_page.export_project(project_dict['name'])
    time.sleep(5)  # give the download some time (ok LOTS of time) to complete
    # See if the file is in the downloads directory
    project_path = glob.glob(os.path.join(browser_download_location_path + "/" + project_dict['name'].replace(" ", "_")) + "*")
    assert (len(project_path) == 1)

    # Delete the project in preparation for reimporting
    projects_page.delete_project(project_dict['name'])

    # Make sure the project was deleted
    assert not projects_page.contains(project_dict['name'])

    # Import the project and give it a new name
    projects_page, project_dict = import_project(projects_page.import_project(), project_path,
                                              verify=True, load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # remove the downloaded file
    os.remove(project_path[0])
コード例 #4
0
def _test_console(browser):
    print "running _test_console..."
    # Check basic console functionality.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    workspace_page.do_command('dir()')
    expected = ">>> dir()\n['__builtins__', 'path', 'top']"
    eq(workspace_page.history, expected)

    # 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_console complete."
コード例 #5
0
def _test_new_project(browser):
    projects_page = begin(browser)

    # Create a project.
    project_info_page, project_dict = new_project(projects_page.new_project())

    # Go back to projects page to see if it is on the list.
    projects_page = project_info_page.go_to_projects_page()
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    project_info_page = projects_page.edit_project(project_dict['name'])
    eq(project_info_page.project_name, project_dict['name'])
    eq(project_info_page.description, project_dict['description'])
    eq(project_info_page.version, project_dict['version'][:5])  # maxlength

    # Clean up.
    project_info_page.delete_project()
コード例 #6
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."
コード例 #7
0
def _test_new_project(browser):
    projects_page = begin(browser)

    # Create a project.
    project_info_page, project_dict = new_project(projects_page.new_project(),
                                                  verify=True)

    # Go back to projects page to see if it is on the list.
    projects_page = project_info_page.go_to_projects_page()
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    project_info_page = projects_page.edit_project(project_dict['name'])
    eq(project_info_page.project_name, project_dict['name'])
    eq(project_info_page.description, project_dict['description'])
    eq(project_info_page.version, project_dict['version'][:5])  # maxlength

    # Clean up.
    project_info_page.delete_project()
コード例 #8
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."
コード例 #9
0
def _test_last_saved_metadata(browser):

    def last_saved(target):
        def wrapper(projects_page, project_name, timestamp, *args, **kargs):
            workspace_page = projects_page.open_project(project_name)
            result = target(workspace_page)

            projects_page = workspace_page.close_workspace()

            if result is False:
                last_saved = timestamp
            else:
                metadata = projects_page.get_project_metadata(project_name)
                last_saved = date_to_datetime(metadata['last_saved'])
                assert(last_saved > timestamp)

            return projects_page, project_name, last_saved

        return wrapper

    def date_to_datetime(date):
        date_regex = re.compile("(\d+)-(\d+)-(\d+)")
        time_regex = re.compile("(\d+):(\d+):(\d+)")

        match_object = date_regex.search(date)
        year  = int(match_object.group(1))
        month = int(match_object.group(2))
        day   = int(match_object.group(3))

        match_object = time_regex.search(date)
        hours   = int(match_object.group(1))
        minutes = int(match_object.group(2))
        seconds = int(match_object.group(3))

        return datetime.datetime(year, month, day, hours, minutes, seconds)

    @last_saved
    def add_file(workspace_page):
        file_path = pkg_resources.resource_filename('openmdao.gui.test.functional', 'files/simple_paraboloid.py')
        workspace_page.add_file(file_path)

    @last_saved
    def new_file(workspace_page):
        workspace_page.new_file('test_file.py')

    @last_saved
    def rename_file(workspace_page):
        workspace_page.get_files()
        workspace_page.rename_file('test_file.py', 'best_file.py')

    @last_saved
    def edit_file(workspace_page):
        if broken_chrome():
            print "Skipping testing metadata after editing file due to broken chrome driver."
            return False

        workspace_window = browser.current_window_handle

        editor_page = workspace_page.open_editor()
        editor_page.edit_file('test_file.py', dclick=False)
        editor_page.add_text_to_file('#just a comment\n')
        editor_page.save_document(check=False)

        browser.switch_to_window(workspace_window)
        port = workspace_page.port
        workspace_page = WorkspacePage.verify(browser, port)

    @last_saved
    def delete_file(workspace_page):
        workspace_page.delete_file('best_file.py')

    @last_saved
    def add_object(workspace_page):
        workspace_page.add_library_item_to_dataflow("openmdao.main.assembly.Assembly", 'top')

    @last_saved
    def replace_object(workspace_page):
        workspace_page.replace_driver("top", 'SLSQPdriver')

    @last_saved
    def commit_project(workspace_page):
        top = workspace_page.get_dataflow_figure('top')
        top.remove()
        workspace_page.commit_project()

    @last_saved
    def revert_project(workspace_page):
        workspace_page.add_library_item_to_dataflow("openmdao.main.assembly.Assembly", 'top')
        workspace_page = workspace_page.revert_project()


    projects_page = begin(browser)
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True, load_workspace=False)

    project_name = project_dict['name']
    metadata = projects_page.get_project_metadata(project_name)
    created_time = date_to_datetime(metadata['created'])

    #Testing metadata for file operations
    projects_page, project_name, add_file_time       = add_file(projects_page, project_name, created_time)
    projects_page, project_name, new_file_time       = new_file(projects_page, project_name, add_file_time)
    projects_page, project_name, edit_file_time      = edit_file(projects_page, project_name, new_file_time)
    projects_page, project_name, rename_file_time    = rename_file(projects_page, project_name, edit_file_time)
    projects_page, project_name, delete_file_time    = delete_file(projects_page, project_name, rename_file_time)

    #Testing metadata for project operations
    projects_page, project_name, add_object_time     = add_object(projects_page, project_name, delete_file_time)
    projects_page, project_name, replace_object_time = replace_object(projects_page, project_name, add_object_time)
    projects_page, project_name, commit_project_time = commit_project(projects_page, project_name, replace_object_time)
    projects_page, project_name, revert_project_time = revert_project(projects_page, project_name, commit_project_time)

    projects_page.delete_project(project_name)
コード例 #10
0
def _test_last_saved_metadata(browser):
    def last_saved(target):
        def wrapper(projects_page, project_name, timestamp, *args, **kargs):
            workspace_page = projects_page.open_project(project_name)
            result = target(workspace_page)

            projects_page = workspace_page.close_workspace()

            if result is False:
                last_saved = timestamp
            else:
                metadata = projects_page.get_project_metadata(project_name)
                last_saved = date_to_datetime(metadata['last_saved'])
                assert (last_saved > timestamp)

            return projects_page, project_name, last_saved

        return wrapper

    def date_to_datetime(date):
        date_regex = re.compile("(\d+)-(\d+)-(\d+)")
        time_regex = re.compile("(\d+):(\d+):(\d+)")

        match_object = date_regex.search(date)
        year = int(match_object.group(1))
        month = int(match_object.group(2))
        day = int(match_object.group(3))

        match_object = time_regex.search(date)
        hours = int(match_object.group(1))
        minutes = int(match_object.group(2))
        seconds = int(match_object.group(3))

        return datetime.datetime(year, month, day, hours, minutes, seconds)

    @last_saved
    def add_file(workspace_page):
        file_path = pkg_resources.resource_filename(
            'openmdao.gui.test.functional', 'files/simple_paraboloid.py')
        workspace_page.add_file(file_path)

    @last_saved
    def new_file(workspace_page):
        workspace_page.new_file('test_file.py')

    @last_saved
    def rename_file(workspace_page):
        workspace_page.get_files()
        workspace_page.rename_file('test_file.py', 'best_file.py')

    @last_saved
    def edit_file(workspace_page):
        if broken_chrome():
            print "Skipping testing metadata after editing file due to broken chrome driver."
            return False

        workspace_window = browser.current_window_handle

        editor_page = workspace_page.open_editor()
        editor_page.edit_file('test_file.py', dclick=False)
        editor_page.add_text_to_file('#just a comment\n')
        editor_page.save_document(check=False)

        browser.switch_to_window(workspace_window)
        port = workspace_page.port
        workspace_page = WorkspacePage.verify(browser, port)

    @last_saved
    def delete_file(workspace_page):
        workspace_page.delete_file('best_file.py')

    @last_saved
    def add_object(workspace_page):
        workspace_page.add_library_item_to_dataflow(
            "openmdao.main.assembly.Assembly", 'top')

    @last_saved
    def replace_object(workspace_page):
        workspace_page.replace_driver("top", 'SLSQPdriver')

    @last_saved
    def commit_project(workspace_page):
        top = workspace_page.get_dataflow_figure('top')
        top.remove()
        workspace_page.commit_project()

    @last_saved
    def revert_project(workspace_page):
        workspace_page.add_library_item_to_dataflow(
            "openmdao.main.assembly.Assembly", 'top')
        workspace_page = workspace_page.revert_project()

    projects_page = begin(browser)
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True,
                                                 load_workspace=False)

    project_name = project_dict['name']
    metadata = projects_page.get_project_metadata(project_name)
    created_time = date_to_datetime(metadata['created'])

    #Testing metadata for file operations
    projects_page, project_name, add_file_time = add_file(
        projects_page, project_name, created_time)
    projects_page, project_name, new_file_time = new_file(
        projects_page, project_name, add_file_time)
    projects_page, project_name, edit_file_time = edit_file(
        projects_page, project_name, new_file_time)
    projects_page, project_name, rename_file_time = rename_file(
        projects_page, project_name, edit_file_time)
    projects_page, project_name, delete_file_time = delete_file(
        projects_page, project_name, rename_file_time)

    #Testing metadata for project operations
    projects_page, project_name, add_object_time = add_object(
        projects_page, project_name, delete_file_time)
    projects_page, project_name, replace_object_time = replace_object(
        projects_page, project_name, add_object_time)
    projects_page, project_name, commit_project_time = commit_project(
        projects_page, project_name, replace_object_time)
    projects_page, project_name, revert_project_time = revert_project(
        projects_page, project_name, commit_project_time)

    projects_page.delete_project(project_name)
コード例 #11
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."
コード例 #12
0
def _test_connections(browser):
    print "running _test_connections..."
    # Check connection frame functionality.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    filename = pkg_resources.resource_filename(
        'openmdao.examples.enginedesign', 'vehicle_singlesim.py')
    editor_page.add_file(filename)
    browser.close()
    browser.switch_to_window(workspace_window)

    # Replace 'top' with VehicleSim.
    top = workspace_page.get_dataflow_figure('top')
    top.remove()
    workspace_page('libraries_tab').click()
    for retry in range(2):
        try:
            workspace_page.find_palette_button('VehicleSim').click()
        except StaleElementReferenceException:
            logging.warning('StaleElementReferenceException in _test_connect')
        else:
            break
    else:
        raise RuntimeError('Too many StaleElementReferenceExceptions')
    asm_name = 'sim'
    workspace_page.add_library_item_to_dataflow('vehicle_singlesim.VehicleSim',
                                                asm_name)

    # show dataflow for vehicle
    workspace_page.expand_object('sim')
    time.sleep(1)
    workspace_page.show_dataflow('sim.vehicle')
    vehicle = workspace_page.get_dataflow_figure('vehicle', 'sim')

    # no connections between assembly vars
    conn_page = vehicle.connections_page()
    eq(conn_page.dialog_title, 'Connections: vehicle')
    eq(conn_page.source_component, '<Assembly>')
    eq(conn_page.destination_component, '<Assembly>')
    eq(len(conn_page.get_variable_figures()), 0)

    # one connection between transmission and engine (RPM)
    conn_page.source_component = 'transmission\n'
    conn_page.destination_component = 'engine\n'
    time.sleep(1)
    eq(conn_page.source_variable, '')
    eq(conn_page.destination_variable, '')
    eq(len(conn_page.get_variable_figures()), 2)

    # two connections between engine and chassis
    conn_page.source_component = 'engine\n'
    conn_page.destination_component = 'chassis\n'
    time.sleep(1)
    eq(conn_page.source_variable, '')
    eq(conn_page.destination_variable, '')
    eq(len(conn_page.get_variable_figures()), 4)

    # disconnect transmission
    tranny = workspace_page.get_dataflow_figure('transmission', 'sim.vehicle')
    tranny.disconnect()

    # now there are no connections between transmission and engine
    conn_page.source_component = 'transmission\n'
    conn_page.destination_component = 'engine\n'
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 0)

    # reconnect transmission RPM to engine RPM
    conn_page.connect_vars('transmission.RPM', 'engine.RPM')
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 2)

    # no connections between transmission and chassis
    conn_page.destination_component = 'chassis\n'
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 0)

    # reconnect transmission torque torque to chassis torque
    conn_page.connect_vars('transmission.torque_ratio', 'chassis.torque_ratio')
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 2)

    # no connections between vehicle assembly and transmission
    conn_page.source_component = '\n'
    conn_page.destination_component = 'transmission\n'
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 0)

    # connect assembly variable to component variable
    conn_page.connect_vars('current_gear', 'transmission.current_gear')
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 2)

    # one connection from chassis component to vehicle assembly
    conn_page.source_component = 'chassis\n'
    conn_page.destination_component = '\n'
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 2)

    # disconnect chassis
    conn_page.close()
    chassis = workspace_page.get_dataflow_figure('chassis', 'sim.vehicle')
    chassis.disconnect()
    vehicle = workspace_page.get_dataflow_figure('vehicle', 'sim')
    conn_page = vehicle.connections_page()
    time.sleep(1)
    eq(len(conn_page.get_variable_figures()), 0)

    # connect component variable to assembly variable
    conn_page.connect_vars('chassis.acceleration', 'acceleration')
    time.sleep(1)
    conn_page.source_component = 'chassis\n'
    eq(len(conn_page.get_variable_figures()), 2)

    conn_page.close()

    # 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_connections complete."
コード例 #13
0
def _test_connect(browser):
    print "running _test_connect..."
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # Import connect.py
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    file_path = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                                'connect.py')
    editor_page.add_file(file_path)
    browser.close()
    browser.switch_to_window(workspace_window)

    # Replace 'top' with connect.py's top.
    top = workspace_page.get_dataflow_figure('top')
    top.remove()
    workspace_page('libraries_tab').click()
    for retry in range(5):
        try:
            workspace_page.find_palette_button('Top').click()
        except StaleElementReferenceException:
            logging.warning('StaleElementReferenceException in _test_connect')
        else:
            break
    else:
        raise RuntimeError('Too many StaleElementReferenceExceptions')
    workspace_page.add_library_item_to_dataflow('connect.Top', 'top')

    # Connect components.
    workspace_page.show_dataflow('top')
    comp1 = workspace_page.get_dataflow_figure('comp1', 'top')
    comp2 = workspace_page.get_dataflow_figure('comp2', 'top')
    conn_page = workspace_page.connect(comp1, comp2)
    eq(conn_page.dialog_title, 'Connections: top')
    for prefix in ('b', 'e', 'f', 'i', 's'):
        conn_page.connect_vars('comp1.' + prefix + '_out',
                               'comp2.' + prefix + '_in')
        time.sleep(0.5)  # Wait for display update.
    conn_page.close()

    # Set inputs (re-fetch required after updating).
    comp1 = workspace_page.get_dataflow_figure('comp1', 'top')
    props = comp1.properties_page()
    eq(props.header, 'Connectable: top.comp1')
    inputs = props.inputs
    eq(inputs[0].value, ['b_in', 'False'])
    inputs[0][1] = 'True'
    inputs = props.inputs
    eq(inputs[2].value, ['e_in', '1'])
    inputs[2][1] = '3'
    inputs = props.inputs
    eq(inputs[3].value, ['f_in', '0.0'])
    inputs[3][1] = '2.781828'
    inputs = props.inputs
    eq(inputs[5].value, ['i_in', '0'])
    inputs[5][1] = '42'
    inputs = props.inputs
    eq(inputs[6].value, ['s_in', ''])
    inputs[6][1] = "'xyzzy'"
    props.close()

    # Run the simulation.
    workspace_page.run()

    # Verify outputs.
    comp2 = workspace_page.get_dataflow_figure('comp2', 'top')
    editor = comp2.editor_page()
    eq(editor.dialog_title, 'Connectable: top.comp2')
    outputs = editor.get_outputs()
    expected = [['b_out', 'bool', 'True', '', 'true', '', ''],
                ['e_out', 'int', '3', '', 'true', '', ''],
                ['f_out', 'float', '2.781828', '', 'true', '', ''],
                ['i_out', 'int', '42', '', 'true', '', ''],
                ['s_out', 'str', 'xyzzy', '', 'true', '', '']]
    for i, row in enumerate(outputs.value):
        eq(row, expected[i])
    editor.close()

    # 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_connect complete."
コード例 #14
0
def _test_projects_begone(browser):
    projects_page = begin(browser)
    projects_page.delete_all_test_projects(True)
コード例 #15
0
def _test_projects_begone(browser):
    projects_page = begin(browser)
    projects_page.delete_all_test_projects(True)
コード例 #16
0
def _test_maxmin(browser):
    print "running _test_maxmin..."
    # Toggles maxmimize/minimize button on assemblies.
    projects_page = begin(browser)
    project_info_page, project_dict = new_project(projects_page.new_project())
    workspace_page = project_info_page.load_project()

    # verify that the globals figure is invisible
    globals_figure = workspace_page.get_dataflow_figure('')
    eq(globals_figure.border.find('none') >= 0, True)
    eq(globals_figure.background_color, 'rgba(0, 0, 0, 0)')

    # Add maxmin.py to project
    workspace_window = browser.current_window_handle
    editor_page = workspace_page.open_editor()
    file_path = pkg_resources.resource_filename('openmdao.gui.test.functional',
                                                'maxmin.py')
    editor_page.add_file(file_path)
    browser.close()
    browser.switch_to_window(workspace_window)

    # Add MaxMin to 'top'.
    workspace_page.show_dataflow('top')
    time.sleep(1)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'top'])
    workspace_page('libraries_tab').click()
    time.sleep(1)
    workspace_page.find_palette_button('MaxMin').click()
    workspace_page.add_library_item_to_dataflow('maxmin.MaxMin', 'maxmin')
    time.sleep(1)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'maxmin', 'top'])

    workspace_page.hide_left()
    workspace_page.hide_right()
    workspace_page.hide_console()

    # Maximize maxmin.
    maxmin = workspace_page.get_dataflow_figure('maxmin')
    background = maxmin('top_right').value_of_css_property('background')
    eq(background.find('circle-plus.png') >= 0, True)

    maxmin('top_right').click()
    background = maxmin('top_right').value_of_css_property('background')
    time.sleep(1)
    eq(background.find('circle-minus.png') >= 0, True)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'driver', 'maxmin', 'sub', 'top'])

    sub = workspace_page.get_dataflow_figure('sub')
    sub('top_right').click()
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'driver', 'driver', 'extcode', 'maxmin', 'sub', 'top'])

    # issue a command and make sure maxmin is still maximized
    workspace_page.show_console()
    time.sleep(0.5)
    workspace_page.do_command('dir()')
    background = maxmin('top_right').value_of_css_property('background')
    eq(background.find('circle-minus.png') >= 0, True)
    time.sleep(1)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'driver', 'driver', 'extcode', 'maxmin', 'sub', 'top'])

    # Minimize sub
    sub('top_right').click()
    background = sub('top_right').value_of_css_property('background')
    eq(background.find('circle-plus.png') >= 0, True)
    time.sleep(1)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'driver', 'maxmin', 'sub', 'top'])

    # remove maxmin and make sure it'c children are removed as well
    maxmin.remove()
    time.sleep(1)
    eq(sorted(workspace_page.get_dataflow_component_names()),
       ['driver', 'top'])

    # 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_maxmin complete."
コード例 #17
0
ファイル: removeTestProjects.py プロジェクト: hitej/meta-core
def _test_projects_begone(browser):
    projects_page = begin(browser)
    projects_page.delete_projects("testing project", True)
コード例 #18
0
def _test_new_project(browser):

    browser_download_location_path = get_browser_download_location_path(
        browser)

    projects_page = begin(browser)
    eq(projects_page.welcome_text, 'Welcome to OpenMDAO %s' % __version__)

    # Create a project.
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True,
                                                 load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'])  # maxlength

    # Edit the project meta data
    project_dict['description'] = "pony express"
    project_dict['version'] = "23432"

    projects_page = edit_project(edit_dialog, project_dict['name'],
                                 project_dict['description'],
                                 project_dict['version'])

    # Make sure all the new project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(),
       project_dict['version'][:5])  # maxlength
    edit_dialog.cancel()

    # Export the project
    projects_page.export_project(project_dict['name'])
    project_pattern = project_dict['name'].replace(' ', '_') + '-*.proj'
    project_pattern = os.path.join(browser_download_location_path,
                                   project_pattern)
    for i in range(10):  # Give the download time to complete.
        time.sleep(1)
        project_path = glob.glob(project_pattern)
        if project_path:
            break
    else:
        assert False, 'Download of %r timed-out' % project_pattern
    assert len(project_path) == 1
    project_path = project_path[0]

    # Delete the project in preparation for reimporting
    projects_page.delete_project(project_dict['name'])

    # Make sure the project was deleted
    assert not projects_page.contains(project_dict['name'], False)

    # Import the project and give it a new name
    projects_page, project_dict = import_project(
        projects_page.import_project(),
        project_path,
        verify=True,
        load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Delete the project that was just imported
    projects_page.delete_project(project_dict['name'])

    # remove the downloaded file
    os.remove(project_path)
コード例 #19
0
def _test_new_project(browser):

    browser_download_location_path = get_browser_download_location_path(browser)

    projects_page = begin(browser)
    eq(projects_page.welcome_text, 'Welcome to OpenMDAO %s' % __version__)

    # Create a project.
    projects_page, project_dict = random_project(projects_page.new_project(),
                                                 verify=True, load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Make sure all the project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'])  # maxlength

    # Edit the project meta data
    project_dict['description'] = "pony express"
    project_dict['version'] = "23432"

    projects_page = edit_project(edit_dialog,
                         project_dict['name'],
                         project_dict['description'],
                         project_dict['version'])

    # Make sure all the new project meta data was saved correctly.
    edit_dialog = projects_page.edit_project(project_dict['name'])
    eq(str(edit_dialog.project_name).strip(), project_dict['name'])
    eq(str(edit_dialog.description).strip(), project_dict['description'])
    eq(str(edit_dialog.version).strip(), project_dict['version'][:5])  # maxlength
    edit_dialog.cancel()

    # Export the project
    projects_page.export_project(project_dict['name'])
    project_pattern = project_dict['name'].replace(' ', '_') + '-*.proj'
    project_pattern = os.path.join(browser_download_location_path,
                                   project_pattern)
    for i in range(10):  # Give the download time to complete.
        time.sleep(1)
        project_path = glob.glob(project_pattern)
        if project_path:
            break
    else:
        assert False, 'Download of %r timed-out' % project_pattern
    assert len(project_path) == 1
    project_path = project_path[0]

    # Delete the project in preparation for reimporting
    projects_page.delete_project(project_dict['name'])

    # Make sure the project was deleted
    assert not projects_page.contains(project_dict['name'], False)

    # Import the project and give it a new name
    projects_page, project_dict = import_project(projects_page.import_project(),
                                                 project_path, verify=True,
                                                 load_workspace=False)
    # Go back to projects page to see if it is on the list.
    assert projects_page.contains(project_dict['name'])

    # Delete the project that was just imported
    projects_page.delete_project(project_dict['name'])

    # remove the downloaded file
    os.remove(project_path)
コード例 #20
0
ファイル: day15-scratch.py プロジェクト: njvrzm/aoc2018
        if not actor.alive:
            # Killed this round
            continue
        if all(being.kind is actor.kind for being in quick()):
            # This check must be _before_ fight, not after, because
            # the round end condition is that an actor discovers they
            # have no-one left to fight. If the last actor kills the last
            # foe, and this check happens after, the round will incorrectly
            # be counted as incomplete.
            return False
        actor.move()
        actor.fight()
    return True


if __name__ == '__main__':
    for power in count(3):
        begin(fn=sys.argv[1])
        Habitor.Elf.power = power
        rounds = 0
        while True:
            if not turn():
                break
            rounds += 1
        points = sum(being.points for being in locus if being.alive)
        score = rounds * points
        slain = sum(1 for being in grave if being.kind is Habitor.Elf)
        print(power, rounds, points, score, slain, sep='\t')
        if not slain:
            break
コード例 #21
0
def _test_projects_begone(browser):
    projects_page = begin(browser)
    projects_page.delete_projects('testing project', True)