def test_reject_rule_editor(windows, plugin, dialog_sleep): """Test editing a reject rule. """ r = RejectRule(suffixes=['foo', 'bar']) w = RejectRuleView(plugin=plugin, rule=r) window = ContainerTestingWindow(widget=w) window.show() process_app_events() assert w.widgets()[-1].text == 'foo, bar' sleep(dialog_sleep) w.widgets()[-1].text = 'bar' process_app_events() assert r.suffixes == ['bar'] sleep(dialog_sleep) r.suffixes = ['foo'] process_app_events() assert w.widgets()[-1].text == 'foo' sleep(dialog_sleep) w.widgets()[-1].text = 'bar, foo, barfoo' process_app_events() assert r.suffixes == ['bar', 'foo', 'barfoo'] sleep(dialog_sleep) assert w.validate()[0] r.suffixes = [] assert not w.validate()[0]
def test_measure_view(measure, windows, dialog_sleep, monkeypatch, workspace): """Test that the displayed buttons do reflect the state of the measure. """ measure.status = 'READY' view = MeasView(model=measure) w = ContainerTestingWindow(widget=view) w.show() process_app_events() sleep(dialog_sleep) assert view.widgets()[2].enabled # cd1 inserted its children before itself def test_state(dial): assert dial.measure.status == 'EDITING' with handle_dialog('reject', custom=test_state): view.widgets()[2].clicked = True assert view.widgets()[-1].enabled measure.plugin.processor.active = True process_app_events() assert not view.widgets()[-1].enabled process_app_events() measure.plugin.processor.active = False from ecpy.measure.workspace.workspace import MeasureSpace spy = CallSpy() monkeypatch.setattr(MeasureSpace, 'process_single_measure', spy) view.widgets()[-1].clicked = True assert spy.called measure.status = 'RUNNING' process_app_events() assert len(view.widgets()) == 2 measure.status = 'COMPLETED' process_app_events() assert len(view.widgets()) == 3 spy = CallSpy() monkeypatch.setattr(MeasureSpace, 'reenqueue_measure', spy) view.widgets()[-1].clicked = True assert view.widgets()[1].text == 'COMPLETED'
def test_format_rule_editor(windows, plugin, dialog_sleep): """Test editing a format rule. """ r = FormatRule(suffixes=['foo', 'bar'], new_entry_suffix='barfoo', new_entry_formatting='{bar}/{foo}') w = FormatRuleView(plugin=plugin, rule=r) # Test editing suffixes window = ContainerTestingWindow(widget=w) window.show() process_app_events() widget = w.widgets()[-6] assert widget.text == 'foo, bar' sleep(dialog_sleep) widget.text = 'bar' process_app_events() assert r.suffixes == ['bar'] sleep(dialog_sleep) r.suffixes = ['foo'] process_app_events() assert widget.text == 'foo' sleep(dialog_sleep) widget.text = 'bar, foo, barfoo' process_app_events() assert r.suffixes == ['bar', 'foo', 'barfoo'] sleep(dialog_sleep) # Set new suffix widget = w.widgets()[-4] assert widget.text == 'barfoo' widget.text = 'foobar' process_app_events() assert r.new_entry_suffix == 'foobar' sleep(dialog_sleep) # Set new formatting widget = w.widgets()[-2] assert widget.text == '{bar}/{foo}' widget.text = '{foo}/{bar}' process_app_events() assert r.new_entry_formatting == '{foo}/{bar}' sleep(dialog_sleep) # Set hide entries widget = w.widgets()[-1] assert widget.checked widget.checked = False process_app_events() assert not r.hide_entries sleep(dialog_sleep) # Test validate function r.suffixes = ['foo', 'bar'] assert w.validate()[0] r.suffixes = [] assert not w.validate()[0] r.suffixes = ['foo', 'bar'] assert w.validate() r.new_entry_suffix = '' assert not w.validate()[0] r.new_entry_suffix = 'foobar' assert w.validate()[0] r.new_entry_formatting = '{foo}' assert not w.validate()[0]
def test_edition_window(text_monitor_workbench, dialog_sleep, monkeypatch): """Test the capabalities of the widget used to edit a text monitor. """ p = text_monitor_workbench.get_plugin('ecpy.measure.monitors.text_monitor') m = p.create_monitor(False) m.rules.append(p.build_rule(dict(id='test', class_id='ecpy.FormatRule', new_entry_formatting='{index}/{number}', suffixes=['index', 'number'], new_entry_suffix='progress'))) assert m.rules[0] m.custom_entries.append(MonitoredEntry(name='dummy', path='dummy', formatting='2*{root/test}', depend_on=['root/test'])) m.handle_database_change(('added', 'root/test', 0)) m.handle_database_change(('added', 'root/simp/t_test2', 0)) m.handle_database_change(('added', 'root/comp/t_index', 0)) m.handle_database_change(('added', 'root/comp/t_number', 0)) assert len(m.displayed_entries) == 4 assert len(m.hidden_entries) == 2 w = ContainerTestingWindow(widget=TextMonitorEdit(monitor=m)) w.show() process_app_events() sleep(dialog_sleep) editor = w.widget # Test hide all editor.widgets()[6].clicked = True process_app_events() assert not m.displayed_entries sleep(dialog_sleep) # Test show one editor.widgets()[1].selected_item = m.undisplayed_entries[0] editor.widgets()[5].clicked = True process_app_events() assert m.displayed_entries sleep(dialog_sleep) # Test hide one editor.widgets()[3].selected_item = m.displayed_entries[0] editor.widgets()[7].clicked = True process_app_events() assert not m.displayed_entries sleep(dialog_sleep) # Test show all editor.widgets()[4].clicked = True process_app_events() assert not m.undisplayed_entries sleep(dialog_sleep) # Test show hidden editor.widgets()[8].checked = True process_app_events() assert m.hidden_entries for e in m.hidden_entries: assert e in m.undisplayed_entries # Test edit rules def handle_rule_edition(dialog): dialog.monitor.rules.append(RejectRule(id='__dummy', suffixes=['test2'])) dialog.monitor.refresh_monitored_entries() with handle_dialog(custom=handle_rule_edition): editor.widgets()[9].clicked = True assert 't_test2' not in [e.name for e in m.displayed_entries] # Test add entry def handle_entry_creation(dialog): dialog.entry = MonitoredEntry(name='new_entry') with handle_dialog(custom=handle_entry_creation): editor.widgets()[10].clicked = True assert 'new_entry' in [e.name for e in m.displayed_entries] # Test edit entry e = [e for e in m.displayed_entries if e.name == 'new_entry'][0] editor.selected = e with handle_dialog('reject'): editor.widgets()[11].clicked = True # Test delete entry with enaml.imports(): from ecpy.measure.monitors.text_monitor import monitor_views def false_question(*args, **kwargs): class O(object): action = 'reject' return O monkeypatch.setattr(monitor_views, 'question', false_question) editor.widgets()[12].clicked = True process_app_events() assert e in m.displayed_entries sleep(dialog_sleep) m.add_entries('undisplayed', [e]) with enaml.imports(): from ecpy.measure.monitors.text_monitor import monitor_views def false_question(*args, **kwargs): class O(object): action = 'accept' return O monkeypatch.setattr(monitor_views, 'question', false_question) editor.widgets()[12].clicked = True assert e not in m.displayed_entries sleep(dialog_sleep)