From f981df65be5c937e1b36aad7fc5fd23d3b3569e1 Mon Sep 17 00:00:00 2001 From: Alexander Adler Date: Tue, 10 Sep 2019 10:06:28 +0000 Subject: [PATCH 1/3] Fixing async syntax for python 3.7 --- src/pytractor/mixins.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pytractor/mixins.py b/src/pytractor/mixins.py index 1c43288..e690222 100644 --- a/src/pytractor/mixins.py +++ b/src/pytractor/mixins.py @@ -75,14 +75,14 @@ def __init__(self, base_url='', root_element='body', script_timeout=10, self.set_script_timeout(script_timeout) def _execute_client_script(self, script_name, *args, **kwargs): - async = kwargs.pop('async', True) + is_async = kwargs.pop('is_async', True) file_name = '{}.js'.format(script_name) js_script = resource_string(__name__, '{}/{}'.format(CLIENT_SCRIPTS_DIR, file_name)) if js_script: js_script = js_script.decode('UTF-8') - if async: + if is_async: result = self.execute_async_script(js_script, *args) else: result = self.execute_script(js_script, *args) @@ -94,7 +94,7 @@ def wait_for_angular(self): else: return self._execute_client_script('waitForAngular', self._root_element, - async=True) + is_async=True) def execute(self, driver_command, params=None): # We also get called from WebElement methods/properties. @@ -131,13 +131,13 @@ def title(self): @angular_wait_required def location_abs_url(self): return self._execute_client_script('getLocationAbsUrl', - self._root_element, async=False) + self._root_element, is_async=False) @angular_wait_required def find_elements_by_repeater(self, descriptor, using=None): return self._execute_client_script('findAllRepeaterRows', descriptor, False, using, - async=False) + is_async=False) @angular_wait_required def find_element(self, *args, **kwargs): @@ -150,7 +150,7 @@ def find_elements(self, *args, **kwargs): @angular_wait_required def find_elements_by_binding(self, descriptor, using=None): elements = self._execute_client_script('findBindings', descriptor, - False, using, async=False) + False, using, is_async=False) return elements def find_element_by_binding(self, descriptor, using=None): @@ -176,7 +176,7 @@ def find_element_by_exact_binding(self, descriptor, using=None): @angular_wait_required def find_elements_by_exact_binding(self, descriptor, using=None): elements = self._execute_client_script('findBindings', descriptor, - True, using, async=False) + True, using, is_async=False) return elements def find_element_by_model(self, descriptor, using=None): @@ -192,7 +192,7 @@ def find_element_by_model(self, descriptor, using=None): @angular_wait_required def find_elements_by_model(self, descriptor, using=None): elements = self._execute_client_script('findByModel', descriptor, - using, async=False) + using, is_async=False) # Workaround for issue #10: findByModel.js returns None instead of empty # list if no element has been found. if elements is None: @@ -233,5 +233,5 @@ def refresh(self): @angular_wait_required def set_location(self, url): result = self._execute_client_script('setLocation', self._root_element, - url, async=False) + url, is_async=False) return result From 4e4557b5d05878842eb4fedb855d4731c68d6eed Mon Sep 17 00:00:00 2001 From: Alexander Adler Date: Wed, 11 Sep 2019 04:39:19 +0000 Subject: [PATCH 2/3] Fixing tests with async variable --- src/pytractor/tests/unit/test_mixins.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pytractor/tests/unit/test_mixins.py b/src/pytractor/tests/unit/test_mixins.py index 5674f92..d7ab357 100644 --- a/src/pytractor/tests/unit/test_mixins.py +++ b/src/pytractor/tests/unit/test_mixins.py @@ -108,7 +108,7 @@ def setUp(self): self.mock_root_element) @patch('pytractor.mixins.resource_string') - def verify__execute_client_script_call(self, async, mock_resource_string): + def verify__execute_client_script_call(self, is_async, mock_resource_string): with patch.multiple( self.instance, execute_async_script=DEFAULT, execute_script=DEFAULT, @@ -121,7 +121,7 @@ def verify__execute_client_script_call(self, async, mock_resource_string): 'execute_async_script')] mock_arg = MagicMock() result = self.instance._execute_client_script('SCRIPT', mock_arg, - async=async) + is_async=is_async) # the script was read correctly with resource_string() mock_resource_string.assert_called_once_with( 'pytractor.mixins', @@ -129,7 +129,7 @@ def verify__execute_client_script_call(self, async, mock_resource_string): ) # execute_async_script or execute_script were called (but not both) script_content = mock_resource_string.return_value.decode() - if async: + if is_async: mock_execute_async_script.assert_called_once_with(script_content, mock_arg) self.assertEqual(len(mock_execute_script.mock_calls), 0) @@ -164,7 +164,7 @@ def verify_function_executes_script_with(self, func_to_call, def test_wait_for_angular(self): self.verify_function_executes_script_with( self.instance.wait_for_angular, - 'waitForAngular', self.mock_root_element, async=True + 'waitForAngular', self.mock_root_element, is_async=True ) def test_wait_for_angular_does_not_call_script_if_ignore_synchronization( @@ -274,7 +274,7 @@ def test_find_elements_by_binding(self): mock_using) mock_methods['wait_for_angular'].assert_called_once_with() mock_methods['_execute_client_script'].assert_called_once_with( - 'findBindings', mock_descriptor, False, mock_using, async=False + 'findBindings', mock_descriptor, False, mock_using, is_async=False ) self.assertIs(result, mock_methods['_execute_client_script'].return_value) @@ -439,7 +439,7 @@ def test_find_elements_by_exact_binding_calls_protractor_script(self): mock_methods['wait_for_angular'].assert_called_once_with() mock_methods['_execute_client_script'].assert_called_once_with( - 'findBindings', mock_descriptor, True, mock_using, async=False + 'findBindings', mock_descriptor, True, mock_using, is_async=False ) self.assertIs(result, mock_methods['_execute_client_script'].return_value) @@ -486,7 +486,7 @@ def test_find_elements_by_model_calls_protractor_script(self): mock_methods['wait_for_angular'].assert_called_once_with() mock_methods['_execute_client_script'].assert_called_once_with( - 'findByModel', mock_descriptor, mock_using, async=False + 'findByModel', mock_descriptor, mock_using, is_async=False ) self.assertIs(result, mock_methods['_execute_client_script'].return_value) @@ -514,7 +514,7 @@ def test_location_abs_url_calls_protractor_script(self): mock_methods['wait_for_angular'].assert_called_once_with() mock_methods['_execute_client_script'].assert_called_once_with( - 'getLocationAbsUrl', self.instance._root_element, async=False + 'getLocationAbsUrl', self.instance._root_element, is_async=False ) self.assertIs(result, mock_methods['_execute_client_script'].return_value) @@ -529,7 +529,7 @@ def test_set_location_calls_protractor_script(self): mock_methods['wait_for_angular'].assert_called_once_with() mock_methods['_execute_client_script'].assert_called_once_with( - 'setLocation', self.instance._root_element, url, async=False + 'setLocation', self.instance._root_element, url, is_async=False ) self.assertIs(result, mock_methods['_execute_client_script'].return_value) From dda422f660f99141a5d25c01cb95b096a13507cc Mon Sep 17 00:00:00 2001 From: Alexander Adler Date: Wed, 11 Sep 2019 04:46:32 +0000 Subject: [PATCH 3/3] Adding python 3.7 to CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 224701e..b119649 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: python python: - "2.7" - "3.5" + - "3.7" # command to install dependencies install: - pip install .