8 from random import randint
10 from optparse import OptionParser
11 from pasytest import PasyTest
13 from dbus.mainloop.glib import DBusGMainLoop
15 DBusGMainLoop(set_as_default=True)
17 def run_test_app(module_name, dbus_name=None, wait_for_debug=False):
19 from subprocess import Popen
21 test_data_directory = os.environ["TEST_DATA_DIRECTORY"]
22 test_modules_directory = os.environ["TEST_MODULES_DIRECTORY"]
23 test_atspi_library = os.environ["TEST_ATSPI_LIBRARY"]
24 test_application = os.environ["TEST_APPLICATION"]
26 test_module = os.path.join(test_modules_directory, module_name)
29 print " ".join([test_application,
30 "--atspi-dbus-name", dbus_name,
31 "--test-atspi-library", test_atspi_library,
32 "--test-module", test_module,
33 "--test-data-directory", test_data_directory,])
34 pop = Popen([test_application,
35 "--atspi-dbus-name", dbus_name,
36 "--test-atspi-library", test_atspi_library,
37 "--test-module", test_module,
38 "--test-data-directory", test_data_directory,])
40 print " ".join([test_application,
41 "--test-atspi-library", test_atspi_library,
42 "--test-module", test_module,
43 "--test-data-directory", test_data_directory,])
44 pop = Popen([test_application,
45 "--test-atspi-library", test_atspi_library,
46 "--test-module", test_module,
47 "--test-data-directory", test_data_directory,])
50 The test application %s has been started with PID %d.
52 To continue the test press ENTER.\n\n
55 raw_input(wait_message % (module_name, pop.pid))
58 parser = OptionParser()
59 parser.add_option("-l", "--library", dest="test_library")
60 parser.add_option("-m", "--module", dest="test_module")
61 parser.add_option("-n", "--name", dest="test_name")
62 parser.add_option("-w", "--wait", action="store_true", dest="wait", default=False)
63 (options, args) = parser.parse_args()
65 bus = dbus.SessionBus()
66 name = "test.atspi.R" + str(randint(1, 1000))
68 app = run_test_app(options.test_library, name, wait_for_debug=options.wait)
70 print "Started test app on bus name %s" % (name,)
72 to = bus.get_object(name, "/org/codethink/atspi/test")
73 test = dbus.Interface(to, "org.codethink.atspi.test")
75 # Run the test script here
76 os.environ["ATSPI_TEST_APP_NAME"] = name
77 module = __import__(options.test_module)
78 test_class = getattr(module, options.test_name)
79 test_object = test_class(bus, name)
82 loop = gobject.MainLoop()
84 def finished_handler():
86 print "\n" + test_object.report() + "\n"
89 test_object.events.finished += finished_handler
93 if __name__=="__main__":
94 sys.exit(main(sys.argv))