Esempio n. 1
0
def test_it_doesnt_crash(monkeypatch, porcusession):
    # the dialog calls .wait_window(), but that doesn't terminate until the
    # user closes the window... so we'll make the window close itself
    called = [0]  # not sure if nonlocal could be used instead

    class FakeToplevel(tkinter.Toplevel):
        def wait_window(self):
            called[0] += 1
            self.destroy()

    fake_tkinter = types.SimpleNamespace()
    fake_tkinter.__dict__.update(tkinter.__dict__)
    fake_tkinter.Toplevel = FakeToplevel

    monkeypatch.setattr(aboutdialog, 'tkinter', fake_tkinter)

    assert actions.get_action('Help/About Porcupine...').enabled
    actions.get_action('Help/About Porcupine...').callback()
    assert called == [1]
Esempio n. 2
0
def test_add_command_and_stuff(porcusession, action_path):
    root = get_main_window()
    callback_ran = False

    def callback():
        nonlocal callback_ran
        callback_ran = True

    with action_events() as (new_events, enable_events, disable_events):
        action = actions.add_command(action_path, callback, '<<Test>>')
        assert new_events.pop().data == action_path
        assert actions.get_action(action_path) is action
        assert action in actions.get_all_actions()

        assert action.path == action_path
        assert action.kind == 'command'
        assert action.binding == '<<Test>>'
        assert action.enabled
        assert action.callback is callback
        assert not hasattr(action, 'var')
        assert not hasattr(action, 'choices')
        assert (repr(action) == str(action) == "<Action object '" +
                action_path + "': kind='command', enabled=True>")

        action.enabled = False
        assert disable_events.pop().data == action_path
        assert 'enabled=False' in repr(action)
        action.enabled = False
        assert not disable_events

        action.enabled = True
        assert enable_events.pop().data == action_path
        assert 'enabled=True' in repr(action)
        action.enabled = True
        assert not enable_events

        with pytest.raises(TypeError):
            action.enabled = 1

    action.enabled = False

    assert not callback_ran
    root.event_generate('<<Test>>')
    assert not callback_ran
    action.enabled = True
    root.event_generate('<<Test>>')
    assert callback_ran

    root.unbind('<<Test>>')
Esempio n. 3
0
def test_start_pasting_with_actions(monkeypatch, filetab):
    called = []

    class FakePaste:
        def __init__(self, pastebin_name, code, path):
            self.started = 0
            assert code == ''
            assert path is None     # because the filetab hasn't been saved
            self._pastebin_name = pastebin_name

        def start(self):
            called.append(self._pastebin_name)

    monkeypatch.setattr(pastebin_module, 'Paste', FakePaste)

    pastebin_names = list(pastebin_module.pastebins.keys())
    random.shuffle(pastebin_names)

    for name in pastebin_names:
        action = actions.get_action('Share/%s' % name)
        assert action.enabled
        action.callback()
    assert called == pastebin_names
Esempio n. 4
0
 def on_enable_disable(self, action_path):
     action = actions.get_action(action_path)
     menu, index = self._items[action_path]
     menu.entryconfig(index,
                      state=('normal' if action.enabled else 'disabled'))
Esempio n. 5
0
 def on_new_action(self, event):
     self.setup_action(actions.get_action(event.data))