validate:launcher: Add a TestManager to run python tests
authorThibault Saunier <tsaunier@igalia.com>
Fri, 15 Jun 2018 20:42:32 +0000 (16:42 -0400)
committerThibault Saunier <tsaunier@igalia.com>
Fri, 15 Jun 2018 21:57:24 +0000 (17:57 -0400)
Add a stupid simple testsuite made to be configured from the outside

validate/launcher/apps/Makefile.am
validate/launcher/apps/meson.build
validate/launcher/apps/pyunittest.py [new file with mode: 0644]
validate/launcher/testsuites/Makefile.am
validate/launcher/testsuites/meson.build
validate/launcher/testsuites/pyunittest.py [new file with mode: 0644]

index 6999253..77d3b95 100644 (file)
@@ -5,4 +5,5 @@ SUBDIRS =
 apps_PYTHON = \
        __init__.py \
        gstvalidate.py \
+       pyunittest.py \
        gstcheck.py
index a13260b..72f2f7f 100644 (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')
diff --git a/validate/launcher/apps/pyunittest.py b/validate/launcher/apps/pyunittest.py
new file mode 100644 (file)
index 0000000..daeac62
--- /dev/null
@@ -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
index 75b0182..b4251bd 100644 (file)
@@ -3,4 +3,5 @@ appsdir = $(libdir)/gst-validate-launcher/python/launcher/testsuites/
 SUBDIRS =
 
 apps_PYTHON = \
-       check.py
+       check.py \
+       pyunittest.py
index dc01698..069297e 100644 (file)
@@ -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 (file)
index 0000000..cd24e9b
--- /dev/null
@@ -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