def _getTestInfo(): "Inspect the file being executed to determine the test's name, description, and parameters" name = '' try: name = utils.getBasenameWithoutExtension(sys.modules['__main__'].__file__) except AttributeError: pass desc = '' therest = None try: # try parsing the test script's docblock assuming it is in the form: # """ # Test description # # YAML tags # """ desc, therest = sys.modules['__main__'].__doc__.split('\n\n', 1) desc = desc.lstrip() except Exception: try: # try parsing the test script's docblock assuming it is in the form: # """Test description""" desc = sys.modules['__main__'].__doc__.lstrip() except Exception: pass if desc is None: # how does this happen? desc = '' parameters = {} if therest: try: parameters = yaml.load(therest) except NameError: pass return (name, desc, parameters)
def launchApplication(args=[], name=None, find=None, cwd=None, env=None, wait=config.MEDIUM_DELAY, cache=True, logString=None): ''' Launch an application with accessibility enabled args, cwd, and env are passed to subprocess.Popen. If cwd is not specified, it defaults to os.cwd(). If env is not specified, it defaults to os.environ, plus GTK_MODULES='gail:atk-bridge' After launching the application, a reference to the strongwind.accessibles.Application is cached. The "name" argument to this method is used to find the accessible that should be promoted to a strongwind.accessibles.Application. The name is also used to refer to the application in the test procedures log. If name is not specified, it defaults to the basename of args[0] with any file extension stripped. If the accessible name of the application is not fixed, the "find" argument can be used to search for a pattern. If find is not specified, it defaults to re.compile('^' + name) Returns a tuple containing a strongwind.accessibles.Application object and a Popen object. ''' # if a name for the application is not specified, try to guess it if name is None: name = utils.getBasenameWithoutExtension(args[0]) if logString is None: logString = 'Launch %s.' % name procedurelogger.action(logString) if env is None: env = os.environ # enable accessibility for this application if not env.has_key('GTK_MODULES'): env['GTK_MODULES'] = 'gail:atk-bridge' if find is None: find = re.compile('^' + name) if cwd is None: cwd = os.getcwd() def findAppWithLargestId(desktop, find): ''' Find the application with the largest id whose name matches find If ids are not recycled (i.e., ids always increment and never start over again at 1), the application with the highest id will be the last launched. We're making this assumption. ''' appWithLargestId = None apps = utils.findAllDescendants( desktop, lambda x: pyatspi.ROLE_APPLICATION == x.role and find. search(x.name), False) if len(apps) > 0: appWithLargestId = apps[0] for a in apps: if a._accessible.id > appWithLargestId._accessible.id: appWithLargestId = a return appWithLargestId # before we launch the application, check to see if there is another # instance of the application already open existingApp = findAppWithLargestId(_desktop, find) # launch the application subproc = subprocess.Popen(args, cwd=cwd, env=env) # wait for the application to launch and for the applications list to # settle. if we try to list the desktop's applications too soon, we get # crashes sometimes. sleep(wait) def findNewApplication(): ''' Find the application we just launched If there is an existing application, make sure the app we find here has an id larger than the existing application. If no application is found, wait and retry a number of times before returning None. ''' for i in xrange(config.RETRY_TIMES): app = findAppWithLargestId(_desktop, find) try: if existingApp is None or existingApp.id < app.id: return app except (LookupError, pyatspi.ORBit.CORBA.COMM_FAILURE): return app sleep(config.RETRY_INTERVAL) raise errors.SearchError app = findNewApplication() if cache: addApplication(app) return (app, subproc)
def launchApplication( args=[], name=None, find=None, cwd=None, env=None, wait=config.MEDIUM_DELAY, cache=True, logString=None ): """ Launch an application with accessibility enabled args, cwd, and env are passed to subprocess.Popen. If cwd is not specified, it defaults to os.cwd(). If env is not specified, it defaults to os.environ, plus GTK_MODULES='gail:atk-bridge' After launching the application, a reference to the strongwind.accessibles.Application is cached. The "name" argument to this method is used to find the accessible that should be promoted to a strongwind.accessibles.Application. The name is also used to refer to the application in the test procedures log. If name is not specified, it defaults to the basename of args[0] with any file extension stripped. If the accessible name of the application is not fixed, the "find" argument can be used to search for a pattern. If find is not specified, it defaults to re.compile('^' + name) Returns a tuple containing a strongwind.accessibles.Application object and a Popen object. """ # if a name for the application is not specified, try to guess it if name is None: name = utils.getBasenameWithoutExtension(args[0]) if logString is None: logString = "Launch %s." % name procedurelogger.action(logString) if env is None: env = os.environ # enable accessibility for this application if not env.has_key("GTK_MODULES"): env["GTK_MODULES"] = "gail:atk-bridge" if find is None: find = re.compile("^" + name) if cwd is None: cwd = os.getcwd() def findAppWithLargestId(desktop, find): """ Find the application with the largest id whose name matches find If ids are not recycled (i.e., ids always increment and never start over again at 1), the application with the highest id will be the last launched. We're making this assumption. """ appWithLargestId = None apps = utils.findAllDescendants( desktop, lambda x: pyatspi.ROLE_APPLICATION == x.role and find.search(x.name), False ) if len(apps) > 0: appWithLargestId = apps[0] for a in apps: if a._accessible.id > appWithLargestId._accessible.id: appWithLargestId = a return appWithLargestId # before we launch the application, check to see if there is another # instance of the application already open existingApp = findAppWithLargestId(_desktop, find) # launch the application subproc = subprocess.Popen(args, cwd=cwd, env=env) # wait for the application to launch and for the applications list to # settle. if we try to list the desktop's applications too soon, we get # crashes sometimes. sleep(wait) def findNewApplication(): """ Find the application we just launched If there is an existing application, make sure the app we find here has an id larger than the existing application. If no application is found, wait and retry a number of times before returning None. """ for i in xrange(config.RETRY_TIMES): app = findAppWithLargestId(_desktop, find) try: if existingApp is None or existingApp.id < app.id: return app except (LookupError, pyatspi.ORBit.CORBA.COMM_FAILURE): return app sleep(config.RETRY_INTERVAL) raise errors.SearchError app = findNewApplication() if cache: addApplication(app) return (app, subproc)