Commit 9845c91a authored by Thibault Saunier's avatar Thibault Saunier

tests: Move all Fundamental types tests in a file

No reason to have one file per type and it makes it more complicated
to handle.
parent dd943155
......@@ -3,13 +3,7 @@
# Keep this list sorted!
tests = \
test_gst.py \
test_fraction.py \
test_intrange.py \
test_int64range.py \
test_doublerange.py \
test_fractionrange.py \
test_valuearray.py \
test_valuelist.py
test_types.py
EXTRA_DIST = \
__init__.py \
......
......@@ -2,13 +2,7 @@ runtests = find_program('runtests.py')
tests = [
['Test gst', 'test_gst.py'],
['Test fractions', 'test_fraction.py'],
['Test integer ranges', 'test_intrange.py'],
['Test 64bit integer ranges', 'test_int64range.py'],
['Test double ranges', 'test_doublerange.py'],
['Test fraction ranges', 'test_fractionrange.py'],
['Test value arrays', 'test_valuearray.py'],
['Test value lists', 'test_valuelist.py']
['Test fundamentals', 'test_types.py'],
]
pluginsdirs = []
......
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
R = Gst.DoubleRange
class TestDoubleRange(TestCase):
def testConstructor(self):
Gst.init(None)
r = R(1.2, 3.4)
self.assertEquals(r.start, 1.2)
self.assertEquals(r.stop, 3.4)
self.assertRaises(TypeError, R, {}, 2)
self.assertRaises(TypeError, R, 2, ())
self.assertRaises(TypeError, R, 2, 1)
self.assertRaises(TypeError, R)
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(R(1,2)), '<Gst.DoubleRange [1.0,2.0]>')
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["range"] = R(1,2)
value = st["range"]
self.failUnlessEqual(value.start, 1.0)
self.failUnlessEqual(value.stop, 2.0)
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
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)
frac = F(1)
self.assertEquals(frac.num, 1)
self.assertEquals(frac.denom, 1)
self.assertRaises(TypeError, F)
def testRepr(self):
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))
self.assertEquals(F(2, 4), F(1, 2))
self.assertNotEquals(F(1, 3), F(1, 2))
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))
self.assertEquals(F(1, 3) / F(4), F(1, 12))
self.assertEquals(F(1, 3) / 4, F(1, 12))
self.assertEquals(F(1, 3) / 2, F(1, 6))
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):
Gst.init(None)
obj = Gst.ElementFactory.make("rawvideoparse")
if not obj:
obj = Gst.ElementFactory.make("rawvideoparse")
if not obj:
# no (raw)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)
value = obj.props.framerate
self.failUnlessEqual(value.num, 2)
self.failUnlessEqual(value.denom, 1)
def bad():
obj.props.framerate = 1
self.failUnlessRaises(TypeError, bad)
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)
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
R = Gst.FractionRange
class TestFractionRange(TestCase):
def testConstructor(self):
Gst.init(None)
r = R(Gst.Fraction(1, 30), Gst.Fraction(1, 2))
self.assertEquals(r.start, Gst.Fraction(1, 30))
self.assertEquals(r.stop, Gst.Fraction(1, 2))
self.assertRaises(TypeError, R, Gst.Fraction(1, 2), Gst.Fraction(1, 30))
self.assertRaises(TypeError, R, 2, Gst.Fraction(1, 2))
self.assertRaises(TypeError, R, Gst.Fraction(1, 2), 2)
self.assertRaises(TypeError, R)
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(R(Gst.Fraction(1,30), Gst.Fraction(1,2))),
'<Gst.FractionRange [1/30,1/2]>')
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["range"] = R(Gst.Fraction(1, 30), Gst.Fraction(1, 2))
value = st["range"]
self.failUnlessEqual(value.start, Gst.Fraction(1, 30))
self.failUnlessEqual(value.stop, Gst.Fraction(1, 2))
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import unittest, sys
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
R = Gst.Int64Range
class TestInt64Range(TestCase):
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testConstructor(self):
Gst.init(None)
r = R(range(0, 10, 2))
self.assertEquals(r.range, range(0, 10, 2))
self.assertRaises(TypeError, R, range(1, 10, 2))
self.assertRaises(TypeError, R, range(0, 9, 2))
self.assertRaises(TypeError, R, range(10, 0))
self.assertRaises(TypeError, R, 1)
self.assertRaises(TypeError, R)
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(R(range(0, 10, 2))), '<Gst.Int64Range [0,10,2]>')
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["range"] = R(range(0, 10, 2))
value = st["range"]
self.failUnlessEqual(value, range(0, 10, 2))
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import unittest, sys
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
R = Gst.IntRange
class TestIntRange(TestCase):
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testConstructor(self):
Gst.init(None)
r = R(range(0, 10, 2))
self.assertEquals(r.range, range(0, 10, 2))
self.assertRaises(TypeError, R, range(1, 10, 2))
self.assertRaises(TypeError, R, range(0, 9, 2))
self.assertRaises(TypeError, R, range(10, 0))
self.assertRaises(TypeError, R, 1)
self.assertRaises(TypeError, R)
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(R(range(0, 10, 2))), '<Gst.IntRange [0,10,2]>')
@unittest.skipUnless(sys.version_info >= (3, 0), "requires Python 3")
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["range"] = R(range(0, 10, 2))
value = st["range"]
self.failUnlessEqual(value, range(0, 10, 2))
This diff is collapsed.
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
A = Gst.ValueArray
class TestFraction(TestCase):
def testConstructor(self):
Gst.init(None)
a = A((1,2,3))
self.assertEquals(a.array, [1,2,3])
self.assertRaises(TypeError, A, 1)
self.assertRaises(TypeError, A)
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(A([1,2,3])), '<Gst.ValueArray <1,2,3>>')
def testPropertyMarshalling(self):
Gst.init(None)
obj = Gst.ElementFactory.make("rawvideoparse")
if not obj:
# no rawvideoparse and I don't know of any elements in core or -base using
# fraction properties. Skip this test.
return
value = obj.props.plane_strides
self.failUnlessEqual(value[0], 320)
self.failUnlessEqual(value[1], 160)
self.failUnlessEqual(value[2], 160)
obj.props.plane_strides = A([640,320,320])
value = obj.props.plane_strides
self.failUnlessEqual(value[0], 640)
self.failUnlessEqual(value[1], 320)
self.failUnlessEqual(value[2], 320)
def bad():
obj.props.plane_strides = 1
self.failUnlessRaises(TypeError, bad)
value = obj.props.plane_strides
self.failUnlessEqual(value[0], 640)
self.failUnlessEqual(value[1], 320)
self.failUnlessEqual(value[2], 320)
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["array"] = A([Gst.Fraction(1, 30), Gst.Fraction(1, 2)])
value = st["array"]
st["array"] = A(value)
self.failUnlessEqual(value[0], Gst.Fraction(1, 30))
self.failUnlessEqual(value[1], Gst.Fraction(1, 2))
st["matrix"] = A([A([0, 1]), A([-1, 0])])
value = st["matrix"]
self.failUnlessEqual(value[0][0], 0)
self.failUnlessEqual(value[0][1], 1)
self.failUnlessEqual(value[1][0], -1)
self.failUnlessEqual(value[1][1], 0)
# -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# gst-python - Python bindings for GStreamer
# Copyright (C) 2007 Johan Dahlin
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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 overrides_hack
overrides_hack
from common import TestCase
import gi
gi.require_version("Gst", "1.0")
from gi.repository import Gst
Gst.init(None)
L = Gst.ValueList
class TestFraction(TestCase):
def testConstructor(self):
Gst.init(None)
a = L((1,2,3))
self.assertEquals(a.array, [1,2,3])
self.assertRaises(TypeError, L, 1)
self.assertRaises(TypeError, L)
def testRepr(self):
Gst.init(None)
self.assertEquals(repr(L([1,2,3])), '<Gst.ValueList {1,2,3}>')
def testGetValue(self):
Gst.init(None)
st = Gst.Structure.new_empty("video/x-raw")
st["framerate"] = L([Gst.Fraction(1, 30), Gst.Fraction(1, 2)])
value = st["framerate"]
self.failUnlessEqual(value[0], Gst.Fraction(1, 30))
self.failUnlessEqual(value[1], Gst.Fraction(1, 2))
st["matrix"] = L([L([0, 1]), L([-1 ,0])])
value = st["matrix"]
self.failUnlessEqual(value[0][0], 0)
self.failUnlessEqual(value[0][1], 1)
self.failUnlessEqual(value[1][0], -1)
self.failUnlessEqual(value[1][1], 0)
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