summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-03-08 03:43:35 (GMT)
committerGitHub <noreply@github.com>2017-03-08 03:43:35 (GMT)
commit78ad039bcf1a8c494cbc8e18380cc30665869c3e (patch)
tree6827b8c0e0485c4de096b10e3592c880f2216de3 /Lib/test
parent23b26c4e206427a9e0a1d39240c17a049cf8c732 (diff)
downloadcpython-78ad039bcf1a8c494cbc8e18380cc30665869c3e.zip
cpython-78ad039bcf1a8c494cbc8e18380cc30665869c3e.tar.gz
cpython-78ad039bcf1a8c494cbc8e18380cc30665869c3e.tar.bz2
bpo-26915: Test identity first in index() and count() of collections.abc.Sequence (GH-553)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 87454cc..47f7562 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -1310,20 +1310,29 @@ class TestCollectionABCs(ABCTestCase):
class CustomEqualObject:
def __eq__(self, other):
return False
- class CustomSequence(list):
- def __contains__(self, value):
- return Sequence.__contains__(self, value)
+ class CustomSequence(Sequence):
+ def __init__(self, seq):
+ self._seq = seq
+ def __getitem__(self, index):
+ return self._seq[index]
+ def __len__(self):
+ return len(self._seq)
nan = float('nan')
obj = CustomEqualObject()
+ seq = CustomSequence([nan, obj, nan])
containers = [
- CustomSequence([nan, obj]),
+ seq,
ItemsView({1: nan, 2: obj}),
ValuesView({1: nan, 2: obj})
]
for container in containers:
for elem in container:
self.assertIn(elem, container)
+ self.assertEqual(seq.index(nan), 0)
+ self.assertEqual(seq.index(obj), 1)
+ self.assertEqual(seq.count(nan), 2)
+ self.assertEqual(seq.count(obj), 1)
def assertSameSet(self, s1, s2):
# coerce both to a real set then check equality