#!/usr/bin/env python

"""An example of a doctest utilising guitest."""

import unittest
import doctest
import gtk.gdk
from guitest.gtktest import GtkTestCase, guistate, setUp, tearDown
from guitest.utils import mainloop_handler

import gtk_sample # app being tested


def doctest_complex():
    """A simple doctest for gtk_sample.

    First, create the application:

        >>> app = gtk_sample.ExampleApp()

    We can peek around a little bit:

        >>> app.win.get_border_width() 
        12L
        >>> app.box.get_spacing()
        12

    The hierarchy of widgets is OK:

        >>> app.label.get_parent() is app.box
        True
        >>> app.button.get_parent() is app.box
        True

    The label at first shows '#':

        >>> app.label.get_label()
        '#'

    Now we simulate 10 clicks and check the label each time:

        >>> for x in range(1, 10):
        ...     app.button.clicked()
        ...     assert app.num == x
        ...     assert app.label.get_label() == str(x)

    """

def doctest_quit():
    """A doctest that checks if gtk_sample exits properly.

    Create the application:

        >>> app = gtk_sample.ExampleApp()

    The application is active:

        >>> guistate.level
        0

    Now, emit a delete event for the main window:

        >>> app.win.emit('delete-event', gtk.gdk.Event(gtk.gdk.DELETE))
        False

    gtk.main_quit() has been invoked:

        >>> guistate.level
        -1

    """


def test_suite():
    # Note: import and use setUp_param instead of setUp if you need to specify
    # custom overrides or logging hooks.  See DoctestHelper.setUp_param().
    return doctest.DocTestSuite(setUp=setUp, tearDown=tearDown)


if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')

