tests: Add test_fraction back in the testsuite
authorThibault Saunier <tsaunier@gnome.org>
Fri, 24 Apr 2015 07:37:24 +0000 (09:37 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Fri, 24 Apr 2015 09:21:44 +0000 (11:21 +0200)
Properly porting it and adding a small test about getting fraction
from a Gst.Structure

testsuite/Makefile.am
testsuite/test_fraction.py [moved from testsuite/old/test_fraction.py with 79% similarity]

index ac3ebba..d37e0a3 100644 (file)
@@ -2,7 +2,8 @@
 # http://www.gnu.org/software/automake/manual/automake.html#Wildcards
 # Keep this list sorted!
 tests =        \
-       test_gst.py
+       test_gst.py \
+       test_fraction.py
 
 EXTRA_DIST = \
        __init__.py \
similarity index 79%
rename from testsuite/old/test_fraction.py
rename to testsuite/test_fraction.py
index 46b1ed8..0a779d6 100644 (file)
 # 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 gobject
-gobject.threads_init()
-from common import gst, TestCase
+import overrides_hack
+overrides_hack
 
-F = gst.Fraction
+from common import TestCase
+
+from gi.repository import Gst
+Gst.init(None)
+
+F = Gst.Fraction
 
 class TestFraction(TestCase):
     def testConstructor(self):
+        Gst.init(None)
+
         frac = F(1, 2)
         self.assertEquals(frac.num, 1)
         self.assertEquals(frac.denom, 2)
@@ -37,9 +43,13 @@ class TestFraction(TestCase):
         self.assertRaises(TypeError, F)
 
     def testRepr(self):
-        self.assertEquals(repr(F(1, 2)), '<gst.Fraction 1/2>')
+        Gst.init(None)
+
+        self.assertEquals(repr(F(1, 2)), '<Gst.Fraction 1/2>')
 
     def testEqNe(self):
+        Gst.init(None)
+
         frac = F(1, 2)
         self.assertEquals(frac, frac)
         self.assertEquals(F(1, 2), F(1, 2))
@@ -49,17 +59,23 @@ class TestFraction(TestCase):
         self.assertNotEquals(F(2, 1), F(1, 2))
 
     def testMul(self):
+        Gst.init(None)
+
         self.assertEquals(F(1, 2) * F(1, 2), F(1, 4))
         self.assertEquals(F(2, 3) * F(4, 5), F(8, 15))
         self.assertEquals(F(1, 3) * F(4), F(4, 3))
         self.assertEquals(F(1, 3) * 4, F(4, 3))
 
     def testRMul(self):
+        Gst.init(None)
+
         self.assertEquals(2 * F(1, 2), F(1))
         self.assertEquals(4 * F(1, 2), F(2))
         self.assertEquals(-10 * F(1, 2), F(-5))
 
     def testDiv(self):
+        Gst.init(None)
+
         self.assertEquals(F(1, 3) / F(1, 4), F(4, 3))
         self.assertEquals(F(2, 3) / F(4, 5), F(10, 12))
 
@@ -69,24 +85,30 @@ class TestFraction(TestCase):
         self.assertEquals(F(1, 5) / -4, F(1, -20))
 
     def testRDiv(self):
+        Gst.init(None)
+
         self.assertEquals(2 / F(1, 3), F(6, 1))
         self.assertEquals(-4 / F(1, 5), F(-20, 1))
 
     def testFloat(self):
+        Gst.init(None)
+
         self.assertEquals(float(F(1, 2)), 0.5)
 
     def testPropertyMarshalling(self):
-        try:
-            obj = gst.element_factory_make("videoparse")
-        except gst.ElementNotFoundError:
+        Gst.init(None)
+
+        obj = Gst.ElementFactory.make("videoparse")
+        if not obj:
             # no videoparse and I don't know of any elements in core or -base using
             # fraction properties. Skip this test.
             return
+
         value = obj.props.framerate
         self.failUnlessEqual(value.num, 25)
         self.failUnlessEqual(value.denom, 1)
 
-        obj.props.framerate = gst.Fraction(2, 1)
+        obj.props.framerate = Gst.Fraction(2, 1)
         value = obj.props.framerate
         self.failUnlessEqual(value.num, 2)
         self.failUnlessEqual(value.denom, 1)
@@ -98,3 +120,12 @@ class TestFraction(TestCase):
         value = obj.props.framerate
         self.failUnlessEqual(value.num, 2)
         self.failUnlessEqual(value.denom, 1)
+
+    def testGetFractionValue(self):
+        Gst.init(None)
+
+        st = Gst.Structure.from_string("video/x-raw,framerate=10/1")[0]
+        value = st["framerate"]
+
+        self.failUnlessEqual(value.num, 10)
+        self.failUnlessEqual(value.denom, 1)