[gst-devel] Test inspiration

Antoine Pitrou antoine.pitrou at wengo.fr
Mon Oct 23 15:52:03 CEST 2006


Le lundi 23 octobre 2006 à 15:19 +0200, Fredrik Persson a écrit :
> I'm looking for inspiration; I'm writing a gtk/gst app in python, and
> I'd like to write unit tests (with pythons unittest) for my app. So I'm
> looking for examples on how to do this; any suggestions?

For the gst part you can write it as a set of sinks, sources and
bins/pipelines. Then you can test each component independently by using
test sources, fake sinks, or example media files.

I find it nice to launch the gobject event loop in a separate thread,
then I can execute some code in that thread using gobject.idle_add() (I
actually use a decorator which takes care of that, as well as not
returning a True value so that the code is not executed repeatedly)...
Thus the bulk of my test suite is still written in a synchronous style.

To communicate results from the event loop I use a Queue. I put the
value in the queue at the desired place in the asynchronous event flow
(probably in a signal callback); in the main thread I do a queue.get()
with a timeout.

To give an example this is the code for a very simplistic test.
"to_av_loop" is the aforementioned decorator.

def test10():
    # AV loop
    q = Queue()
    @to_av_loop
    def f():
        q.put(1)
    f()
    assert q.get(True, 1.0) == 1


Here is a less empty test. It checks if a decoder is able to decode a
given file. You don't need to know the details of the helper functions
("_filesrc()", etc.) which are quite straightforward.

def test1():
    # Ogg Vorbis file
    q = Queue()
    src = _filesrc(_ogg_file())
    decoder = _decoder()
    sink = _fakesink()
    pipeline = _linear_pipeline(src, decoder, sink)
    def _src_pad_ready(*_):
        q.put(1)
    decoder.connect("src-pad-ready", _src_pad_ready)
    pipeline.set_state(gst.STATE_PLAYING)
    try:
        assert q.get(True, 1.0) == 1
    finally:
        pipeline.set_state(gst.STATE_NULL)



(note: I use nosetest -
http://somethingaboutorange.com/mrl/projects/nose/ - rather than
Python's unittest but the advice should still apply)

Regards

Antoine.






More information about the gstreamer-devel mailing list