testsuite/runtests.py (gettestnames): Cleanup

Original commit message from CVS:
* testsuite/runtests.py (gettestnames): Cleanup

* testsuite/element.py (FakeSinkTest): Enable again and disable
stderr while changing state to ready
(ElementName.testElementStateGetName): New function to test
gst.element_state_get_name.

* testsuite/common.py (path): Don't import ltihooks and proper
check for gst module. Add --gst-debug-no-color as a global option
(disable_stderr, enable_stderr): New functions to disable stdout
called from non python
This commit is contained in:
Johan Dahlin 2004-05-01 15:35:32 +00:00
parent ca3eb4296c
commit 290df83671
5 changed files with 96 additions and 19 deletions

View file

@ -1,3 +1,17 @@
2004-05-01 Johan Dahlin <johan@gnome.org>
* testsuite/runtests.py (gettestnames): Cleanup
* testsuite/element.py (FakeSinkTest): Enable again and disable
stderr while changing state to ready
(ElementName.testElementStateGetName): New function to test
gst.element_state_get_name.
* testsuite/common.py (path): Don't import ltihooks and proper
check for gst module. Add --gst-debug-no-color as a global option
(disable_stderr, enable_stderr): New functions to disable stdout
called from non python
2004-04-30 Johan Dahlin <johan@gnome.org> 2004-04-30 Johan Dahlin <johan@gnome.org>
* gst/gst.defs (element_state_get_name): Add. * gst/gst.defs (element_state_get_name): Add.

View file

@ -4,16 +4,17 @@ import sys
import unittest import unittest
# Don't insert before . # Don't insert before .
sys.path.insert(1, os.path.join('..', 'gst')) sys.path.insert(1, os.path.join('..'))
import ltihooks
# Load GST and make sure we load it from the current build # Load GST and make sure we load it from the current build
sys.setdlopenflags(dl.RTLD_LAZY | dl.RTLD_GLOBAL) sys.setdlopenflags(dl.RTLD_LAZY | dl.RTLD_GLOBAL)
# Hack
sys.argv.append('--gst-debug-no-color')
path = os.path.abspath(os.path.join('..', 'gst')) path = os.path.abspath(os.path.join('..', 'gst'))
import gst import gst
assert gst.__path__ != path, 'bad path' assert gst._gst.__file__ == '../gst/_gst.la'
try: try:
import gst.interfaces import gst.interfaces
@ -26,6 +27,23 @@ try:
assert os.path.basename(gst.play.__file__) != path, 'bad path' assert os.path.basename(gst.play.__file__) != path, 'bad path'
except ImportError: except ImportError:
pass pass
_stderr = None
def disable_stderr():
global _stderr
_stderr = file('/tmp/stderr', 'w+')
sys.stderr = os.fdopen(os.dup(2), 'w')
os.close(2)
os.dup(_stderr.fileno())
def enable_stderr():
global _stderr
os.close(2)
os.dup(sys.stderr.fileno())
_stderr.seek(0, 0)
data = _stderr.read()
_stderr.close()
os.remove('/tmp/stderr')
return data

View file

