当前位置: 首页>>代码示例>>Python>>正文


Python TestCase.failureException方法代码示例

本文整理汇总了Python中unittest.TestCase.failureException方法的典型用法代码示例。如果您正苦于以下问题:Python TestCase.failureException方法的具体用法?Python TestCase.failureException怎么用?Python TestCase.failureException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.TestCase的用法示例。


在下文中一共展示了TestCase.failureException方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _test_array_parameter

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:54,代码来源:test_workflow.py

示例2: _test_addfiles

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:RacerXFD,项目名称:OpenMDAO-Framework,代码行数:29,代码来源:test_workspace.py

示例3: _test_remove_folder

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:Daiyu506,项目名称:OpenMDAO-Framework,代码行数:49,代码来源:test_filetree.py

示例4: _test_newfile

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:Kenneth-T-Moore,项目名称:OpenMDAO-Framework,代码行数:61,代码来源:test_codeeditor.py

示例5: _test_file_commit

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:TwanvdBorgh,项目名称:OpenMDAO-Framework,代码行数:63,代码来源:test_workspace.py

示例6: _test_palette_update

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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)
开发者ID:TwanvdBorgh,项目名称:OpenMDAO-Framework,代码行数:86,代码来源:test_workspace.py

示例7: _test_MDAO_MDF

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]

#.........这里部分代码省略.........
        '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)
开发者ID:Kenneth-T-Moore,项目名称:OpenMDAO-Framework,代码行数:104,代码来源:test_tutorials.py

示例8: TestCase

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
"""
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 '=='
开发者ID:actionless,项目名称:wooper,代码行数:33,代码来源:assertions.py

示例9: _test_MDAO_MDF

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]

#.........这里部分代码省略.........
    # 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)
开发者ID:swryan,项目名称:OpenMDAO-Framework,代码行数:104,代码来源:test_tutorials.py

示例10: _test_Avartrees

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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
#.........这里部分代码省略.........
开发者ID:hitej,项目名称:meta-core,代码行数:103,代码来源:test_valueeditors.py

示例11: _test_MDAO_MDF

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]

#.........这里部分代码省略.........

    # 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)
开发者ID:hitej,项目名称:meta-core,代码行数:104,代码来源:test_tutorials.py

示例12: _test_remove_files

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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()
#.........这里部分代码省略.........
开发者ID:Daiyu506,项目名称:OpenMDAO-Framework,代码行数:103,代码来源:test_filetree.py

示例13: _test_value_editors

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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]]
#.........这里部分代码省略.........
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:103,代码来源:test_valueeditors.py

示例14: passed_step

# 需要导入模块: from unittest import TestCase [as 别名]
# 或者: from unittest.TestCase import failureException [as 别名]
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')
开发者ID:folt,项目名称:grail,代码行数:33,代码来源:test_direct_exception_handling.py


注:本文中的unittest.TestCase.failureException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。