From 011708215249d40acd0ddb2e04e416a07dd5f73b Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 6 May 2022 10:57:31 +0000 Subject: [PATCH 1/4] chore: remove unused variables --- describe.py | 3 +-- googleapiclient/discovery.py | 4 ++-- samples/coordinate/coordinate.py | 2 +- tests/test__auth.py | 4 ++-- tests/test_discovery.py | 34 ++++++++++++++++---------------- tests/test_http.py | 6 +++--- tests/test_mocks.py | 4 +--- 7 files changed, 27 insertions(+), 30 deletions(-) diff --git a/describe.py b/describe.py index 506e251dd04..384c6d0469f 100755 --- a/describe.py +++ b/describe.py @@ -307,7 +307,7 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS): """ collections = [] methods = [] - resource_name = path.split(".")[-2] + path.split(".")[-2] html = [ "", css, @@ -347,7 +347,6 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS): if methods: html.append("

Method Details

") for name in methods: - dname = name.rsplit("_")[0] html.append(method(name, getattr(resource, name).__doc__)) html.append("") diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py index c4d0eadb719..f8f866e38fe 100644 --- a/googleapiclient/discovery.py +++ b/googleapiclient/discovery.py @@ -427,8 +427,8 @@ def _retrieve_discovery_doc( pass try: - service = json.loads(content) - except ValueError as e: + json.loads(content) + except ValueError: logger.error("Failed to parse as JSON: " + content) raise InvalidJsonError() if cache_discovery and cache: diff --git a/samples/coordinate/coordinate.py b/samples/coordinate/coordinate.py index e569e3f00bf..75cc072dfa1 100644 --- a/samples/coordinate/coordinate.py +++ b/samples/coordinate/coordinate.py @@ -94,7 +94,7 @@ def main(argv): pprint.pprint(update_result) - except client.AccessTokenRefreshError as e: + except client.AccessTokenRefreshError: print ('The credentials have been revoked or expired, please re-run' 'the application to re-authorize') diff --git a/tests/test__auth.py b/tests/test__auth.py index 6809647b785..8d28361433a 100644 --- a/tests/test__auth.py +++ b/tests/test__auth.py @@ -128,11 +128,11 @@ def test_default_credentials(self): def test_credentials_from_file(self): with self.assertRaises(EnvironmentError): - credentials = _auth.credentials_from_file("credentials.json") + _auth.credentials_from_file("credentials.json") def test_default_credentials_with_scopes_and_quota_project(self): with self.assertRaises(EnvironmentError): - credentials = _auth.default_credentials( + _auth.default_credentials( scopes=["1", "2"], quota_project_id="my-project" ) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 63d1a71b0c0..643b6658fdb 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -243,7 +243,7 @@ def test_fix_up_parameters_optional_body(self): dummy_schema = {"Request": {"properties": {}}} method_desc = {"request": {"$ref": "Request"}} - parameters = _fix_up_parameters(method_desc, {}, "POST", dummy_schema) + _fix_up_parameters(method_desc, {}, "POST", dummy_schema) def _base_fix_up_method_description_test( self, @@ -440,14 +440,14 @@ def test_ResourceMethodParameters_zoo_animals_patch(self): class Discovery(unittest.TestCase): def test_discovery_http_is_closed(self): http = HttpMock(datafile("malformed.json"), {"status": "200"}) - service = build("plus", "v1", credentials=mock.sentinel.credentials) + build("plus", "v1", credentials=mock.sentinel.credentials) http.close.assert_called_once() class DiscoveryErrors(unittest.TestCase): def test_tests_should_be_run_with_strict_positional_enforcement(self): try: - plus = build("plus", "v1", None, static_discovery=False) + build("plus", "v1", None, static_discovery=False) self.fail("should have raised a TypeError exception over missing http=.") except TypeError: pass @@ -455,7 +455,7 @@ def test_tests_should_be_run_with_strict_positional_enforcement(self): def test_failed_to_parse_discovery_json(self): self.http = HttpMock(datafile("malformed.json"), {"status": "200"}) try: - plus = build( + build( "plus", "v1", http=self.http, @@ -474,7 +474,7 @@ def test_unknown_api_name_or_version(self): ] ) with self.assertRaises(UnknownApiNameOrVersion): - plus = build("plus", "v1", http=http, cache_discovery=False) + build("plus", "v1", http=http, cache_discovery=False) def test_credentials_and_http_mutually_exclusive(self): http = HttpMock(datafile("plus.json"), {"status": "200"}) @@ -603,7 +603,7 @@ def test_building_with_context_manager(self): ) as plus: self.assertIsNotNone(plus) self.assertTrue(hasattr(plus, "activities")) - plus._http.http.close.assert_called_once() + http.close.assert_called_once() def test_resource_close(self): discovery = read_datafile("plus.json") @@ -668,7 +668,7 @@ def test_scopes_from_client_options(self): discovery = read_datafile("plus.json") with mock.patch("googleapiclient._auth.default_credentials") as default: - plus = build_from_document( + build_from_document( discovery, client_options={"scopes": ["1", "2"]}, ) @@ -679,7 +679,7 @@ def test_quota_project_from_client_options(self): discovery = read_datafile("plus.json") with mock.patch("googleapiclient._auth.default_credentials") as default: - plus = build_from_document( + build_from_document( discovery, client_options=google.api_core.client_options.ClientOptions( quota_project_id="my-project" @@ -692,7 +692,7 @@ def test_credentials_file_from_client_options(self): discovery = read_datafile("plus.json") with mock.patch("googleapiclient._auth.credentials_from_file") as default: - plus = build_from_document( + build_from_document( discovery, client_options=google.api_core.client_options.ClientOptions( credentials_file="credentials.json" @@ -977,7 +977,7 @@ def test_userip_is_added_to_discovery_uri(self): http = HttpMockSequence( [({"status": "400"}, read_datafile("zoo.json", "rb"))] ) - zoo = build( + build( "zoo", "v1", http=http, @@ -995,7 +995,7 @@ def test_userip_missing_is_not_added_to_discovery_uri(self): http = HttpMockSequence( [({"status": "400"}, read_datafile("zoo.json", "rb"))] ) - zoo = build( + build( "zoo", "v1", http=http, @@ -1013,7 +1013,7 @@ def test_key_is_added_to_discovery_uri(self): http = HttpMockSequence( [({"status": "400"}, read_datafile("zoo.json", "rb"))] ) - zoo = build( + build( "zoo", "v1", http=http, @@ -1232,7 +1232,7 @@ def import_mock(name, *args, **kwargs): self.mocked_api.memcache.get.return_value = None - plus = build("plus", "v1", http=self.http, static_discovery=False) + build("plus", "v1", http=self.http, static_discovery=False) # memcache.get is called once url = "https://www.googleapis.com/discovery/v1/apis/plus/v1/rest" @@ -1253,7 +1253,7 @@ def import_mock(name, *args, **kwargs): # (Otherwise it should through an error) self.http = HttpMock(None, {"status": "200"}) - plus = build("plus", "v1", http=self.http, static_discovery=False) + build("plus", "v1", http=self.http, static_discovery=False) # memcache.get is called twice self.mocked_api.memcache.get.assert_has_calls( @@ -1312,7 +1312,7 @@ def test_file_based_cache(self): ): self.http = HttpMock(datafile("plus.json"), {"status": "200"}) - plus = build("plus", "v1", http=self.http, static_discovery=False) + build("plus", "v1", http=self.http, static_discovery=False) # cache.get is called once url = "https://www.googleapis.com/discovery/v1/apis/plus/v1/rest" @@ -1329,7 +1329,7 @@ def test_file_based_cache(self): # (Otherwise it should through an error) self.http = HttpMock(None, {"status": "200"}) - plus = build("plus", "v1", http=self.http, static_discovery=False) + build("plus", "v1", http=self.http, static_discovery=False) # cache.get is called twice cache.get.assert_has_calls([mock.call(url), mock.call(url)]) @@ -1951,7 +1951,7 @@ def test_media_io_base_stream_chunksize_resume(self): ) try: - body = request.execute(http=http) + request.execute(http=http) except HttpError as e: self.assertEqual(b"01234", e.content) diff --git a/tests/test_http.py b/tests/test_http.py index 3233f668ce7..194238843e3 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -323,7 +323,7 @@ def test_media_io_base_upload_serializable(self): upload = MediaIoBaseUpload(fd=f, mimetype="image/png") try: - json = upload.to_json() + upload.to_json() self.fail("MediaIoBaseUpload should not be serializable.") except NotImplementedError: pass @@ -960,7 +960,7 @@ def test_no_retry_connection_errors(self): request._sleep = lambda _x: 0 # do nothing request._rand = lambda: 10 with self.assertRaises(OSError): - response = request.execute(num_retries=3) + request.execute(num_retries=3) def test_retry_connection_errors_non_resumable(self): model = JsonModel() @@ -1238,7 +1238,7 @@ def test_serialize_request_media_body(self): resumable=None, ) # Just testing it shouldn't raise an exception. - s = batch._serialize_request(request).splitlines() + batch._serialize_request(request).splitlines() def test_serialize_request_no_body(self): batch = BatchHttpRequest() diff --git a/tests/test_mocks.py b/tests/test_mocks.py index 1f542b594c4..29c9db75ea4 100644 --- a/tests/test_mocks.py +++ b/tests/test_mocks.py @@ -203,9 +203,7 @@ def test_errors(self): ) try: - activity = ( - plus.activities().list(collection="public", userId="me").execute() - ) + plus.activities().list(collection="public", userId="me").execute() self.fail("An exception should have been thrown") except HttpError as e: self.assertEqual(b"{}", e.content) From 9f40503feec79669b283a48fffaa497fa54c92a5 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 6 May 2022 11:01:22 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20po?= =?UTF-8?q?st-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- tests/test__auth.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test__auth.py b/tests/test__auth.py index 8d28361433a..bda822b87e3 100644 --- a/tests/test__auth.py +++ b/tests/test__auth.py @@ -132,9 +132,7 @@ def test_credentials_from_file(self): def test_default_credentials_with_scopes_and_quota_project(self): with self.assertRaises(EnvironmentError): - _auth.default_credentials( - scopes=["1", "2"], quota_project_id="my-project" - ) + _auth.default_credentials(scopes=["1", "2"], quota_project_id="my-project") def test_with_scopes_non_scoped(self): credentials = mock.Mock(spec=oauth2client.client.Credentials) From 1c4bfb2a1ad7196aad42d25236d785878b9d00f8 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 6 May 2022 10:25:26 -0400 Subject: [PATCH 3/4] address review feedback Co-authored-by: Maciej Strzelczyk --- describe.py | 1 - 1 file changed, 1 deletion(-) diff --git a/describe.py b/describe.py index 384c6d0469f..4807774d711 100755 --- a/describe.py +++ b/describe.py @@ -307,7 +307,6 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS): """ collections = [] methods = [] - path.split(".")[-2] html = [ "", css, From d7653b0c8c09fe1be80c1233570496fd10e5cce6 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 6 May 2022 15:47:06 +0000 Subject: [PATCH 4/4] fix tests --- tests/test_discovery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_discovery.py b/tests/test_discovery.py index 643b6658fdb..2484efdd3b2 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -595,7 +595,7 @@ def test_building_with_developer_key_skips_adc(self): def test_building_with_context_manager(self): discovery = read_datafile("plus.json") - with mock.patch("httplib2.Http") as http: + with mock.patch("httplib2.Http"): with build_from_document( discovery, base="https://www.googleapis.com/", @@ -603,7 +603,7 @@ def test_building_with_context_manager(self): ) as plus: self.assertIsNotNone(plus) self.assertTrue(hasattr(plus, "activities")) - http.close.assert_called_once() + plus._http.http.close.assert_called_once() def test_resource_close(self): discovery = read_datafile("plus.json")