@ -2,6 +2,7 @@
# #
# testsuite for gstreamer.Element # testsuite for gstreamer.Element
import common
from common import gst, unittest from common import gst, unittest
class ElementTest(unittest.TestCase): class ElementTest(unittest.TestCase):
@ -32,8 +33,7 @@ class FakeSinkTest(ElementTest):
def setUp(self): def setUp(self):
self.element = gst.Element('fakesink', 'sink') self.element = gst.Element('fakesink', 'sink')
# Disabled - since it outputs junks def testStateError(self):
def _testStateError(self):
self.element.set_property('state-error', self.element.set_property('state-error',
self.FAKESINK_STATE_ERROR_NULL_READY) self.FAKESINK_STATE_ERROR_NULL_READY)
def error_cb(element, source, error, debug): def error_cb(element, source, error, debug):
@ -44,8 +44,10 @@ class FakeSinkTest(ElementTest):
assert isinstance(error, gst.GError) assert isinstance(error, gst.GError)
self.element.connect('error', error_cb) self.element.connect('error', error_cb)
common.disable_stderr()
self.element.set_state(gst.STATE_READY) self.element.set_state(gst.STATE_READY)
common.enable_stderr()
class NonExistentTest(ElementTest): class NonExistentTest(ElementTest):
name = 'this-element-does-not-exist' name = 'this-element-does-not-exist'
alias = 'no-alias' alias = 'no-alias'
@ -53,5 +55,21 @@ class NonExistentTest(ElementTest):
def testGoodConstructor(self): def testGoodConstructor(self):
pass pass
class ElementName(unittest.TestCase):
def testElementStateGetName(self):
get_name = gst.element_state_get_name
for state in ('NULL',
'READY',
'PLAYING',
'PAUSED'):
name = 'STATE_' + state
assert hasattr(gst, name)
attr = getattr(gst, name)
assert get_name(attr) == state
assert get_name(gst.STATE_VOID_PENDING) == 'NONE_PENDING'
assert get_name(-1) == 'UNKNOWN!'
self.assertRaises(TypeError, get_name, '')
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

View file

@ -1,12 +1,21 @@
#!/usr/bin/env python #!/usr/bin/env python
import glob
import sys import sys
from unittest import TestSuite, TestLoader, TextTestRunner import unittest
from types import ClassType
loader = TestLoader() SKIP_FILES = ['common', 'runtests']
testRunner = TextTestRunner()
test = TestSuite() def gettestnames():
for name in ('element', 'interface', 'pipeline'): files = glob.glob('*.py')
test.addTest(loader.loadTestsFromName(name)) names = map(lambda x: x[:-3], files)
testRunner.run(tests) map(names.remove, SKIP_FILES)
return names
suite = unittest.TestSuite()
loader = unittest.TestLoader()
for name in gettestnames():
suite.addTest(loader.loadTestsFromName(name))
testRunner = unittest.TextTestRunner()
testRunner.run(suite)

View file

@ -2,6 +2,7 @@
# #
# testsuite for gstreamer.Element # testsuite for gstreamer.Element
import common
from common import gst, unittest from common import gst, unittest
class ElementTest(unittest.TestCase): class ElementTest(unittest.TestCase):
@ -32,8 +33,7 @@ class FakeSinkTest(ElementTest):
def setUp(self): def setUp(self):
self.element = gst.Element('fakesink', 'sink') self.element = gst.Element('fakesink', 'sink')
# Disabled - since it outputs junks def testStateError(self):
def _testStateError(self):
self.element.set_property('state-error', self.element.set_property('state-error',
self.FAKESINK_STATE_ERROR_NULL_READY) self.FAKESINK_STATE_ERROR_NULL_READY)
def error_cb(element, source, error, debug): def error_cb(element, source, error, debug):
@ -44,8 +44,10 @@ class FakeSinkTest(ElementTest):
assert isinstance(error, gst.GError) assert isinstance(error, gst.GError)
self.element.connect('error', error_cb) self.element.connect('error', error_cb)
common.disable_stderr()
self.element.set_state(gst.STATE_READY) self.element.set_state(gst.STATE_READY)
common.enable_stderr()
class NonExistentTest(ElementTest): class NonExistentTest(ElementTest):
name = 'this-element-does-not-exist' name = 'this-element-does-not-exist'
alias = 'no-alias' alias = 'no-alias'
@ -53,5 +55,21 @@ class NonExistentTest(ElementTest):
def testGoodConstructor(self): def testGoodConstructor(self):
pass pass
class ElementName(unittest.TestCase):
def testElementStateGetName(self):
get_name = gst.element_state_get_name
for state in ('NULL',
'READY',
'PLAYING',
'PAUSED'):
name = 'STATE_' + state
assert hasattr(gst, name)
attr = getattr(gst, name)
assert get_name(attr) == state
assert get_name(gst.STATE_VOID_PENDING) == 'NONE_PENDING'
assert get_name(-1) == 'UNKNOWN!'
self.assertRaises(TypeError, get_name, '')
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()