From 750b084c3c381c4943c4403bb3a1bc24c4e5fe1e Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 7 Dec 2018 10:25:05 -0500 Subject: [PATCH 1/4] Run 'pytype' only over the 'google/' directory. --- api_core/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_core/setup.cfg b/api_core/setup.cfg index 046436b8c99f..973b9433355e 100644 --- a/api_core/setup.cfg +++ b/api_core/setup.cfg @@ -4,6 +4,6 @@ universal = 1 [pytype] python_version = 3.6 inputs = - . + google/ exclude = tests/ From f4ca70730ba888e9acb6a93083659c8820d28cc3 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 7 Dec 2018 10:26:01 -0500 Subject: [PATCH 2/4] Ignore 'pytype_output/' derived files. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a769e15e9823..97c4071c0a3f 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,4 @@ generated_python/ cloud-bigtable-client/ googleapis-pb/ grpc_python_venv/ +pytype_output/ From 40388b924a18e8df49eb02129933b503d008e0eb Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 7 Dec 2018 10:26:57 -0500 Subject: [PATCH 3/4] Remove spurious 'MutableMapping.register' call. 'pytype' chokes on it, but the 'Policy' class already derives from 'MutableMapping', so the call is a no-op. --- api_core/google/api_core/iam.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/api_core/google/api_core/iam.py b/api_core/google/api_core/iam.py index c17bddcd9dfd..446f1944e453 100644 --- a/api_core/google/api_core/iam.py +++ b/api_core/google/api_core/iam.py @@ -243,6 +243,3 @@ def to_api_repr(self): del resource["bindings"] return resource - - -collections_abc.MutableMapping.register(Policy) From 85befc487524420550c7e5954d39135de36cbbb7 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 7 Dec 2018 10:37:28 -0500 Subject: [PATCH 4/4] Silence deprecation spew during IAM unit tests. --- api_core/tests/unit/test_iam.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/api_core/tests/unit/test_iam.py b/api_core/tests/unit/test_iam.py index 59f3b2c8a309..199c38907983 100644 --- a/api_core/tests/unit/test_iam.py +++ b/api_core/tests/unit/test_iam.py @@ -90,9 +90,12 @@ def test_owners_setter(self): MEMBER = "user:phred@example.com" expected = set([MEMBER]) policy = self._make_one() - with warnings.catch_warnings(): - warnings.simplefilter("always") + + with warnings.catch_warnings(record=True) as warned: policy.owners = [MEMBER] + + warning, = warned + assert warning.category is DeprecationWarning assert policy[OWNER_ROLE] == expected def test_editors_getter(self): @@ -111,9 +114,12 @@ def test_editors_setter(self): MEMBER = "user:phred@example.com" expected = set([MEMBER]) policy = self._make_one() - with warnings.catch_warnings(): - warnings.simplefilter("always") + + with warnings.catch_warnings(record=True) as warned: policy.editors = [MEMBER] + + warning, = warned + assert warning.category is DeprecationWarning assert policy[EDITOR_ROLE] == expected def test_viewers_getter(self): @@ -132,9 +138,12 @@ def test_viewers_setter(self): MEMBER = "user:phred@example.com" expected = set([MEMBER]) policy = self._make_one() - with warnings.catch_warnings(): - warnings.simplefilter("always") + + with warnings.catch_warnings(record=True) as warned: policy.viewers = [MEMBER] + + warning, = warned + assert warning.category is DeprecationWarning assert policy[VIEWER_ROLE] == expected def test_user(self): @@ -240,17 +249,20 @@ def test_to_api_repr_binding_wo_members(self): assert policy.to_api_repr() == {} def test_to_api_repr_binding_w_duplicates(self): + import warnings from google.api_core.iam import OWNER_ROLE OWNER = "group:cloud-logs@google.com" policy = self._make_one() - policy.owners = [OWNER, OWNER] + with warnings.catch_warnings(record=True): + policy.owners = [OWNER, OWNER] assert policy.to_api_repr() == { "bindings": [{"role": OWNER_ROLE, "members": [OWNER]}] } def test_to_api_repr_full(self): import operator + import warnings from google.api_core.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE OWNER1 = "group:cloud-logs@google.com" @@ -265,9 +277,10 @@ def test_to_api_repr_full(self): {"role": VIEWER_ROLE, "members": [VIEWER1, VIEWER2]}, ] policy = self._make_one("DEADBEEF", 17) - policy.owners = [OWNER1, OWNER2] - policy.editors = [EDITOR1, EDITOR2] - policy.viewers = [VIEWER1, VIEWER2] + with warnings.catch_warnings(record=True): + policy.owners = [OWNER1, OWNER2] + policy.editors = [EDITOR1, EDITOR2] + policy.viewers = [VIEWER1, VIEWER2] resource = policy.to_api_repr() assert resource["etag"] == "DEADBEEF" assert resource["version"] == 17