From 520a529f3b4277127843454c6d5ec40cceb2755d Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 19 Sep 2018 10:42:23 +0100 Subject: Run tests with same Python version as application Since c28acbf326bb79543b285f371bdf068d8831d9a7 the application has used the Python version detected at configure time, but tests were still unconditionally run with the system version of Python 2. This made it impossible to run the tests on systems with only Python 3. --- .gitignore | 1 + src/tests/Makefile.am | 6 ++- src/tests/tests.py | 108 ------------------------------------------------- src/tests/tests.py.in | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 109 deletions(-) delete mode 100755 src/tests/tests.py create mode 100755 src/tests/tests.py.in diff --git a/.gitignore b/.gitignore index 4bda0ea..113516e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,5 @@ po/stamp-it po/*.gmo py-compile src/d-feet +src/tests/tests.py test-driver diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index d8c2f03..14761b2 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -2,8 +2,12 @@ TESTS = tests.py check_SCRIPTS = tests.py -EXTRA_DIST = tests.py +EXTRA_DIST = tests.py.in +CLEANFILES = $(check_SCRIPTS) +tests.py: tests.py.in + $(AM_V_GEN) sed -e 's|@PYTHON[@]|$(PYTHON)|g' $< > $@ + chmod +x $@ # Default pep8.py --exclude + emacs backup files PEP8_EXCLUDES=--exclude='.svn,CVS,.bzr,.hg,.git,__pycache__,.\#*' diff --git a/src/tests/tests.py b/src/tests/tests.py deleted file mode 100755 index 31a7292..0000000 --- a/src/tests/tests.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python -import sys -import os -sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../"))) - -from gi.repository import Gtk -from gi.repository import Gio -from gi.repository import GLib -from dfeet.introspection import AddressInfo -from dfeet.introspection_helper import DBusNode -from dfeet.introspection_helper import DBusInterface -from dfeet.introspection_helper import DBusProperty -from dfeet.introspection_helper import DBusSignal -from dfeet.introspection_helper import DBusMethod -import unittest - -XML = """ - - - - - - - - - - - - - - - -""" - -DATA_DIR = os.path.abspath("../../data/") - - -class IntrospectionHelperTest(unittest.TestCase): - """tests for the introspection helper classes""" - def setUp(self): - self.name = "org.gnome.dfeet" - self.object_path = "/org/gnome/dfeet" - self.node_info = Gio.DBusNodeInfo.new_for_xml(XML) - - def test_dbus_node_info(self): - """test DBusNode class""" - obj_node = DBusNode(self.name, self.object_path, self.node_info) - self.assertEqual(obj_node.name, self.name) - self.assertEqual(obj_node.object_path, self.object_path) - self.assertEqual(len(obj_node.node_info.interfaces), 1) - - def test_dbus_interface(self): - """test DBusInterface class""" - obj_node = DBusNode(self.name, self.object_path, self.node_info) - obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) - self.assertEqual(obj_iface.name, self.name) - self.assertEqual(obj_iface.object_path, self.object_path) - self.assertEqual(len(obj_iface.iface_info.methods), 1) - self.assertEqual(len(obj_iface.iface_info.properties), 3) - self.assertEqual(len(obj_iface.iface_info.signals), 1) - - def test_dbus_property(self): - """test DBusProperty class""" - obj_node = DBusNode(self.name, self.object_path, self.node_info) - obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) - obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[0]) - self.assertEqual(obj_prop.name, self.name) - self.assertEqual(obj_prop.object_path, self.object_path) - # get the markup string with value for struct prop (see bgo #702593) - obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[2]) - obj_prop.value = ("string", 1, 2) - self.assertIn("'string', 1, 2", obj_prop.markup_str) - - def test_dbus_signal(self): - """test DBusSignal class""" - obj_node = DBusNode(self.name, self.object_path, self.node_info) - obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) - obj_sig = DBusSignal(obj_iface, obj_iface.iface_info.signals[0]) - self.assertEqual(obj_sig.name, self.name) - self.assertEqual(obj_sig.object_path, self.object_path) - - -class AddressInfoTest(unittest.TestCase): - """tests for the AddressInfo class and the introspection stuff""" - - def setUp(self): - self.bus = Gio.TestDBus() - self.bus.unset() - self.bus.up() - - def tearDown(self): - self.bus.stop() - - def test_bus(self): - """introspect a name on the system bus""" - ai = AddressInfo(DATA_DIR, self.bus.get_bus_address(), None, "org.freedesktop.DBus") - - @unittest.skip("TODO:peer to peer test not implemented") - def test_peer_to_peer(self): - """test a p2p connection""" - # TODO: setup a gdbus server and test a peer to peer connection - # (see http://developer.gnome.org/gio/unstable/GDBusServer.html#gdbus-peer-to-peer) - pass - - -if __name__ == "__main__": - # run tests - unittest.main() diff --git a/src/tests/tests.py.in b/src/tests/tests.py.in new file mode 100755 index 0000000..152bef3 --- /dev/null +++ b/src/tests/tests.py.in @@ -0,0 +1,109 @@ +#!@PYTHON@ +# -*- coding: utf-8 -*- +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../"))) + +from gi.repository import Gtk +from gi.repository import Gio +from gi.repository import GLib +from dfeet.introspection import AddressInfo +from dfeet.introspection_helper import DBusNode +from dfeet.introspection_helper import DBusInterface +from dfeet.introspection_helper import DBusProperty +from dfeet.introspection_helper import DBusSignal +from dfeet.introspection_helper import DBusMethod +import unittest + +XML = """ + + + + + + + + + + + + + + + +""" + +DATA_DIR = os.path.abspath("../../data/") + + +class IntrospectionHelperTest(unittest.TestCase): + """tests for the introspection helper classes""" + def setUp(self): + self.name = "org.gnome.dfeet" + self.object_path = "/org/gnome/dfeet" + self.node_info = Gio.DBusNodeInfo.new_for_xml(XML) + + def test_dbus_node_info(self): + """test DBusNode class""" + obj_node = DBusNode(self.name, self.object_path, self.node_info) + self.assertEqual(obj_node.name, self.name) + self.assertEqual(obj_node.object_path, self.object_path) + self.assertEqual(len(obj_node.node_info.interfaces), 1) + + def test_dbus_interface(self): + """test DBusInterface class""" + obj_node = DBusNode(self.name, self.object_path, self.node_info) + obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) + self.assertEqual(obj_iface.name, self.name) + self.assertEqual(obj_iface.object_path, self.object_path) + self.assertEqual(len(obj_iface.iface_info.methods), 1) + self.assertEqual(len(obj_iface.iface_info.properties), 3) + self.assertEqual(len(obj_iface.iface_info.signals), 1) + + def test_dbus_property(self): + """test DBusProperty class""" + obj_node = DBusNode(self.name, self.object_path, self.node_info) + obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) + obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[0]) + self.assertEqual(obj_prop.name, self.name) + self.assertEqual(obj_prop.object_path, self.object_path) + # get the markup string with value for struct prop (see bgo #702593) + obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[2]) + obj_prop.value = ("string", 1, 2) + self.assertIn("'string', 1, 2", obj_prop.markup_str) + + def test_dbus_signal(self): + """test DBusSignal class""" + obj_node = DBusNode(self.name, self.object_path, self.node_info) + obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) + obj_sig = DBusSignal(obj_iface, obj_iface.iface_info.signals[0]) + self.assertEqual(obj_sig.name, self.name) + self.assertEqual(obj_sig.object_path, self.object_path) + + +class AddressInfoTest(unittest.TestCase): + """tests for the AddressInfo class and the introspection stuff""" + + def setUp(self): + self.bus = Gio.TestDBus() + self.bus.unset() + self.bus.up() + + def tearDown(self): + self.bus.stop() + + def test_bus(self): + """introspect a name on the system bus""" + ai = AddressInfo(DATA_DIR, self.bus.get_bus_address(), None, "org.freedesktop.DBus") + + @unittest.skip("TODO:peer to peer test not implemented") + def test_peer_to_peer(self): + """test a p2p connection""" + # TODO: setup a gdbus server and test a peer to peer connection + # (see http://developer.gnome.org/gio/unstable/GDBusServer.html#gdbus-peer-to-peer) + pass + + +if __name__ == "__main__": + # run tests + unittest.main() -- cgit v1.2.1