Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(154024)

Side by Side Diff: Lib/test/test_dictviews.py

Issue 28189: dictitems_contains swallows compare errors
Patch Set: Created 2 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Objects/dictobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import collections 1 import collections
2 import copy 2 import copy
3 import pickle 3 import pickle
4 import unittest 4 import unittest
5 5
6 class DictSetTest(unittest.TestCase): 6 class DictSetTest(unittest.TestCase):
7 7
8 def test_constructors_not_callable(self): 8 def test_constructors_not_callable(self):
9 kt = type({}.keys()) 9 kt = type({}.keys())
10 self.assertRaises(TypeError, kt, {}) 10 self.assertRaises(TypeError, kt, {})
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 212
213 def test_pickle(self): 213 def test_pickle(self):
214 d = {1: 10, "a": "ABC"} 214 d = {1: 10, "a": "ABC"}
215 for proto in range(pickle.HIGHEST_PROTOCOL + 1): 215 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
216 self.assertRaises((TypeError, pickle.PicklingError), 216 self.assertRaises((TypeError, pickle.PicklingError),
217 pickle.dumps, d.keys(), proto) 217 pickle.dumps, d.keys(), proto)
218 self.assertRaises((TypeError, pickle.PicklingError), 218 self.assertRaises((TypeError, pickle.PicklingError),
219 pickle.dumps, d.values(), proto) 219 pickle.dumps, d.values(), proto)
220 self.assertRaises((TypeError, pickle.PicklingError), 220 self.assertRaises((TypeError, pickle.PicklingError),
221 pickle.dumps, d.items(), proto) 221 pickle.dumps, d.items(), proto)
222
223 def test_compare_error(self):
224 class Exc(Exception): pass
225 class BadEq:
226 def __hash__(self):
227 return 7
228 def __eq__(self, other):
229 raise Exc
230
231 k1, k2 = BadEq(), BadEq()
232 v1, v2 = BadEq(), BadEq()
233 d = {k1: v1}
234
235 self.assertIn(k1, d)
236 self.assertIn(k1, d.keys())
237 self.assertIn(v1, d.values())
238 self.assertIn((k1, v1), d.items())
239
240 self.assertRaises(Exc, d.__contains__, k2)
241 self.assertRaises(Exc, d.keys().__contains__, k2)
242 self.assertRaises(Exc, d.items().__contains__, (k2, v1))
243 self.assertRaises(Exc, d.items().__contains__, (k1, v2))
244 with self.assertRaises(Exc):
245 v2 in d.values()
222 246
223 def test_abc_registry(self): 247 def test_abc_registry(self):
224 d = dict(a=1) 248 d = dict(a=1)
225 249
226 self.assertIsInstance(d.keys(), collections.KeysView) 250 self.assertIsInstance(d.keys(), collections.KeysView)
227 self.assertIsInstance(d.keys(), collections.MappingView) 251 self.assertIsInstance(d.keys(), collections.MappingView)
228 self.assertIsInstance(d.keys(), collections.Set) 252 self.assertIsInstance(d.keys(), collections.Set)
229 self.assertIsInstance(d.keys(), collections.Sized) 253 self.assertIsInstance(d.keys(), collections.Sized)
230 self.assertIsInstance(d.keys(), collections.Iterable) 254 self.assertIsInstance(d.keys(), collections.Iterable)
231 self.assertIsInstance(d.keys(), collections.Container) 255 self.assertIsInstance(d.keys(), collections.Container)
232 256
233 self.assertIsInstance(d.values(), collections.ValuesView) 257 self.assertIsInstance(d.values(), collections.ValuesView)
234 self.assertIsInstance(d.values(), collections.MappingView) 258 self.assertIsInstance(d.values(), collections.MappingView)
235 self.assertIsInstance(d.values(), collections.Sized) 259 self.assertIsInstance(d.values(), collections.Sized)
236 260
237 self.assertIsInstance(d.items(), collections.ItemsView) 261 self.assertIsInstance(d.items(), collections.ItemsView)
238 self.assertIsInstance(d.items(), collections.MappingView) 262 self.assertIsInstance(d.items(), collections.MappingView)
239 self.assertIsInstance(d.items(), collections.Set) 263 self.assertIsInstance(d.items(), collections.Set)
240 self.assertIsInstance(d.items(), collections.Sized) 264 self.assertIsInstance(d.items(), collections.Sized)
241 self.assertIsInstance(d.items(), collections.Iterable) 265 self.assertIsInstance(d.items(), collections.Iterable)
242 self.assertIsInstance(d.items(), collections.Container) 266 self.assertIsInstance(d.items(), collections.Container)
243 267
244 268
245 if __name__ == "__main__": 269 if __name__ == "__main__":
246 unittest.main() 270 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | Objects/dictobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+