* test/python: Add python regression test
authorJohn (J5) Palmieri <johnp@redhat.com>
Thu, 25 Aug 2005 00:20:41 +0000 (00:20 +0000)
committerJohn (J5) Palmieri <johnp@redhat.com>
Thu, 25 Aug 2005 00:20:41 +0000 (00:20 +0000)
* configure.in: Add test/python/Makefile

* test/Makefile.am: Add the python directory to SUBDIRS

ChangeLog
configure.in
test/Makefile.am
test/python/Makefile.am [new file with mode: 0644]
test/python/run-test.sh [new file with mode: 0755]
test/python/test-client.py [new file with mode: 0755]
test/python/test-service.py [new file with mode: 0755]

index 3d9962d..6338f4b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-08-24  John (J5) Palmieri  <johnp@redhat.com>
 
+       * test/python: Add python regression test
+
+       * configure.in: Add test/python/Makefile
+
+       * test/Makefile.am: Add the python directory to SUBDIRS
+
+2005-08-24  John (J5) Palmieri  <johnp@redhat.com>
+
        * Release 0.36.1
 
        * python/_dbus.py: 
index bf177ee..d338f68 100644 (file)
@@ -1202,6 +1202,7 @@ TEST_PATH(SERVICE_DIR, data/valid-service-files)
 TEST_PATH(SERVICE_BINARY, test-service)
 TEST_PATH(SHELL_SERVICE_BINARY, test-shell-service)
 TEST_PATH(GLIB_SERVICE_BINARY, glib/test-service-glib)
+TEST_PATH(PYTHON_SERVICE_BINARY, python/test-service.py)
 TEST_PATH(EXIT_BINARY, test-exit)
 TEST_PATH(SEGFAULT_BINARY, test-segfault)
 TEST_PATH(SLEEP_FOREVER_BINARY, test-sleep-forever)
@@ -1300,6 +1301,7 @@ bus/Makefile
 tools/Makefile
 test/Makefile
 test/glib/Makefile
+test/python/Makefile
 doc/Makefile
 dbus-1.pc
 dbus-glib-1.pc
@@ -1311,6 +1313,7 @@ test/data/valid-service-files/debug-segfault.service
 test/data/valid-service-files/debug-glib.service
 test/data/valid-service-files/debug-shell-echo-success.service
 test/data/valid-service-files/debug-shell-echo-fail.service
+test/data/valid-service-files/debug-python.service
 ])
 
 ### FIXME it's bizarre that have_qt and have_glib are used
index 27f5102..e0a25aa 100644 (file)
@@ -2,9 +2,12 @@
 if HAVE_GLIB
     GLIB_SUBDIR=glib
 endif
+if HAVE_PYTHON
+    PYTHON_SUBDIR=python
+endif
 
-SUBDIRS=$(GLIB_SUBDIR)
-DIST_SUBDIRS=glib
+SUBDIRS=$(GLIB_SUBDIR) $(PYTHON_SUBDIR)
+DIST_SUBDIRS=glib python
 
 INCLUDES=-I$(top_srcdir) $(DBUS_TEST_CFLAGS) 
 
