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

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

Issue 26915: Test identity first in membership operation of ItemsView, ValuesView and Sequence in collections.abc
Patch Set: Created 3 years, 9 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 | « Lib/_collections_abc.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(list):
1083 def __contains__(self, value): 1083 def __contains__(self, value):
1084 return Sequence.__contains__(self, value) 1084 return Sequence.__contains__(self, value)
1085 def index(self, value, start=0, stop=None):
1086 return Sequence.index(self, value, start, stop)
1087 def count(self, value):
1088 return Sequence.count(self, value)
1085 1089
1086 nan = float('nan') 1090 nan = float('nan')
1087 obj = CustomEqualObject() 1091 obj = CustomEqualObject()
1088 containers = [ 1092 seq = CustomSequence([nan, obj, nan])
1089 CustomSequence([nan, obj]), 1093 containers = [seq, ItemsView({1: nan, 2: obj}), ValuesView({1: nan, 2: o bj})]
storchaka 2016/06/03 20:06:20 Line is too long.
1090 ItemsView({1: nan, 2: obj}),
1091 ValuesView({1: nan, 2: obj})
1092 ]
1093 for container in containers: 1094 for container in containers:
1094 for elem in container: 1095 for elem in container:
1095 self.assertIn(elem, container) 1096 self.assertIn(elem, container)
1097 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)
1098 self.assertEqual(seq.index(obj), 1)
1099 self.assertEqual(seq.count(nan), 2)
1100 self.assertEqual(seq.count(obj), 1)
1096 1101
1097 def assertSameSet(self, s1, s2): 1102 def assertSameSet(self, s1, s2):
1098 # coerce both to a real set then check equality 1103 # coerce both to a real set then check equality
1099 self.assertSetEqual(set(s1), set(s2)) 1104 self.assertSetEqual(set(s1), set(s2))
1100 1105
1101 def test_Set_interoperability_with_real_sets(self): 1106 def test_Set_interoperability_with_real_sets(self):
1102 # Issue: 8743 1107 # Issue: 8743
1103 class ListSet(Set): 1108 class ListSet(Set):
1104 def __init__(self, elements=()): 1109 def __init__(self, elements=()):
1105 self.data = [] 1110 self.data = []
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, 1681 test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs,
1677 TestCollectionABCs, TestCounter, TestChainMap, 1682 TestCollectionABCs, TestCounter, TestChainMap,
1678 TestUserObjects, 1683 TestUserObjects,
1679 ] 1684 ]
1680 support.run_unittest(*test_classes) 1685 support.run_unittest(*test_classes)
1681 support.run_doctest(collections, verbose) 1686 support.run_doctest(collections, verbose)
1682 1687
1683 1688
1684 if __name__ == "__main__": 1689 if __name__ == "__main__":
1685 test_main(verbose=True) 1690 test_main(verbose=True)
OLDNEW
« no previous file with comments | « Lib/_collections_abc.py ('k') | no next file » | no next file with comments »

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