#!@PYTHON@ # -*- coding: utf-8 -*- import sys import os import tempfile sys.path.insert(0, os.path.abspath(os.path.join(__file__, "@SRC_DIR@"))) import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gio from gi.repository import GLib from dfeet.settings import Settings 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_DIR@") 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 class SettingsTest(unittest.TestCase): """Tests for the Settings class. Why does it reimplement list values around ConfigParser rather than using GKeyFile which supports list values directly? Nobody knows. """ def setUp(self): self.tempfile = tempfile.NamedTemporaryFile() def tearDown(self): self.tempfile.close() def test_read_empty(self): settings = Settings(self.tempfile.name) self.assertIn('windowwidth', settings.general) self.assertIn('windowheight', settings.general) self.assertEqual([], settings.general['addbus_list']) def test_write(self): settings = Settings(self.tempfile.name) settings.general['windowwidth'] = 800 settings.general['windowheight'] = 600 settings.general['addbus_list'] = ['a', 'b'] settings.write() # Reload with a new instance settings = Settings(self.tempfile.name) # FIXME: yes, these come back out as strings self.assertEqual('800', settings.general['windowwidth']) self.assertEqual('600', settings.general['windowheight']) self.assertEqual(['a', 'b'], settings.general['addbus_list']) if __name__ == "__main__": # run tests unittest.main()