def printResult(result): ''' Prints the given test result. ''' log.debug("Print test result: %s" % result) summary = result.get(name=SUMMARY_CHANNEL)[0].getSummary() log.info("Print summary of test execution results: %s" % summary) report = "Ran %d of %d test cases in %s" % (summary[COUNTER_TESTS_RUN], summary[COUNTER_N_TESTS], summary[COUNTER_RUN_TIME]) print '\n', report printSeparator(len(report)) if summary[STATUS_PASSED]: print "Tests passed:\t\t%d" % summary[STATUS_PASSED] if summary[STATUS_FAILED]: print "Tests failed:\t\t%d" % summary[STATUS_FAILED] if summary[STATUS_NOT_COMPLETED]: print "Tests not completed:\t%d" % summary[STATUS_NOT_COMPLETED] if summary[COUNTER_CORE_DUMPS]: print "Core dumps:\t\t%d" % summary[COUNTER_CORE_DUMPS] if summary[STATUS_ERROR]: print "Tests error:\t\t%d" % summary[STATUS_ERROR] filechls = [chl for chl in result.get(cls=channels.TestResultFileChannel) if chl.isActive()] if filechls: print "Result file:" if len(filechls) == 1 else "Result files:" for channel in filechls: print "\t%s" % channel.filePath() printSeparator() status = (1 if (summary[STATUS_FAILED] + summary[STATUS_ERROR] + summary[STATUS_NOT_COMPLETED]) else 0) exitWithStatus("FAILURE" if status else "SUCCESS", status)
def runTestCases(tests, locations, devices): ''' A function responsible for running the given test cases. ''' log.debug("Run test cases from '%s' locations using '%s' devices: %s" % (", ".join(locations), ", ".join([str(d) for d in devices]), ", ".join(tests))) loader = TestLoader() amountToRun = 0 for path in locations: location.add(path) if not isinstance(tests, (list, tuple)): tests = [tests] suites, errors = loader.loadFromNames(*tests) ncases = 0 for test in suites: ncases += test.count() print (" LOADED %d TEST CASES " % ncases).center(80, '-') + '\n' if len(errors) > 0: print "There were errors during loading test cases:" for error in errors: print "%s\n%s" % (error.name, error.traceback) printSeparator() print if not ncases: #Nothing to do exitWithStatus(status=0) log.info("Start running tests: %s" % suites) channels.add("SummaryChannel", SUMMARY_CHANNEL) result = testresult.TestResult() runner = TestRunner(devices, suites, result) for device in devices: device.connect() try: runner.start() runner.join() except KeyboardInterrupt: runner.stop() finally: for device in devices: if device.isConnected(): device.disconnect() return result
def performRequest(device, options): ''' Performs a request on the given device using the specified options. :param device: A device to perform the request on :type device: tadek.connection.device.Device :param options: Options representing the request :type params: dictionary ''' log.debug("Perform a request on '%s' device using options: %s" % (device, options)) path = accessible.Path(*options.pop("path").split('/')[1:]) device.connect() try: if "action" in options: status = device.doAccessible(path, options["action"]) elif "set-text" in options: text = options["set-text"] status = device.setAccessible(path, text=text) elif "set-text-file" in options: fn = options["set-text-file"] if not os.path.isfile(fn): exitWithError("There is no such file: %s" % fn) fd = None try: fd = open(fn) text = fd.read() finally: if fd: fd.close() status = device.setAccessible(path, text=text) elif "set-value" in options: value = float(options["set-value"]) status = device.setAccessible(path, value=value) elif "mouse-click" in options: x, y = options["mouse-click"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "CLICK") elif "mouse-double-click" in options: x, y = options["mouse-double-click"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "DOUBLE_CLICK") elif "mouse-press" in options: x, y = options["mouse-press"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "PRESS") elif "mouse-release" in options: x, y = options["mouse-release"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "RELEASE") elif "mouse-absolute-motion" in options: x, y = options["mouse-absolute-motion"] status = device.mouseEvent(path, int(x), int(y), '', "ABSOLUTE_MOTION") elif "mouse-relative-motion" in options: x, y = options["mouse-relative-motion"] status = device.mouseEvent(path, int(x), int(y), '', "RELATIVE_MOTION") elif "key" in options: key = options["key"].upper() if key in constants.KEY_SYMS: key = constants.KEY_SYMS[key] elif len(key) == 1: key = ord(key) elif key.startswith("0X"): key = int(key, 16) else: key = int(key) if "modifiers" in options: modifiers = [constants.KEY_CODES[mod] for mod in options["modifiers"]] else: modifiers = [] status = device.keyboardEvent(path, key, modifiers) elif "dump" in options or "dump-all" in options: all = False if "dump" in options: depth = int(options["dump"]) else: depth = -1 if "output" in options: fn = options["output"] all = True obj = device.getAccessible(path, depth, all=all) if obj is None: exitWithStatus("There is no such path: %s" % path, 1) if all: printSeparator() utils.saveXml(obj.marshal(), fn) exitWithStatus("Dump saved to file: %s" % fn) else: printAccessibleTree(obj) exitWithStatus() else: for name in (["all"] + [attr[0] for attr in _ATTRS_EXTRA]): if name in options: break else: exitWithError("Invalid request options: %s" % options) obj = device.getAccessible(path, 0, **{name: True}) if obj is None: exitWithStatus("There is no such path: %s" % path, 1) printAccessibleDetails(obj, name) exitWithStatus() finally: if device.isConnected(): device.disconnect() printSeparator() if status: exitWithStatus("SUCCESS") else: exitWithStatus("FAILURE", 1)
def performRequest(device, options): ''' Performs a request on the given device using the specified options. :param device: A device to perform the request on :type device: tadek.connection.device.Device :param options: Options representing the request :type params: dictionary ''' log.debug("Perform a request on '%s' device using options: %s" % (device, options)) path = accessible.Path(*options.pop("path").split('/')[1:]) device.connect() try: if "action" in options: status = device.doAccessible(path, options["action"]) elif "set-text" in options: text = options["set-text"] status = device.setAccessible(path, text=text) elif "set-text-file" in options: fn = options["set-text-file"] if not os.path.isfile(fn): exitWithError("There is no such file: %s" % fn) fd = None try: fd = open(fn) text = fd.read() finally: if fd: fd.close() status = device.setAccessible(path, text=text) elif "set-value" in options: value = float(options["set-value"]) status = device.setAccessible(path, value=value) elif "mouse-click" in options: x, y = options["mouse-click"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "CLICK") elif "mouse-double-click" in options: x, y = options["mouse-double-click"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "DOUBLE_CLICK") elif "mouse-press" in options: x, y = options["mouse-press"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "PRESS") elif "mouse-release" in options: x, y = options["mouse-release"] button = options["button"] status = device.mouseEvent(path, int(x), int(y), button, "RELEASE") elif "mouse-absolute-motion" in options: x, y = options["mouse-absolute-motion"] status = device.mouseEvent(path, int(x), int(y), '', "ABSOLUTE_MOTION") elif "mouse-relative-motion" in options: x, y = options["mouse-relative-motion"] status = device.mouseEvent(path, int(x), int(y), '', "RELATIVE_MOTION") elif "key" in options: key = options["key"].upper() if key in constants.KEY_SYMS: key = constants.KEY_SYMS[key] elif len(key) == 1: key = ord(key) elif key.startswith("0X"): key = int(key, 16) else: key = int(key) if "modifiers" in options: modifiers = [ constants.KEY_CODES[mod] for mod in options["modifiers"] ] else: modifiers = [] status = device.keyboardEvent(path, key, modifiers) elif "dump" in options or "dump-all" in options: all = False if "dump" in options: depth = int(options["dump"]) else: depth = -1 if "output" in options: fn = options["output"] all = True obj = device.getAccessible(path, depth, all=all) if obj is None: exitWithStatus("There is no such path: %s" % path, 1) if all: printSeparator() utils.saveXml(obj.marshal(), fn) exitWithStatus("Dump saved to file: %s" % fn) else: printAccessibleTree(obj) exitWithStatus() else: for name in (["all"] + [attr[0] for attr in _ATTRS_EXTRA]): if name in options: break else: exitWithError("Invalid request options: %s" % options) obj = device.getAccessible(path, 0, **{name: True}) if obj is None: exitWithStatus("There is no such path: %s" % path, 1) printAccessibleDetails(obj, name) exitWithStatus() finally: if device.isConnected(): device.disconnect() printSeparator() if status: exitWithStatus("SUCCESS") else: exitWithStatus("FAILURE", 1)