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

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, 9 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 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 self.assertFalse(ncs < cs) 1072 self.assertFalse(ncs < cs)
1073 self.assertTrue(ncs <= cs) 1073 self.assertTrue(ncs <= cs)
1074 self.assertFalse(ncs > cs) 1074 self.assertFalse(ncs > cs)
1075 self.assertTrue(ncs >= cs) 1075 self.assertTrue(ncs >= cs)
1076 1076
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(list): 1082 class CustomSequence(Sequence):
1083 def __contains__(self, value): 1083 def __init__(self, seq):
1084 return Sequence.__contains__(self, value) 1084 self._seq = seq
1085 def index(self, value, start=0, stop=None): 1085 def __getitem__(self, index):
1086 return Sequence.index(self, value, start, stop) 1086 return self._seq[index]
1087 def count(self, value): 1087 def __len__(self):
1088 return Sequence.count(self, value) 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 = [seq, ItemsView({1: nan, 2: obj}), ValuesView({1: nan, 2: o bj})] 1093 containers = [
storchaka 2016/06/03 20:06:20 Line is too long.
1094 seq,
1095 ItemsView({1: nan, 2: obj}),
1096 ValuesView({1: nan, 2: obj})
1097 ]
1094 for container in containers: 1098 for container in containers:
1095 for elem in container: 1099 for elem in container:
1096 self.assertIn(elem, container) 1100 self.assertIn(elem, container)
1097 self.assertEqual(seq.index(nan), 0) 1101 self.assertEqual(seq.index(nan), 0)
storchaka 2016/06/03 20:06:20 Would be worth to add a test for seq.index(nan, 1)
1102 self.assertNotEqual(seq.index(nan), 1)
storchaka 2016/06/04 19:06:13 What the purpose of this test?
1098 self.assertEqual(seq.index(obj), 1) 1103 self.assertEqual(seq.index(obj), 1)
1099 self.assertEqual(seq.count(nan), 2) 1104 self.assertEqual(seq.count(nan), 2)
1100 self.assertEqual(seq.count(obj), 1) 1105 self.assertEqual(seq.count(obj), 1)
1101 1106
1102 def assertSameSet(self, s1, s2): 1107 def assertSameSet(self, s1, s2):
1103 # coerce both to a real set then check equality 1108 # coerce both to a real set then check equality
1104 self.assertSetEqual(set(s1), set(s2)) 1109 self.assertSetEqual(set(s1), set(s2))
1105 1110
1106 def test_Set_interoperability_with_real_sets(self): 1111 def test_Set_interoperability_with_real_sets(self):
1107 # Issue: 8743 1112 # Issue: 8743
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, 1686 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
1682 TestCollectionABCs, TestCounter, TestChainMap, 1687 TestCollectionABCs, TestCounter, TestChainMap,
1683 TestUserObjects, 1688 TestUserObjects,
1684 ] 1689 ]
1685 support.run_unittest(*test_classes) 1690 support.run_unittest(*test_classes)
1686 support.run_doctest(collections, verbose) 1691 support.run_doctest(collections, verbose)
1687 1692
1688 1693
1689 if __name__ == "__main__": 1694 if __name__ == "__main__":
1690 test_main(verbose=True) 1695 test_main(verbose=True)
LEFTRIGHT

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