[gnome-bluetooth/wip/hadess/add-tests] tests: Add integration tests
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/add-tests] tests: Add integration tests
- Date: Fri, 12 Feb 2021 17:21:08 +0000 (UTC)
commit 3f6bccd0aeb7e4bb503cca5070610a08b12058f1
Author: Bastien Nocera <hadess hadess net>
Date: Fri Feb 12 17:47:57 2021 +0100
tests: Add integration tests
Add a simple test using python-dbusmock to test out some of our code.
.gitlab-ci.yml | 3 ++
meson.build | 1 +
tests/integration-test | 117 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/meson.build | 13 ++++++
4 files changed, 134 insertions(+)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index ba79ce44..928ac01c 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,6 +14,8 @@ variables:
gcc
glibc-devel
git
+ TEST_DEPS:
+ python3-dbusmock
GIT_SUBMODULE_STRATEGY: recursive
DEPENDENCIES_ABI_CHECK:
libabigail
@@ -27,6 +29,7 @@ build_stable:
- meson . _build --prefix=/usr
- ninja -C _build
- ninja -C _build install
+ - dnf install -y --nogpgcheck $TEST_DEPS
- ninja -C _build test
- ninja -C _build dist
- dnf install -y $DEPENDENCIES_ABI_CHECK
diff --git a/meson.build b/meson.build
index 4e712ef1..6a64f5f2 100644
--- a/meson.build
+++ b/meson.build
@@ -114,6 +114,7 @@ if enable_gtk_doc
endif
subdir('po')
+subdir('tests')
configure_file(
output: 'config.h',
diff --git a/tests/integration-test b/tests/integration-test
new file mode 100755
index 00000000..3b78f251
--- /dev/null
+++ b/tests/integration-test
@@ -0,0 +1,117 @@
+#!/usr/bin/python3
+
+# gnome-bluetooth integration test suite
+#
+# Copyright: (C) 2021 Bastien Nocera <hadess hadess net>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 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 General Public License for more details.
+
+import os
+import sys
+import dbus
+import tempfile
+import subprocess
+import unittest
+import time
+
+try:
+ import gi
+ from gi.repository import GLib
+ from gi.repository import Gio
+except ImportError as e:
+ sys.stderr.write('Skipping tests, PyGobject not available for Python 3, or missing GI typelibs: %s\n' %
str(e))
+ sys.exit(0)
+
+try:
+ gi.require_version('GIRepository', '2.0')
+ from gi.repository import GIRepository
+ builddir = os.getenv('top_builddir', '.')
+ GIRepository.Repository.prepend_library_path(builddir + '/lib/')
+
+ gi.require_version('GnomeBluetooth', '1.0')
+ from gi.repository import GnomeBluetooth
+except ImportError as e:
+ sys.stderr.write('Could not find GnomeBluetooth gobject-introspection data: %s\n' % str(e))
+ sys.exit(1)
+
+try:
+ gi.require_version('UMockdev', '1.0')
+ from gi.repository import UMockdev
+except ImportError:
+ sys.stderr.write('Skipping tests, umockdev not available (https://github.com/martinpitt/umockdev)\n')
+ sys.exit(0)
+
+try:
+ import dbusmock
+except ImportError:
+ sys.stderr.write('Skipping tests, python-dbusmock not available
(http://pypi.python.org/pypi/python-dbusmock).\n')
+ sys.exit(0)
+
+# Out-of-process tests
+class OopTests(dbusmock.DBusTestCase):
+ @classmethod
+ def setUp(self):
+ self.client = GnomeBluetooth.Client.new()
+
+ def print_tree(self, model):
+ def print_row(model, treepath, treeiter):
+ print("\t" * (treepath.get_depth() - 1), model[treeiter][:], sep="")
+ model.foreach(print_row)
+
+ def wait_for_mainloop(self):
+ ml = GLib.MainLoop()
+ GLib.timeout_add_seconds(1, ml.quit)
+ ml.run()
+
+ def test_no_adapters(self):
+ adapters = self.client.get_adapter_model()
+ self.wait_for_mainloop()
+ self.assertEqual(len(adapters), 0)
+
+ def test_one_adapter(self):
+ adapters = self.client.get_adapter_model()
+ self.wait_for_mainloop()
+ self.assertEqual(len(adapters), 1)
+
+class Tests(dbusmock.DBusTestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ os.environ['G_MESSAGES_DEBUG'] = 'all'
+ cls.start_system_bus()
+ cls.dbus_con = cls.get_dbus(True)
+ (cls.p_mock, cls.obj_bluez) = cls.spawn_server_template(
+ 'bluez5', {}, stdout=subprocess.PIPE)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.p_mock.stdout.close()
+ cls.p_mock.terminate()
+ cls.p_mock.wait()
+
+ def setUp(self):
+ self.obj_bluez.Reset()
+ self.dbusmock = dbus.Interface(self.obj_bluez, dbusmock.MOCK_IFACE)
+ self.dbusmock_bluez = dbus.Interface(self.obj_bluez, 'org.bluez.Mock')
+
+ def run_test_process(self, test_name):
+ out = subprocess.run([sys.argv[0], test_name], capture_output=True)
+ self.assertEqual(out.returncode, 0, "Running test " + test_name + " failed:" + str(out.stderr))
+
+ def test_no_adapters(self):
+ self.run_test_process('OopTests.test_no_adapters')
+
+ def test_one_adapter(self):
+ self.dbusmock_bluez.AddAdapter('hci0', 'my-computer')
+ self.run_test_process('OopTests.test_one_adapter')
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 00000000..28c3125a
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,13 @@
+integration_test = find_program('integration-test')
+
+envs = environment()
+envs.set ('top_builddir', meson.build_root())
+envs.set ('top_srcdir', meson.source_root())
+
+if enable_gir
+ test('gnome-bluetooth-integration-test',
+ integration_test,
+ args: [ 'Tests' ],
+ env: envs
+ )
+endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]