testsuite/: Fix unit tests for pygobject >= 2.13.0

Original commit message from CVS:
* testsuite/common.py:
* testsuite/test_bin.py:
* testsuite/test_element.py:
* testsuite/test_ghostpad.py:
* testsuite/test_pad.py:
* testsuite/test_pipeline.py:
Fix unit tests for pygobject >= 2.13.0
See the pygobject bug #320428 for more information about the changes.
This commit is contained in:
Edward Hervey 2007-10-09 14:27:18 +00:00
parent 36d561c1f0
commit f6294fea73
7 changed files with 71 additions and 45 deletions

View file

@ -1,3 +1,14 @@
2007-10-09 Edward Hervey <bilboed@bilboed.com>
* testsuite/common.py:
* testsuite/test_bin.py:
* testsuite/test_element.py:
* testsuite/test_ghostpad.py:
* testsuite/test_pad.py:
* testsuite/test_pipeline.py:
Fix unit tests for pygobject >= 2.13.0
See the pygobject bug #320428 for more information about the changes.
2007-10-08 Sebastien Moutte <sebastien@moutte.net> 2007-10-08 Sebastien Moutte <sebastien@moutte.net>
* gst/pygstminiobject.c: (pygstminiobject_dealloc): * gst/pygstminiobject.c: (pygstminiobject_dealloc):

View file

@ -42,6 +42,14 @@ try:
except: except:
print "WARNING: gobject doesn't have threads_init, no threadsafety" print "WARNING: gobject doesn't have threads_init, no threadsafety"
# Detect the version of pygobject
# In pygobject >= 2.13.0 the refcounting of objects has changed.
pgmaj,pgmin,pgmac = gobject.pygobject_version
if pgmaj >= 2 and pgmin >= 13:
pygobject_2_13 = True
else:
pygobject_2_13 = False
# Don't insert before . # Don't insert before .
# sys.path.insert(1, os.path.join('..')) # sys.path.insert(1, os.path.join('..'))

View file

@ -21,7 +21,7 @@
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from common import gobject, gst, unittest, TestCase from common import gobject, gst, unittest, TestCase, pygobject_2_13
import sys import sys
import time import time
@ -62,7 +62,7 @@ class BinSubclassTest(TestCase):
def testStateChange(self): def testStateChange(self):
bin = MyBin("mybin") bin = MyBin("mybin")
self.assertEquals(bin.__gstrefcount__, 1) self.assertEquals(bin.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(bin), 3) self.assertEquals(sys.getrefcount(bin), pygobject_2_13 and 2 or 3)
self.assertEquals(bin.get_name(), "mybin") self.assertEquals(bin.get_name(), "mybin")
self.assertEquals(bin.__gstrefcount__, 1) self.assertEquals(bin.__gstrefcount__, 1)

View file

