diff --git a/validate/launcher/apps/Makefile.am b/validate/launcher/apps/Makefile.am index 69992530d0..77d3b9579c 100644 --- a/validate/launcher/apps/Makefile.am +++ b/validate/launcher/apps/Makefile.am @@ -5,4 +5,5 @@ SUBDIRS = apps_PYTHON = \ __init__.py \ gstvalidate.py \ + pyunittest.py \ gstcheck.py diff --git a/validate/launcher/apps/meson.build b/validate/launcher/apps/meson.build index a13260b587..72f2f7fbd1 100644 --- a/validate/launcher/apps/meson.build +++ b/validate/launcher/apps/meson.build @@ -1,2 +1,2 @@ -install_data(sources: ['__init__.py', 'gstvalidate.py', 'gstcheck.py'], +install_data(sources: ['__init__.py', 'gstvalidate.py', 'gstcheck.py', 'pyunittest.py'], install_dir: _launcherdir + '/apps') diff --git a/validate/launcher/apps/pyunittest.py b/validate/launcher/apps/pyunittest.py new file mode 100644 index 0000000000..daeac622f7 --- /dev/null +++ b/validate/launcher/apps/pyunittest.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2018,Thibault Saunier +# +# This program 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 program 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 program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301, USA. +import os +import sys +import unittest + +from launcher.baseclasses import Test +from launcher.baseclasses import TestsManager + + +class PythonTest(Test): + + def build_arguments(self): + """Builds subprocess arguments.""" + self.add_arguments('-m', 'unittest', '.'.join(self.classname.split('.')[1:])) + + +class PythonTestsManager(TestsManager): + name = "pyunittest" + arggroup = None + + def __init__(self): + super().__init__() + + def add_options(self, parser): + if self.arggroup: + return + + arggroup = PythonTestsManager.arggroup = parser.add_argument_group( + "Python tests specific options and behaviours") + arggroup.add_argument("--pyunittest-dir", + action="append", + default=[], + help="Paths to look for Python tests.") + + def list_tests(self): + if self.tests: + return self.tests + + for _dir in self.options.pyunittest_dir: + loader = unittest.TestLoader() + testsuites = loader.discover(_dir) + for testsuite in testsuites: + for _tests in testsuite: + if isinstance(_tests, unittest.loader._FailedTest): + print(_tests._exception) + continue + for test in _tests: + self.add_test(PythonTest( + sys.executable, test.id(), + self.options, self.reporter, + extra_env_variables={'PYTHONPATH': _dir})) + + return self.tests diff --git a/validate/launcher/testsuites/Makefile.am b/validate/launcher/testsuites/Makefile.am index 75b0182154..b4251bd3dd 100644 --- a/validate/launcher/testsuites/Makefile.am +++ b/validate/launcher/testsuites/Makefile.am @@ -3,4 +3,5 @@ appsdir = $(libdir)/gst-validate-launcher/python/launcher/testsuites/ SUBDIRS = apps_PYTHON = \ - check.py + check.py \ + pyunittest.py diff --git a/validate/launcher/testsuites/meson.build b/validate/launcher/testsuites/meson.build index dc016989d5..069297e2ec 100644 --- a/validate/launcher/testsuites/meson.build +++ b/validate/launcher/testsuites/meson.build @@ -1,3 +1,3 @@ -install_data(sources: ['check.py'], +install_data(sources: ['check.py', 'pyunittest.py'], install_dir: _launcherdir + '/testsuites') diff --git a/validate/launcher/testsuites/pyunittest.py b/validate/launcher/testsuites/pyunittest.py new file mode 100644 index 0000000000..cd24e9be6b --- /dev/null +++ b/validate/launcher/testsuites/pyunittest.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2018,Thibault Saunier +# +# This program 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 program 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 program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +TEST_MANAGER = "pyunittest" + + +def setup_tests(test_manager, options): + """Sets up python unit testsuite from external configuration.""" + test_manager.list_tests() + return True