Commit ed1f9ecc authored by Thibault Saunier's avatar Thibault Saunier 🌵

tests: Fix tests in python2

Python2 core checks that the first argument of a method is of the type
of the object if it does not have any info about the method, so when
using Gst not initialized it raiser a TypeError and not a
Gst.NotInitialized as expected.

+ And fix a typo
parent b80ea319
......@@ -338,12 +338,12 @@ Gst.fixme = _gi_gst.fixme
Gst.memdump = _gi_gst.memdump
# Make sure PyGst is not usable if GStreamer has not been initialized
class NotInitalized(Exception):
class NotInitialized(Exception):
pass
__all__.append('NotInitalized')
__all__.append('NotInitialized')
def fake_method(*args):
raise NotInitalized("Please call Gst.init(argv) before using GStreamer")
raise NotInitialized("Please call Gst.init(argv) before using GStreamer")
real_functions = [o for o in inspect.getmembers(Gst) if isinstance(o[1], type(Gst.init))]
......
import os
import gi.overrides
if not gi.overrides.__path__[0].endswith("gst-python/gi/overrides"):
......@@ -7,5 +8,9 @@ if not gi.overrides.__path__[0].endswith("gst-python/gi/overrides"):
if path.endswith("gst-python/gi/overrides"):
local_overrides = path
gi.overrides.__path__.remove(local_overrides)
if local_overrides:
gi.overrides.__path__.remove(local_overrides)
else:
local_overrides = os.path.abspath(os.path.join(__file__, "../", "../", "gi", "overrides"))
gi.overrides.__path__.insert(0, local_overrides)
......@@ -17,6 +17,7 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import sys
import overrides_hack
overrides_hack
from common import TestCase, unittest
......@@ -38,13 +39,18 @@ class TimeArgsTest(TestCase):
class TestNotInitialized(TestCase):
def testNotInitialized(self):
with self.assertRaises(Gst.NotInitalized):
if sys.version_info >= (3, 0):
assert_type = Gst.NotInitialized
else:
assert_type = TypeError
with self.assertRaises(assert_type):
Gst.Caps.from_string("audio/x-raw")
with self.assertRaises(Gst.NotInitalized):
with self.assertRaises(assert_type):
Gst.Structure.from_string("audio/x-raw")
with self.assertRaises(Gst.NotInitalized):
with self.assertRaises(assert_type):
Gst.ElementFactory.make("identity", None)
def testNotDeinitialized(self):
......@@ -55,13 +61,18 @@ class TestNotInitialized(TestCase):
assert(Gst.ElementFactory.make("identity", None))
Gst.deinit()
with self.assertRaises(Gst.NotInitalized):
if sys.version_info >= (3, 0):
assert_type = Gst.NotInitialized
else:
assert_type = TypeError
with self.assertRaises(assert_type):
Gst.Caps.from_string("audio/x-raw")
with self.assertRaises(Gst.NotInitalized):
with self.assertRaises(assert_type):
Gst.Structure.from_string("audio/x-raw")
with self.assertRaises(Gst.NotInitalized):
with self.assertRaises(assert_type):
Gst.ElementFactory.make("identity", None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment