7 from random import randint
9 from optparse import OptionParser
10 from pasytest import PasyTest
12 from dbus.mainloop.glib import DBusGMainLoop
14 DBusGMainLoop(set_as_default=True)
16 def run_test_app(module_name, dbus_name=None, wait_for_debug=False):
18 from subprocess import Popen
20 test_data_directory = os.environ["TEST_DATA_DIRECTORY"]
21 test_modules_directory = os.environ["TEST_MODULES_DIRECTORY"]
22 test_atspi_library = os.environ["TEST_ATSPI_LIBRARY"]
23 test_application = os.environ["TEST_APPLICATION"]
25 test_module = os.path.join(test_modules_directory, module_name)
28 print " ".join([test_application,
29 "--atspi-dbus-name", dbus_name,
30 "--test-atspi-library", test_atspi_library,
31 "--test-module", test_module,
32 "--test-data-directory", test_data_directory,])
33 pop = Popen([test_application,
34 "--atspi-dbus-name", dbus_name,
35 "--test-atspi-library", test_atspi_library,
36 "--test-module", test_module,
37 "--test-data-directory", test_data_directory,])
39 print " ".join([test_application,
40 "--test-atspi-library", test_atspi_library,
41 "--test-module", test_module,
42 "--test-data-directory", test_data_directory,])
43 pop = Popen([test_application,
44 "--test-atspi-library", test_atspi_library,
45 "--test-module", test_module,
46 "--test-data-directory", test_data_directory,])
49 The test application %s has been started with PID %d.
51 To continue the test press ENTER.\n\n
54 raw_input(wait_message % (module_name, pop.pid))
57 parser = OptionParser()
58 parser.add_option("-l", "--library", dest="test_library")
59 parser.add_option("-m", "--module", dest="test_module")
60 parser.add_option("-n", "--name", dest="test_name")
61 parser.add_option("-w", "--wait", action="store_true", dest="wait", default=False)
62 (options, args) = parser.parse_args()
64 bus = dbus.SessionBus()
65 name = "test.atspi.R" + str(randint(1, 1000))
67 app = run_test_app(options.test_library, name, wait_for_debug=options.wait)
69 print "Started test app on bus name %s" % (name,)
71 to = bus.get_object(name, "/org/codethink/atspi/test")
72 test = dbus.Interface(to, "org.codethink.atspi.test")
74 # Run the test script here
75 module = __import__(options.test_module)
76 test_class = getattr(module, options.test_name)
77 test_object = test_class(bus, name)
80 loop = gobject.MainLoop()
82 def finished_handler():
84 print "\n" + test_object.report() + "\n"
87 test_object.events.finished += finished_handler
91 if __name__=="__main__":
92 sys.exit(main(sys.argv))