diff --git a/src/Selenium2Library/keywords/_runonfailure.py b/src/Selenium2Library/keywords/_runonfailure.py index 4e9057107..737e02f91 100644 --- a/src/Selenium2Library/keywords/_runonfailure.py +++ b/src/Selenium2Library/keywords/_runonfailure.py @@ -57,7 +57,7 @@ def _run_on_failure(self): self._running_on_failure_routine = True try: BUILTIN.run_keyword(self._run_on_failure_keyword) - except Exception, err: + except Exception as err: self._run_on_failure_error(err) finally: self._running_on_failure_routine = False diff --git a/src/Selenium2Library/keywords/_tableelement.py b/src/Selenium2Library/keywords/_tableelement.py index 55eea39c8..443f9eaa7 100644 --- a/src/Selenium2Library/keywords/_tableelement.py +++ b/src/Selenium2Library/keywords/_tableelement.py @@ -64,7 +64,7 @@ def table_cell_should_contain(self, table_locator, row, column, expected, loglev % (table_locator, row, column, expected)) try: content = self.get_table_cell(table_locator, row, column, loglevel='NONE') - except AssertionError, err: + except AssertionError as err: self._info(err) self.log_source(loglevel) raise AssertionError(message) diff --git a/src/Selenium2Library/keywords/keywordgroup.py b/src/Selenium2Library/keywords/keywordgroup.py index 672603afd..dab2af51d 100644 --- a/src/Selenium2Library/keywords/keywordgroup.py +++ b/src/Selenium2Library/keywords/keywordgroup.py @@ -13,7 +13,7 @@ def _run_on_failure_decorator(method, *args, **kwargs): self._already_in_keyword = True # Set a flag on the instance so that as we call keywords inside this call and this gets run again, we know we're at least one level in. try: return method(*args, **kwargs) - except Exception, err: + except Exception as err: if hasattr(self, '_run_on_failure') and not self._has_run_on_failure: # If we're in an inner keyword, track the fact that we've already run on failure once self._has_run_on_failure = True @@ -28,7 +28,7 @@ def _run_on_failure_decorator(method, *args, **kwargs): class KeywordGroupMetaClass(type): def __new__(cls, clsname, bases, dict): if decorator: - for name, method in dict.items(): + for name, method in list(dict.items()): if not name.startswith('_') and inspect.isroutine(method): dict[name] = decorator(_run_on_failure_decorator, method) return type.__new__(cls, clsname, bases, dict) diff --git a/src/Selenium2Library/locators/elementfinder.py b/src/Selenium2Library/locators/elementfinder.py index 041471370..81da96539 100644 --- a/src/Selenium2Library/locators/elementfinder.py +++ b/src/Selenium2Library/locators/elementfinder.py @@ -22,7 +22,7 @@ def __init__(self): 'default': self._find_by_default } self._strategies = NormalizedDict(initial=strategies, caseless=True, spaceless=True) - self._default_strategies = strategies.keys() + self._default_strategies = list(strategies.keys()) def find(self, browser, locator, tag=None): assert browser is not None @@ -190,9 +190,7 @@ def _element_matches(self, element, tag, constraints): def _filter_elements(self, elements, tag, constraints): elements = self._normalize_result(elements) if tag is None: return elements - return filter( - lambda element: self._element_matches(element, tag, constraints), - elements) + return [element for element in elements if self._element_matches(element, tag, constraints)] def _get_attrs_with_url(self, key_attrs, criteria, browser): attrs = [] diff --git a/test/lib/mockito/invocation.py b/test/lib/mockito/invocation.py index 067881b99..159a56863 100644 --- a/test/lib/mockito/invocation.py +++ b/test/lib/mockito/invocation.py @@ -47,14 +47,14 @@ def matches(self, invocation): return False if len(self.named_params) != len(invocation.named_params): return False - if self.named_params.keys() != invocation.named_params.keys(): + if list(self.named_params.keys()) != list(invocation.named_params.keys()): return False for x, p1 in enumerate(self.params): if not self.compare(p1, invocation.params[x]): return False - for x, p1 in self.named_params.iteritems(): + for x, p1 in self.named_params.items(): if not self.compare(p1, invocation.named_params[x]): return False diff --git a/test/lib/mockito/mock_registry.py b/test/lib/mockito/mock_registry.py index c7a0208f6..5b702e209 100644 --- a/test/lib/mockito/mock_registry.py +++ b/test/lib/mockito/mock_registry.py @@ -12,7 +12,7 @@ def mock_for(self, cls): return self.mocks.get(cls, None) def unstub_all(self): - for mock in self.mocks.itervalues(): + for mock in self.mocks.values(): mock.unstub() self.mocks.clear() diff --git a/test/lib/mockito/mockito.py b/test/lib/mockito/mockito.py index 30f188a4f..50f820021 100644 --- a/test/lib/mockito/mockito.py +++ b/test/lib/mockito/mockito.py @@ -15,7 +15,7 @@ class ArgumentError(Exception): pass def _multiple_arguments_in_use(*args): - return len(filter(lambda x: x, args)) > 1 + return len([x for x in args if x]) > 1 def _invalid_argument(value): return (value is not None and value < 1) or value == 0 diff --git a/test/resources/statuschecker.py b/test/resources/statuschecker.py index 20b6a849d..5af72b86c 100755 --- a/test/resources/statuschecker.py +++ b/test/resources/statuschecker.py @@ -177,14 +177,14 @@ def _get_log_message(self, msg_str): import os if not 2 <= len(sys.argv) <= 3 or '--help' in sys.argv: - print __doc__ + print(__doc__) sys.exit(1) infile = sys.argv[1] outfile = sys.argv[2] if len(sys.argv) == 3 else None - print "Checking %s" % os.path.abspath(infile) + print("Checking %s" % os.path.abspath(infile)) rc = process_output(infile, outfile) if outfile: - print "Output: %s" % os.path.abspath(outfile) + print("Output: %s" % os.path.abspath(outfile)) if rc > 255: rc = 255 sys.exit(rc) diff --git a/test/resources/testserver/testserver.py b/test/resources/testserver/testserver.py index 3d33a24ca..c67ca3c4a 100644 --- a/test/resources/testserver/testserver.py +++ b/test/resources/testserver/testserver.py @@ -94,7 +94,7 @@ def start_server(port=7000): if __name__ == '__main__': import sys if len(sys.argv) != 2 or sys.argv[1] not in [ 'start', 'stop' ]: - print 'usage: %s start|stop' % sys.argv[0] + print('usage: %s start|stop' % sys.argv[0]) sys.exit(1) if sys.argv[1] == 'start': start_server() diff --git a/test/run_tests.py b/test/run_tests.py index ac7f69c8c..673db64e6 100755 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -53,8 +53,8 @@ def execute_tests(runner, args): if not os.path.exists(env.RESULTS_DIR): os.mkdir(env.RESULTS_DIR) command = [runner] + [arg % ARG_VALUES for arg in ROBOT_ARGS] + args + [env.ACCEPTANCE_TEST_DIR] - print '' - print 'Starting test execution with command:\n' + ' '.join(command) + print('') + print('Starting test execution with command:\n' + ' '.join(command)) syslog = os.path.join(env.RESULTS_DIR, 'syslog.txt') call(command, shell=os.sep=='\\', env=dict(os.environ, ROBOT_SYSLOG_FILE=syslog)) @@ -62,20 +62,20 @@ def stop_http_server(): call(['python', env.HTTP_SERVER_FILE, 'stop']) def process_output(args): - print + print() if _has_robot_27(): call(['python', os.path.join(env.RESOURCES_DIR, 'statuschecker.py'), os.path.join(env.RESULTS_DIR, 'output.xml')]) rebot = 'rebot' if os.sep == '/' else 'rebot.bat' rebot_cmd = [rebot] + [ arg % ARG_VALUES for arg in REBOT_ARGS ] + args + \ [os.path.join(ARG_VALUES['outdir'], 'output.xml') ] - print '' - print 'Starting output processing with command:\n' + ' '.join(rebot_cmd) + print('') + print('Starting output processing with command:\n' + ' '.join(rebot_cmd)) rc = call(rebot_cmd, env=os.environ) if rc == 0: - print 'All critical tests passed' + print('All critical tests passed') else: - print '%d critical test%s failed' % (rc, 's' if rc != 1 else '') + print('%d critical test%s failed' % (rc, 's' if rc != 1 else '')) return rc def _has_robot_27(): @@ -89,18 +89,18 @@ def _exit(rc): sys.exit(rc) def _help(): - print 'Usage: python run_tests.py python|jython browser [options]' - print - print 'See README.txt for details.' + print('Usage: python run_tests.py python|jython browser [options]') + print() + print('See README.txt for details.') return 255 def _run_unit_tests(): - print 'Running unit tests' + print('Running unit tests') failures = run_unit_tests() if failures != 0: - print '\n%d unit tests failed - not running acceptance tests!' % failures + print('\n%d unit tests failed - not running acceptance tests!' % failures) else: - print 'All unit tests passed' + print('All unit tests passed') return failures diff --git a/test/run_unit_tests.py b/test/run_unit_tests.py index aa417c192..3b5a0399f 100755 --- a/test/run_unit_tests.py +++ b/test/run_unit_tests.py @@ -10,9 +10,9 @@ def run_unit_tests(modules_to_run=[]): bad_modules_to_run = [module_to_run for module_to_run in modules_to_run if module_to_run not in test_module_names] if bad_modules_to_run: - print "Specified test module%s not exist: %s" % ( + print("Specified test module%s not exist: %s" % ( ' does' if len(bad_modules_to_run) == 1 else 's do', - ', '.join(bad_modules_to_run)) + ', '.join(bad_modules_to_run))) return -1 tests = [unittest.defaultTestLoader.loadTestsFromModule(test_module) diff --git a/test/unit/keywords/test_browsermanagement.py b/test/unit/keywords/test_browsermanagement.py index fd6062c60..782491730 100644 --- a/test/unit/keywords/test_browsermanagement.py +++ b/test/unit/keywords/test_browsermanagement.py @@ -96,7 +96,7 @@ def test_bad_browser_name(self): try: bm._make_browser("fireox") self.fail("Exception not raised") - except ValueError, e: + except ValueError as e: self.assertEquals("fireox is not a supported browser.", e.message) def test_create_webdriver(self):