@@ -90,9 +90,12 @@ def test_owners_setter(self):
9090 MEMBER = "user:phred@example.com"
9191 expected = set ([MEMBER ])
9292 policy = self ._make_one ()
93- with warnings . catch_warnings ():
94- warnings .simplefilter ( "always" )
93+
94+ with warnings .catch_warnings ( record = True ) as warned :
9595 policy .owners = [MEMBER ]
96+
97+ warning , = warned
98+ assert warning .category is DeprecationWarning
9699 assert policy [OWNER_ROLE ] == expected
97100
98101 def test_editors_getter (self ):
@@ -111,9 +114,12 @@ def test_editors_setter(self):
111114 MEMBER = "user:phred@example.com"
112115 expected = set ([MEMBER ])
113116 policy = self ._make_one ()
114- with warnings . catch_warnings ():
115- warnings .simplefilter ( "always" )
117+
118+ with warnings .catch_warnings ( record = True ) as warned :
116119 policy .editors = [MEMBER ]
120+
121+ warning , = warned
122+ assert warning .category is DeprecationWarning
117123 assert policy [EDITOR_ROLE ] == expected
118124
119125 def test_viewers_getter (self ):
@@ -132,9 +138,12 @@ def test_viewers_setter(self):
132138 MEMBER = "user:phred@example.com"
133139 expected = set ([MEMBER ])
134140 policy = self ._make_one ()
135- with warnings . catch_warnings ():
136- warnings .simplefilter ( "always" )
141+
142+ with warnings .catch_warnings ( record = True ) as warned :
137143 policy .viewers = [MEMBER ]
144+
145+ warning , = warned
146+ assert warning .category is DeprecationWarning
138147 assert policy [VIEWER_ROLE ] == expected
139148
140149 def test_user (self ):
@@ -240,17 +249,20 @@ def test_to_api_repr_binding_wo_members(self):
240249 assert policy .to_api_repr () == {}
241250
242251 def test_to_api_repr_binding_w_duplicates (self ):
252+ import warnings
243253 from google .api_core .iam import OWNER_ROLE
244254
245255 OWNER = "group:cloud-logs@google.com"
246256 policy = self ._make_one ()
247- policy .owners = [OWNER , OWNER ]
257+ with warnings .catch_warnings (record = True ):
258+ policy .owners = [OWNER , OWNER ]
248259 assert policy .to_api_repr () == {
249260 "bindings" : [{"role" : OWNER_ROLE , "members" : [OWNER ]}]
250261 }
251262
252263 def test_to_api_repr_full (self ):
253264 import operator
265+ import warnings
254266 from google .api_core .iam import OWNER_ROLE , EDITOR_ROLE , VIEWER_ROLE
255267
256268 OWNER1 = "group:cloud-logs@google.com"
@@ -265,9 +277,10 @@ def test_to_api_repr_full(self):
265277 {"role" : VIEWER_ROLE , "members" : [VIEWER1 , VIEWER2 ]},
266278 ]
267279 policy = self ._make_one ("DEADBEEF" , 17 )
268- policy .owners = [OWNER1 , OWNER2 ]
269- policy .editors = [EDITOR1 , EDITOR2 ]
270- policy .viewers = [VIEWER1 , VIEWER2 ]
280+ with warnings .catch_warnings (record = True ):
281+ policy .owners = [OWNER1 , OWNER2 ]
282+ policy .editors = [EDITOR1 , EDITOR2 ]
283+ policy .viewers = [VIEWER1 , VIEWER2 ]
271284 resource = policy .to_api_repr ()
272285 assert resource ["etag" ] == "DEADBEEF"
273286 assert resource ["version" ] == 17
0 commit comments