pida-hacks / tests /

Full commit
import py
import gtk
import pytest

class UidefFile(pytest.File):
    def collect(self):
        item = PathFuncTestItem('uidef', ui_action_names_no_hyphens, self)
        item.keywords['xfail'] = py.test.mark.xfail(reason='not yet fixed')
        return [item]

class GladeFile(pytest.File):
    def collect(self):
        return [
            PathFuncTestItem('glade', loadable, self),
            PathFuncTestItem('glade', objectlists_are_scrollable, self),

class PathFuncTestItem(pytest.Item):
    def __init__(self, keyword, func, parent):
        super(PathFuncTestItem, self).__init__(func.__name__, parent)
        self.func = func
        self.keywords[keyword] = True

    def reportinfo(self):
        path = self.parent.fspath
        base = py.path.local(__file__).dirpath().dirpath()
        return path, None, path.relto(base)

    def _prunetraceback(self, excinfo):
        excinfo.traceback = excinfo.traceback.cut(

    def runtest(self):
        __tracebackhide__ = True

def loadable(path):
    from pygtkhelpers.ui import objectlist
    builder = gtk.Builder()

def objectlists_are_scrollable(path):
    from lxml.etree import parse, XPath
    with as f:
        doc = parse(f)

    regexpNS = ""
    find = XPath('.//object[re:test(@class, "PyGTKHelpersObject")]',
                 namespaces={'re': regexpNS})
    objectlists = find(doc)
    failed = False
    for ol in objectlists:
        container = ol.getparent().getparent()
        failed = failed or not container.attrib['class'] == 'GtkScrolledWindow'
        print ol.attrib['id'], 'in', container.attrib['id'],\
                               'of', container.attrib['class']
    assert not failed

def ui_action_names_no_hyphens(path):
    from lxml.etree import parse, XPath
    with as f:
        doc = parse(f)

    items = doc.findall('.//toolitem') + doc.findall('.//menuitem')
    for toolitem in items:
        action = toolitem.attrib['action']
        #XXX: find the action in the actionsconfig
        assert action.islower()
        assert '-' not in action

        name = toolitem.attrib['name']
        assert name == action
        print action