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/ 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) 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/ 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