Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
"<html><body>",
css,
Expand Down Expand Up @@ -347,7 +347,6 @@ def document_collection(resource, path, root_discovery, discovery, css=CSS):
if methods:
html.append("<h3>Method Details</h3>")
for name in methods:
dname = name.rsplit("_")[0]
html.append(method(name, getattr(resource, name).__doc__))

html.append("</body></html>")
Expand Down
4 changes: 2 additions & 2 deletions googleapiclient/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion samples/coordinate/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
6 changes: 2 additions & 4 deletions tests/test__auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +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(
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)
Expand Down
34 changes: 17 additions & 17 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -440,22 +440,22 @@ 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

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,
Expand All @@ -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"})
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"]},
)
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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)])
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions tests/test_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down