diff options
author | masklinn <github.com@masklinn.net> | 2020-12-19 04:33:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 04:33:36 (GMT) |
commit | 1e27b57dbc8c1b758e37a531487813aef2d111ca (patch) | |
tree | 4f7b7740e4f6739e9c053a5369f56ae2e8e9b05e /Lib/test/test_random.py | |
parent | e0096124768f5d06b78cec977d9c37f27c5eab5f (diff) | |
download | cpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.zip cpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.tar.gz cpython-1e27b57dbc8c1b758e37a531487813aef2d111ca.tar.bz2 |
bpo-42470: Do not warn on sequences which are also sets in random.sample() (GH-23665)
Diffstat (limited to 'Lib/test/test_random.py')
-rw-r--r-- | Lib/test/test_random.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 0c1fdee..327bfa3 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -11,7 +11,7 @@ from functools import partial from math import log, exp, pi, fsum, sin, factorial from test import support from fractions import Fraction -from collections import Counter +from collections import abc, Counter class TestBasicOps: # Superclass with tests common to all generators. @@ -163,6 +163,22 @@ class TestBasicOps: population = {10, 20, 30, 40, 50, 60, 70} self.gen.sample(population, k=5) + def test_sample_on_seqsets(self): + class SeqSet(abc.Sequence, abc.Set): + def __init__(self, items): + self._items = items + + def __len__(self): + return len(self._items) + + def __getitem__(self, index): + return self._items[index] + + population = SeqSet([2, 4, 1, 3]) + with warnings.catch_warnings(): + warnings.simplefilter("error", DeprecationWarning) + self.gen.sample(population, k=2) + def test_sample_with_counts(self): sample = self.gen.sample |