Skip to content

Commit

Permalink
API Core: fix pytype build (#6873)
Browse files Browse the repository at this point in the history
* Run 'pytype' only over the 'google/' directory.

* Ignore 'pytype_output/' derived files.

* Remove spurious 'MutableMapping.register' call.

'pytype' chokes on it, but the 'Policy' class already derives from
'MutableMapping', so the call is a no-op.

* Silence deprecation spew during IAM unit tests.
  • Loading branch information
tseaver authored Dec 7, 2018
1 parent 7a15ffc commit 143b042
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ generated_python/
cloud-bigtable-client/
googleapis-pb/
grpc_python_venv/
pytype_output/
3 changes: 0 additions & 3 deletions api_core/google/api_core/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,3 @@ def to_api_repr(self):
del resource["bindings"]

return resource


collections_abc.MutableMapping.register(Policy)
2 changes: 1 addition & 1 deletion api_core/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ universal = 1
[pytype]
python_version = 3.6
inputs =
.
google/
exclude =
tests/
33 changes: 23 additions & 10 deletions api_core/tests/unit/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 143b042

Please sign in to comment.