From 290df8367154d6aec7c026fb6933fc794753de7a Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Sat, 1 May 2004 15:35:32 +0000 Subject: [PATCH] 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 --- ChangeLog | 14 ++++++++++++++ testsuite/common.py | 28 +++++++++++++++++++++++----- testsuite/element.py | 24 +++++++++++++++++++++--- testsuite/runtests.py | 25 +++++++++++++++++-------- testsuite/test_element.py | 24 +++++++++++++++++++++--- 5 files changed, 96 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index af96a3bb8e..44d3433157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-05-01 Johan Dahlin + + * 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 * gst/gst.defs (element_state_get_name): Add. diff --git a/testsuite/common.py b/testsuite/common.py index 7d8927dfec..a657c8caee 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -4,16 +4,17 @@ import sys import unittest # Don't insert before . -sys.path.insert(1, os.path.join('..', 'gst')) - -import ltihooks +sys.path.insert(1, os.path.join('..')) # Load GST and make sure we load it from the current build sys.setdlopenflags(dl.RTLD_LAZY | dl.RTLD_GLOBAL) +# Hack +sys.argv.append('--gst-debug-no-color') + path = os.path.abspath(os.path.join('..', 'gst')) import gst -assert gst.__path__ != path, 'bad path' +assert gst._gst.__file__ == '../gst/_gst.la' try: import gst.interfaces @@ -26,6 +27,23 @@ try: assert os.path.basename(gst.play.__file__) != path, 'bad path' except ImportError: 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 diff --git a/testsuite/element.py b/testsuite/element.py index 502ab5ab0b..e5043715ce 100644 --- a/testsuite/element.py +++ b/testsuite/element.py @@ -2,6 +2,7 @@ # # testsuite for gstreamer.Element +import common from common import gst, unittest class ElementTest(unittest.TestCase): @@ -32,8 +33,7 @@ class FakeSinkTest(ElementTest): def setUp(self): self.element = gst.Element('fakesink', 'sink') - # Disabled - since it outputs junks - def _testStateError(self): + def testStateError(self): self.element.set_property('state-error', self.FAKESINK_STATE_ERROR_NULL_READY) def error_cb(element, source, error, debug): @@ -44,8 +44,10 @@ class FakeSinkTest(ElementTest): assert isinstance(error, gst.GError) self.element.connect('error', error_cb) + common.disable_stderr() self.element.set_state(gst.STATE_READY) - + common.enable_stderr() + class NonExistentTest(ElementTest): name = 'this-element-does-not-exist' alias = 'no-alias' @@ -53,5 +55,21 @@ class NonExistentTest(ElementTest): def testGoodConstructor(self): 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__": unittest.main() diff --git a/testsuite/runtests.py b/testsuite/runtests.py index 42eabdec5d..b15a627869 100644 --- a/testsuite/runtests.py +++ b/testsuite/runtests.py @@ -1,12 +1,21 @@ #!/usr/bin/env python +import glob import sys -from unittest import TestSuite, TestLoader, TextTestRunner -from types import ClassType +import unittest -loader = TestLoader() -testRunner = TextTestRunner() +SKIP_FILES = ['common', 'runtests'] -test = TestSuite() -for name in ('element', 'interface', 'pipeline'): - test.addTest(loader.loadTestsFromName(name)) -testRunner.run(tests) +def gettestnames(): + files = glob.glob('*.py') + names = map(lambda x: x[:-3], files) + 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) diff --git a/testsuite/test_element.py b/testsuite/test_element.py index 502ab5ab0b..e5043715ce 100644 --- a/testsuite/test_element.py +++ b/testsuite/test_element.py @@ -2,6 +2,7 @@ # # testsuite for gstreamer.Element +import common from common import gst, unittest class ElementTest(unittest.TestCase): @@ -32,8 +33,7 @@ class FakeSinkTest(ElementTest): def setUp(self): self.element = gst.Element('fakesink', 'sink') - # Disabled - since it outputs junks - def _testStateError(self): + def testStateError(self): self.element.set_property('state-error', self.FAKESINK_STATE_ERROR_NULL_READY) def error_cb(element, source, error, debug): @@ -44,8 +44,10 @@ class FakeSinkTest(ElementTest): assert isinstance(error, gst.GError) self.element.connect('error', error_cb) + common.disable_stderr() self.element.set_state(gst.STATE_READY) - + common.enable_stderr() + class NonExistentTest(ElementTest): name = 'this-element-does-not-exist' alias = 'no-alias' @@ -53,5 +55,21 @@ class NonExistentTest(ElementTest): def testGoodConstructor(self): 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__": unittest.main()