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

Delta Between Two Patch Sets: Lib/test/test_collections.py

Issue 26915: Test identity first in membership operation of ItemsView, ValuesView and Sequence in collections.abc
Left Patch Set: Created 3 years, 8 months ago
Right Patch Set: Created 3 years, 8 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/_collections_abc.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Unit tests for collections.py.""" 1 """Unit tests for collections.py."""
2 2
3 import collections 3 import collections
4 import copy 4 import copy
5 import doctest 5 import doctest
6 import inspect 6 import inspect
7 import keyword 7 import keyword
8 import operator 8 import operator
9 import pickle 9 import pickle
10 from random import choice, randrange 10 from random import choice, randrange
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 def test_issue26915(self): 1077 def test_issue26915(self):
1078 # Container membership test should check identity first 1078 # Container membership test should check identity first
1079 class CustomEqualObject: 1079 class CustomEqualObject:
1080 def __eq__(self, other): 1080 def __eq__(self, other):
1081 return False 1081 return False
1082 class CustomSequence(Sequence): 1082 class CustomSequence(Sequence):
1083 def __init__(self, seq): 1083 def __init__(self, seq):
1084 self._seq = seq 1084 self._seq = seq
1085 def __getitem__(self, index): 1085 def __getitem__(self, index):
1086 return self._seq[index] 1086 return self._seq[index]
1087 def __len__(self, index): 1087 def __len__(self):
1088 return len(self._seq) 1088 return len(self._seq)
1089 1089
1090 nan = float('nan') 1090 nan = float('nan')
1091 obj = CustomEqualObject() 1091 obj = CustomEqualObject()
1092 seq = CustomSequence([nan, obj, nan]) 1092 seq = CustomSequence([nan, obj, nan])
1093 containers = [ 1093 containers = [
1094 seq, 1094 seq,
1095 ItemsView({1: nan, 2: obj}), 1095 ItemsView({1: nan, 2: obj}),
1096 ValuesView({1: nan, 2: obj}) 1096 ValuesView({1: nan, 2: obj})
1097 ] 1097 ]
1098 for container in containers: 1098 for container in containers:
1099 for elem in container: 1099 for elem in container:
1100 self.assertIn(elem, container) 1100 self.assertIn(elem, container)
1101 self.assertEqual(seq.index(nan), 0) 1101 self.assertEqual(seq.index(nan), 0)
1102 self.assertNotEqual(seq.index(nan), 1) 1102 self.assertNotEqual(seq.index(nan), 1)
storchaka 2016/06/04 19:06:13 What the purpose of this test?
1103 self.assertEqual(seq.index(obj), 1) 1103 self.assertEqual(seq.index(obj), 1)
1104 self.assertEqual(seq.count(nan), 2) 1104 self.assertEqual(seq.count(nan), 2)
1105 self.assertEqual(seq.count(obj), 1) 1105 self.assertEqual(seq.count(obj), 1)
1106 1106
1107 def assertSameSet(self, s1, s2): 1107 def assertSameSet(self, s1, s2):
1108 # coerce both to a real set then check equality 1108 # coerce both to a real set then check equality
1109 self.assertSetEqual(set(s1), set(s2)) 1109 self.assertSetEqual(set(s1), set(s2))
1110 1110
1111 def test_Set_interoperability_with_real_sets(self): 1111 def test_Set_interoperability_with_real_sets(self):
1112 # Issue: 8743 1112 # Issue: 8743
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, 1686 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
1687 TestCollectionABCs, TestCounter, TestChainMap, 1687 TestCollectionABCs, TestCounter, TestChainMap,
1688 TestUserObjects, 1688 TestUserObjects,
1689 ] 1689 ]
1690 support.run_unittest(*test_classes) 1690 support.run_unittest(*test_classes)
1691 support.run_doctest(collections, verbose) 1691 support.run_doctest(collections, verbose)
1692 1692
1693 1693
1694 if __name__ == "__main__": 1694 if __name__ == "__main__":
1695 test_main(verbose=True) 1695 test_main(verbose=True)
LEFTRIGHT

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