Source

pida-hacks / tests / core / test_actions.py

import gtk
import mock
from pida.core.actions import ActionsConfig
from unittest import TestCase

from pida.utils.testing import refresh_gui


class ConfiguredActions(ActionsConfig):
    actions = [
        gtk.Action('test', 'test', 'test', gtk.STOCK_OK ),
    ]


def test_confiugred():
    svc = mock.Mock()
    svc.get_name.return_value=''
    actions = ConfiguredActions(svc)


class MyActions(ActionsConfig):

    actions = [
        gtk.Action('banana', 'do a banana', 'banana tooltip', gtk.STOCK_OPEN)
    ]

    def on_banana(self, action):
        self.svc.banana = True


def pytest_funcarg__svc(request):
    svc = mock.Mock()
    svc.banana = False
    svc.get_name.return_value = 'testcase'
    return svc

def pytest_funcarg__config(request):
    return MyActions(request.getfuncargvalue('svc'))

def pytest_funcarg__act(request):
    acts = request.getfuncargvalue('config')
    return acts.group.get_action('banana')

def test_action(svc, act):
    assert not svc.banana
    act.activate()
    refresh_gui()
    assert svc.banana

def test_label(act):
    assert act.props.label == 'do a banana'

def test_tooltip(act):
    assert act.props.tooltip == 'banana tooltip'

def test_sid(act):
    assert act.props.stock_id == gtk.STOCK_OPEN