bpo-45852: Fix the Counter/iter test for statistics.mode() (GH-29667) (GH-29671)

Suggested by Stefan Pochmann.
(cherry picked from commit 48744db70e)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2021-11-20 16:27:44 -08:00 committed by GitHub
parent cf8c8788c9
commit 9841ac2da5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -1897,10 +1897,13 @@ def test_none_data(self):
def test_counter_data(self):
# Test that a Counter is treated like any other iterable.
data = collections.Counter([1, 1, 1, 2])
# Since the keys of the counter are treated as data points, not the
# counts, this should return the first mode encountered, 1
self.assertEqual(self.func(data), 1)
# We're making sure mode() first calls iter() on its input.
# The concern is that a Counter of a Counter returns the original
# unchanged rather than counting its keys.
c = collections.Counter(a=1, b=2)
# If iter() is called, mode(c) loops over the keys, ['a', 'b'],
# all the counts will be 1, and the first encountered mode is 'a'.
self.assertEqual(self.func(c), 'a')
class TestMultiMode(unittest.TestCase):