예제 #1
0
def test_rule_creation_dialog(text_monitor_workbench, dialog_sleep,
                              should_save, monkeypatch):
    """Test the creation of a new rule using the dialog.

    """
    p = text_monitor_workbench.get_plugin(PLUGIN_ID)

    d = CreateRuleDialog(plugin=p)
    d.show()
    process_app_events()
    sleep(dialog_sleep)

    d.central_widget().widgets()[0].selected_tab = \
        'ecpy.measure.monitors.text_monitor.create_rule'
    page = d.central_widget().widgets()[0].pages()[1]
    page_content = page.page_widget().widgets

    # Select rule type
    page_content()[0].selected = 'ecpy.RejectRule'
    process_app_events()
    assert d.rule is page.rule
    assert isinstance(page.rule, RejectRule)
    sleep(dialog_sleep)

    # Parametrize rule
    page_content()[1].rule.id = '__dummy'
    page_content()[1].rule.suffixes = ['foo']
    process_app_events()
    sleep(dialog_sleep)

    # Choose whether or not to save: use a parametrization of the test function
    page_content()[-1].checked = should_save
    process_app_events()
    assert isinstance(page.rule, RejectRule)
    sleep(dialog_sleep)

    # Check the created rule
    ok_btn = d.central_widget().widgets()[-2]
    assert ok_btn.enabled
    d.rule.suffixes = []
    with enaml.imports():
        from ecpy.measure.monitors.text_monitor.rules import edition_views

    called = []

    def false_warning(*args, **kwargs):
        called.append(True)

    monkeypatch.setattr(edition_views, 'warning', false_warning)
    ok_btn.clicked = True
    process_app_events()
    assert called

    d.rule.suffixes = ['foo']
    ok_btn.clicked = True
    process_app_events()
    if should_save:
        assert '__dummy' in p.rules
예제 #2
0
def test_rule_selection_for_loading(text_monitor_workbench, dialog_sleep):
    """Test using the dialog to select an existing config to load a task.

    """
    p = text_monitor_workbench.get_plugin(PLUGIN_ID)

    d = CreateRuleDialog(plugin=p)
    d.show()
    process_app_events()
    sleep(dialog_sleep)

    page = d.central_widget().widgets()[0].pages()[0]
    page_content = page.page_widget().widgets()

    # Select rule config
    qlist = page_content[0]
    qlist.selected_item = qlist.items[-1]
    process_app_events()
    assert page.rule == d.rule
    sleep(dialog_sleep)
예제 #3
0
def test_rule_selection_for_loading(text_monitor_workbench, dialog_sleep):
    """Test using the dialog to select an existing config to load a task.

    """
    p = text_monitor_workbench.get_plugin(PLUGIN_ID)

    d = CreateRuleDialog(plugin=p)
    d.show()
    process_app_events()
    sleep(dialog_sleep)

    page = d.central_widget().widgets()[0].pages()[0]
    page_content = page.page_widget().widgets()

    # Select rule config
    qlist = page_content[0]
    qlist.selected_item = qlist.items[-1]
    process_app_events()
    assert page.rule == d.rule
    sleep(dialog_sleep)
예제 #4
0
def test_rule_creation_dialog(text_monitor_workbench, dialog_sleep,
                              should_save, monkeypatch):
    """Test the creation of a new rule using the dialog.

    """
    p = text_monitor_workbench.get_plugin(PLUGIN_ID)

    d = CreateRuleDialog(plugin=p)
    d.show()
    process_app_events()
    sleep(dialog_sleep)

    d.central_widget().widgets()[0].selected_tab = \
        'ecpy.measure.monitors.text_monitor.create_rule'
    page = d.central_widget().widgets()[0].pages()[1]
    page_content = page.page_widget().widgets

    # Select rule type
    page_content()[0].selected = 'ecpy.RejectRule'
    process_app_events()
    assert d.rule is page.rule
    assert isinstance(page.rule, RejectRule)
    sleep(dialog_sleep)

    # Parametrize rule
    page_content()[1].rule.id = '__dummy'
    page_content()[1].rule.suffixes = ['foo']
    process_app_events()
    sleep(dialog_sleep)

    # Choose whether or not to save: use a parametrization of the test function
    page_content()[-1].checked = should_save
    process_app_events()
    assert isinstance(page.rule, RejectRule)
    sleep(dialog_sleep)

    # Check the created rule
    ok_btn = d.central_widget().widgets()[-2]
    assert ok_btn.enabled
    d.rule.suffixes = []
    with enaml.imports():
        from ecpy.measure.monitors.text_monitor.rules import edition_views

    called = []

    def false_warning(*args, **kwargs):
        called.append(True)

    monkeypatch.setattr(edition_views, 'warning', false_warning)
    ok_btn.clicked = True
    process_app_events()
    assert called

    d.rule.suffixes = ['foo']
    ok_btn.clicked = True
    process_app_events()
    if should_save:
        assert '__dummy' in p.rules