validate:launcher: Add a TestManager to run python tests

Add a stupid simple testsuite made to be configured from the outside
This commit is contained in:
Thibault Saunier 2018-06-15 16:42:32 -04:00
parent 94ee508123
commit d80fb50c4b
6 changed files with 99 additions and 3 deletions

View file

@ -5,4 +5,5 @@ SUBDIRS =
apps_PYTHON = \
__init__.py \
gstvalidate.py \
pyunittest.py \
gstcheck.py

View file

@ -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')

View file

@ -0,0 +1,70 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018,Thibault Saunier <tsaunier@igalia.com>
#
# 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

View file

@ -3,4 +3,5 @@ appsdir = $(libdir)/gst-validate-launcher/python/launcher/testsuites/
SUBDIRS =
apps_PYTHON = \
check.py
check.py \
pyunittest.py

View file

@ -1,3 +1,3 @@
install_data(sources: ['check.py'],
install_data(sources: ['check.py', 'pyunittest.py'],
install_dir: _launcherdir + '/testsuites')

View file

@ -0,0 +1,24 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018,Thibault Saunier <tsaunier@igalia.com>
#
# 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