@ -20,7 +20,7 @@
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from common import gst, unittest, TestCase from common import gst, unittest, TestCase, pygobject_2_13
import sys import sys
@ -181,7 +181,7 @@ class QueryTest(TestCase):
self.element = self.pipeline.get_by_name('source') self.element = self.pipeline.get_by_name('source')
self.assertEquals(self.pipeline.__gstrefcount__, 1) self.assertEquals(self.pipeline.__gstrefcount__, 1)
self.assertEquals(self.element.__gstrefcount__, 2) self.assertEquals(self.element.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.element), 3) self.assertEquals(sys.getrefcount(self.element), pygobject_2_13 and 2 or 3)
def tearDown(self): def tearDown(self):
del self.pipeline del self.pipeline
@ -192,9 +192,9 @@ class QueryTest(TestCase):
gst.debug('querying fakesrc in FORMAT_BYTES') gst.debug('querying fakesrc in FORMAT_BYTES')
res = self.element.query_position(gst.FORMAT_BYTES) res = self.element.query_position(gst.FORMAT_BYTES)
self.assertEquals(self.pipeline.__gstrefcount__, 1) self.assertEquals(self.pipeline.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.assertEquals(self.element.__gstrefcount__, 2) self.assertEquals(self.element.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.element), 3) self.assertEquals(sys.getrefcount(self.element), pygobject_2_13 and 2 or 3)
assert res assert res
assert res[0] == 0 assert res[0] == 0
self.assertRaises(gst.QueryError, self.element.query_position, self.assertRaises(gst.QueryError, self.element.query_position,

View file

@ -20,7 +20,7 @@
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from common import gst, unittest, TestCase from common import gst, unittest, TestCase, pygobject_2_13
import sys import sys
import gc import gc
@ -57,24 +57,24 @@ class PipeTest(TestCase):
TestCase.setUp(self) TestCase.setUp(self)
self.pipeline = gst.Pipeline() self.pipeline = gst.Pipeline()
self.assertEquals(self.pipeline.__gstrefcount__, 1) self.assertEquals(self.pipeline.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.src = SrcBin() self.src = SrcBin()
self.src.prepare() self.src.prepare()
self.sink = SinkBin() self.sink = SinkBin()
self.sink.prepare() self.sink.prepare()
self.assertEquals(self.src.__gstrefcount__, 1) self.assertEquals(self.src.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 1) self.assertEquals(self.sink.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
gst.info("end of SetUp") gst.info("end of SetUp")
def tearDown(self): def tearDown(self):
gst.info("tearDown") gst.info("tearDown")
self.assertTrue (self.pipeline.__gstrefcount__ >= 1 and self.pipeline.__gstrefcount__ <= 2) self.assertTrue (self.pipeline.__gstrefcount__ >= 1 and self.pipeline.__gstrefcount__ <= 2)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.assertEquals(self.src.__gstrefcount__, 2) self.assertEquals(self.src.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 2) self.assertEquals(self.sink.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), 3)
gst.debug('deleting pipeline') gst.debug('deleting pipeline')
@ -83,8 +83,8 @@ class PipeTest(TestCase):
self.assertEquals(self.src.__gstrefcount__, 1) # parent gone self.assertEquals(self.src.__gstrefcount__, 1) # parent gone
self.assertEquals(self.sink.__gstrefcount__, 1) # parent gone self.assertEquals(self.sink.__gstrefcount__, 1) # parent gone
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
gst.debug('deleting src') gst.debug('deleting src')
del self.src del self.src
self.gccollect() self.gccollect()

View file

@ -20,7 +20,7 @@
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from common import gst, unittest, TestCase from common import gst, unittest, TestCase, pygobject_2_13
import sys import sys
import time import time
@ -30,7 +30,7 @@ class PadTemplateTest(TestCase):
template = gst.PadTemplate("template", gst.PAD_SINK, template = gst.PadTemplate("template", gst.PAD_SINK,
gst.PAD_ALWAYS, gst.caps_from_string("audio/x-raw-int")) gst.PAD_ALWAYS, gst.caps_from_string("audio/x-raw-int"))
self.failUnless(template) self.failUnless(template)
self.assertEquals(sys.getrefcount(template), 3) self.assertEquals(sys.getrefcount(template), pygobject_2_13 and 2 or 3)
#self.assertEquals(template.__gstrefcount__, 1) #self.assertEquals(template.__gstrefcount__, 1)
class PadPushUnlinkedTest(TestCase): class PadPushUnlinkedTest(TestCase):
@ -40,10 +40,10 @@ class PadPushUnlinkedTest(TestCase):
self.sink = gst.Pad("sink", gst.PAD_SINK) self.sink = gst.Pad("sink", gst.PAD_SINK)
def tearDown(self): def tearDown(self):
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.src.__gstrefcount__, 1) self.assertEquals(self.src.__gstrefcount__, 1)
del self.src del self.src
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 1) self.assertEquals(self.sink.__gstrefcount__, 1)
del self.sink del self.sink
TestCase.tearDown(self) TestCase.tearDown(self)
@ -90,11 +90,11 @@ class PadPushLinkedTest(TestCase):
self.buffers = [] self.buffers = []
def tearDown(self): def tearDown(self):
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.src.__gstrefcount__, 1) self.assertEquals(self.src.__gstrefcount__, 1)
self.src.set_caps(None) self.src.set_caps(None)
del self.src del self.src
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 1) self.assertEquals(self.sink.__gstrefcount__, 1)
self.sink.set_caps(None) self.sink.set_caps(None)
del self.sink del self.sink
@ -171,11 +171,11 @@ class PadPushEventLinkedTest(TestCase):
self.events = [] self.events = []
def tearDown(self): def tearDown(self):
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.src.__gstrefcount__, 1) self.assertEquals(self.src.__gstrefcount__, 1)
self.src.set_caps(None) self.src.set_caps(None)
del self.src del self.src
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 1) self.assertEquals(self.sink.__gstrefcount__, 1)
self.sink.set_caps(None) self.sink.set_caps(None)
del self.sink del self.sink
@ -269,11 +269,11 @@ class PadPushProbeLinkTest(TestCase):
self.buffers = [] self.buffers = []
def tearDown(self): def tearDown(self):
self.assertEquals(sys.getrefcount(self.src), 3) self.assertEquals(sys.getrefcount(self.src), pygobject_2_13 and 2 or 3)
self.assertEquals(self.src.__gstrefcount__, 1) self.assertEquals(self.src.__gstrefcount__, 1)
self.src.set_caps(None) self.src.set_caps(None)
del self.src del self.src
self.assertEquals(sys.getrefcount(self.sink), 3) self.assertEquals(sys.getrefcount(self.sink), pygobject_2_13 and 2 or 3)
self.assertEquals(self.sink.__gstrefcount__, 1) self.assertEquals(self.sink.__gstrefcount__, 1)
self.sink.set_caps(None) self.sink.set_caps(None)
del self.sink del self.sink
@ -310,7 +310,7 @@ class PadTest(TestCase):
gst.debug('creating pad with name src') gst.debug('creating pad with name src')
pad = gst.Pad("src", gst.PAD_SRC) pad = gst.Pad("src", gst.PAD_SRC)
self.failUnless(pad) self.failUnless(pad)
self.assertEquals(sys.getrefcount(pad), 3) self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
self.assertEquals(pad.__gstrefcount__, 1) self.assertEquals(pad.__gstrefcount__, 1)
gst.debug('creating pad with no name') gst.debug('creating pad with no name')
@ -347,44 +347,44 @@ class PadProbePipeTest(TestCase):
TestCase.setUp(self) TestCase.setUp(self)
self.pipeline = gst.Pipeline() self.pipeline = gst.Pipeline()
self.assertEquals(self.pipeline.__gstrefcount__, 1) self.assertEquals(self.pipeline.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.fakesrc = gst.element_factory_make('fakesrc') self.fakesrc = gst.element_factory_make('fakesrc')
self.fakesink = gst.element_factory_make('fakesink') self.fakesink = gst.element_factory_make('fakesink')
self.assertEquals(self.fakesrc.__gstrefcount__, 1) self.assertEquals(self.fakesrc.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.fakesrc), 3) self.assertEquals(sys.getrefcount(self.fakesrc), pygobject_2_13 and 2 or 3)
self.pipeline.add(self.fakesrc, self.fakesink) self.pipeline.add(self.fakesrc, self.fakesink)
self.assertEquals(self.fakesrc.__gstrefcount__, 2) # added self.assertEquals(self.fakesrc.__gstrefcount__, 2) # added
self.assertEquals(sys.getrefcount(self.fakesrc), 3) self.assertEquals(sys.getrefcount(self.fakesrc), pygobject_2_13 and 2 or 3)
self.assertEquals(self.fakesink.__gstrefcount__, 2) # added self.assertEquals(self.fakesink.__gstrefcount__, 2) # added
self.assertEquals(sys.getrefcount(self.fakesink), 3) self.assertEquals(sys.getrefcount(self.fakesink), pygobject_2_13 and 2 or 3)
self.fakesrc.link(self.fakesink) self.fakesrc.link(self.fakesink)
self.assertEquals(self.pipeline.__gstrefcount__, 1) self.assertEquals(self.pipeline.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.assertEquals(self.fakesrc.__gstrefcount__, 2) self.assertEquals(self.fakesrc.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.fakesrc), 3) self.assertEquals(sys.getrefcount(self.fakesrc), pygobject_2_13 and 2 or 3)
self.assertEquals(self.fakesink.__gstrefcount__, 2) self.assertEquals(self.fakesink.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.fakesink), 3) self.assertEquals(sys.getrefcount(self.fakesink), pygobject_2_13 and 2 or 3)
def tearDown(self): def tearDown(self):
# Refcount must be either 1 or 2, to allow for a possibly still running # Refcount must be either 1 or 2, to allow for a possibly still running
# state-recalculation thread # state-recalculation thread
self.assertTrue (self.pipeline.__gstrefcount__ >= 1 and self.pipeline.__gstrefcount__ <= 2) self.assertTrue (self.pipeline.__gstrefcount__ >= 1 and self.pipeline.__gstrefcount__ <= 2)
self.assertEquals(sys.getrefcount(self.pipeline), 3) self.assertEquals(sys.getrefcount(self.pipeline), pygobject_2_13 and 2 or 3)
self.assertEquals(self.fakesrc.__gstrefcount__, 2) self.assertEquals(self.fakesrc.__gstrefcount__, 2)
self.assertEquals(sys.getrefcount(self.fakesrc), 3) self.assertEquals(sys.getrefcount(self.fakesrc), pygobject_2_13 and 2 or 3)
gst.debug('deleting pipeline') gst.debug('deleting pipeline')
del self.pipeline del self.pipeline
self.gccollect() self.gccollect()
self.assertEquals(self.fakesrc.__gstrefcount__, 1) # parent gone self.assertEquals(self.fakesrc.__gstrefcount__, 1) # parent gone
self.assertEquals(self.fakesink.__gstrefcount__, 1) # parent gone self.assertEquals(self.fakesink.__gstrefcount__, 1) # parent gone
self.assertEquals(sys.getrefcount(self.fakesrc), 3) self.assertEquals(sys.getrefcount(self.fakesrc), pygobject_2_13 and 2 or 3)
self.assertEquals(sys.getrefcount(self.fakesink), 3) self.assertEquals(sys.getrefcount(self.fakesink), pygobject_2_13 and 2 or 3)
gst.debug('deleting fakesrc') gst.debug('deleting fakesrc')
del self.fakesrc del self.fakesrc
self.gccollect() self.gccollect()
@ -479,32 +479,38 @@ class PadRefCountTest(TestCase):
def testAddPad(self): def testAddPad(self):
# add a pad to an element # add a pad to an element
e = gst.element_factory_make('fakesrc') e = gst.element_factory_make('fakesrc')
self.assertEquals(sys.getrefcount(e), 3) self.assertEquals(sys.getrefcount(e), pygobject_2_13 and 2 or 3)
self.assertEquals(e.__gstrefcount__, 1) self.assertEquals(e.__gstrefcount__, 1)
gst.debug('creating pad with name mypad') gst.debug('creating pad with name mypad')
pad = gst.Pad("mypad", gst.PAD_SRC) pad = gst.Pad("mypad", gst.PAD_SRC)
self.failUnless(pad) self.failUnless(pad)
self.assertEquals(sys.getrefcount(pad), 3) self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
self.assertEquals(pad.__gstrefcount__, 1) self.assertEquals(pad.__gstrefcount__, 1)
gst.debug('adding pad to element') gst.debug('adding pad to element')
e.add_pad(pad) e.add_pad(pad)
self.assertEquals(sys.getrefcount(e), 3) self.assertEquals(sys.getrefcount(e), pygobject_2_13 and 2 or 3)
self.assertEquals(e.__gstrefcount__, 1) self.assertEquals(e.__gstrefcount__, 1)
self.assertEquals(sys.getrefcount(pad), 3) self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
self.assertEquals(pad.__gstrefcount__, 2) # added to element self.assertEquals(pad.__gstrefcount__, 2) # added to element
gst.debug('deleting element and collecting') gst.debug('deleting element and collecting')
self.gccollect() self.gccollect()
del e del e
self.assertEquals(self.gccollect(), 1) # collected the element if not pygobject_2_13:
self.assertEquals(sys.getrefcount(pad), 3) # the element will be collected at 'del e' if we're using
# pygobject >= 2.13.0
self.assertEquals(self.gccollect(), 1) # collected the element
self.assertEquals(sys.getrefcount(pad), pygobject_2_13 and 2 or 3)
self.assertEquals(pad.__gstrefcount__, 1) # removed from element self.assertEquals(pad.__gstrefcount__, 1) # removed from element
gst.debug('deleting pad and collecting') gst.debug('deleting pad and collecting')
del pad del pad
self.assertEquals(self.gccollect(), 1) # collected the pad if not pygobject_2_13:
# the pad will be collected at 'del pad' if we're using
# pygobject >= 2.13.0
self.assertEquals(self.gccollect(), 1) # collected the pad
gst.debug('going into teardown') gst.debug('going into teardown')
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -22,7 +22,7 @@
import time import time
from common import gst, unittest, TestCase from common import gst, unittest, TestCase, pygobject_2_13
import gobject import gobject
@ -83,7 +83,8 @@ class Bus(TestCase):
self.assertEquals(bus.__gstrefcount__, 2) self.assertEquals(bus.__gstrefcount__, 2)
del pipeline del pipeline
self.failUnless(self.gccollect()) if not pygobject_2_13:
self.failUnless(self.gccollect())
self.assertEquals(bus.__gstrefcount__, 1) self.assertEquals(bus.__gstrefcount__, 1)
class PipelineAndBus(TestCase): class PipelineAndBus(TestCase):