diff --git a/test/python/Makefile.am b/test/python/Makefile.am
new file mode 100644 (file)
index 0000000..5e4da98
--- /dev/null
@@ -0,0 +1,11 @@
+## note that TESTS has special meaning (stuff to use in make check)
+## so if adding tests not to be run in make check, don't add them to 
+## TESTS
+if DBUS_BUILD_TESTS
+TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=$(ABSOLUTE_TOP_BUILDDIR)
+TESTS=run-test.sh
+else
+TESTS=
+endif
+
+EXTRA_DIST=run-test.sh test-service.py test-client.py
diff --git a/test/python/run-test.sh b/test/python/run-test.sh
new file mode 100755 (executable)
index 0000000..f7e067a
--- /dev/null
@@ -0,0 +1,34 @@
+#! /bin/bash
+
+function die()
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+    echo $SCRIPTNAME: $* >&2
+
+    rm $DBUS_TOP_BUILDDIR/python/dbus
+    exit 1
+}
+
+
+SCRIPTNAME=$0
+MODE=$1
+
+## so the tests can complain if you fail to use the script to launch them
+export DBUS_TEST_PYTHON_RUN_TEST_SCRIPT=1
+
+# Rerun ourselves with tmp session bus if we're not already
+if test -z "$DBUS_TEST_PYTHON_IN_RUN_TEST"; then
+  DBUS_TEST_PYTHON_IN_RUN_TEST=1
+  export DBUS_TEST_PYTHON_IN_RUN_TEST
+  exec $DBUS_TOP_BUILDDIR/tools/run-with-tmp-session-bus.sh $SCRIPTNAME $MODE
+fi  
+
+ln -s $DBUS_TOP_BUILDDIR/python $DBUS_TOP_BUILDDIR/python/dbus
+echo "running test-client.py"
+$DBUS_TOP_BUILDDIR/test/python/test-client.py || die "test-client.py failed"
+rm $DBUS_TOP_BUILDDIR/python/dbus
+
diff --git a/test/python/test-client.py b/test/python/test-client.py
new file mode 100755 (executable)
index 0000000..f9f692c
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+import sys
+import os
+
+builddir = os.environ["DBUS_TOP_BUILDDIR"]
+pydir = builddir + "/python"
+
+sys.path.insert(0, pydir)
+
+import dbus
+
+if not dbus.__file__.startswith(pydir):
+    raise Exception("DBus modules are not being picked up from the package")
+
+bus = dbus.SessionBus()
+remote_object = bus.get_object("org.freedesktop.DBus.TestSuitePythonService", "/org/freedesktop/DBus/TestSuitePythonObject")
+iface = dbus.Interface(remote_object, "org.freedesktop.DBus.TestSuiteInterface")
+
+try:
+    #test dbus_interface parameter 
+    print remote_object.Echo("dbus_interface test Passed", dbus_interface = "org.freedesktop.DBus.TestSuiteInterface")
+
+    #test introspection
+    print "\n********* Introspection Test ************"
+    print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable")
+    print "Introspection test passed"
+
+    #test sending python types and getting them back
+    print "\n********* Testing Python Types ***********"
+    test_vals = [1, 12323231, 3.14159265, 99999999.99,
+                 "dude", "123", "What is all the fuss about?", "gob@gob.com",
+                 [1,2,3], ["how", "are", "you"], [1.23,2.3], [1], ["Hello"],
+                 (1,2,3), (1,), (1,"2",3), ("2", "what"), ("you", 1.2),
+                 {1:"a", 2:"b"}, {"a":1, "b":2}, {1:1.1, 2:2.2}, {1.1:"a", 1.2:"b"}, 
+                 [[1,2,3],[2,3,4]], [["a","b"],["c","d"]],
+                 ([1,2,3],"c", 1.2, ["a","b","c"], {"a": (1,"v"), "b": (2,"d")})]
+                 
+    for send_val in test_vals:
+        print "Testing %s"% str(send_val)
+        recv_val = iface.Echo(send_val)
+        #TODO: is this right in python - construct a better comparison
+        #      method
+        if send_val != recv_val:
+            raise Exception("Python type tests: %s does not equal %s"%(str(send_val), str(recv_val)))
+    
+    
+    
+except Exception, e:
+    print e
+    sys.exit(1)
+
+sys.exit(0)
diff --git a/test/python/test-service.py b/test/python/test-service.py
new file mode 100755 (executable)
index 0000000..21d101c
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+import sys
+import os
+
+builddir = os.environ["DBUS_TOP_BUILDDIR"]
+pydir = builddir + "/python"
+
+sys.path.insert(0, pydir)
+
+import dbus
+
+if not dbus.__file__.startswith(pydir):
+    raise Exception("DBus modules are not being picked up from the package")
+
+import dbus.service
+import dbus.glib
+import gobject
+
+class TestObject(dbus.service.Object):
+    def __init__(self, bus_name, object_path="/org/freedesktop/DBus/TestSuitePythonObject"):
+        dbus.service.Object.__init__(self, bus_name, object_path)
+
+    """ Echo whatever is sent
+    """
+    @dbus.service.method("org.freedesktop.DBus.TestSuiteInterface")
+    def Echo(self, arg):
+        return arg
+
+session_bus = dbus.SessionBus()
+name = dbus.service.BusName("org.freedesktop.DBus.TestSuitePythonService", bus=session_bus)
+object = TestObject(name)
+
+loop = gobject.MainLoop()
+loop.run()