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

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 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 def __lt__(self, x): 1067 def __lt__(self, x):
1068 return NotImplemented 1068 return NotImplemented
1069 1069
1070 cs = MyComparableSet() 1070 cs = MyComparableSet()
1071 ncs = MyNonComparableSet() 1071 ncs = MyNonComparableSet()
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_issue(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 __getitem__(self, index):
1086 return self._seq[index]
1087 def __len__(self):
1088 return len(self._seq)
1085 1089
1086 nan = float('nan') 1090 nan = float('nan')
1087 obj = CustomEqualObject() 1091 obj = CustomEqualObject()
1092 seq = CustomSequence([nan, obj, nan])
1088 containers = [ 1093 containers = [
1089 CustomSequence([nan, obj]), 1094 seq,
1090 ItemsView({1: nan, 2: obj}), 1095 ItemsView({1: nan, 2: obj}),
1091 ValuesView({1: nan, 2: obj}) 1096 ValuesView({1: nan, 2: obj})
1092 ] 1097 ]
1093 for container in containers: 1098 for container in containers:
1094 for elem in container: 1099 for elem in container:
1095 self.assertIn(elem, container) 1100 self.assertIn(elem, container)
1101 self.assertEqual(seq.index(nan), 0)
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)
1104 self.assertEqual(seq.count(nan), 2)
1105 self.assertEqual(seq.count(obj), 1)
1096 1106
1097 def assertSameSet(self, s1, s2): 1107 def assertSameSet(self, s1, s2):
1098 # coerce both to a real set then check equality 1108 # coerce both to a real set then check equality
1099 self.assertSetEqual(set(s1), set(s2)) 1109 self.assertSetEqual(set(s1), set(s2))
1100 1110
1101 def test_Set_interoperability_with_real_sets(self): 1111 def test_Set_interoperability_with_real_sets(self):
1102 # Issue: 8743 1112 # Issue: 8743
1103 class ListSet(Set): 1113 class ListSet(Set):
1104 def __init__(self, elements=()): 1114 def __init__(self, elements=()):
1105 self.data = [] 1115 self.data = []
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, 1686 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
1677 TestCollectionABCs, TestCounter, TestChainMap, 1687 TestCollectionABCs, TestCounter, TestChainMap,
1678 TestUserObjects, 1688 TestUserObjects,
1679 ] 1689 ]
1680 support.run_unittest(*test_classes) 1690 support.run_unittest(*test_classes)
1681 support.run_doctest(collections, verbose) 1691 support.run_doctest(collections, verbose)
1682 1692
1683 1693
1684 if __name__ == "__main__": 1694 if __name__ == "__main__":
1685 test_main(verbose=True) 1695 test_main(verbose=True)
LEFTRIGHT

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