From 018e1b7aad8d1a33ee14aae5c466d581d31e2369 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=B6=E0=B1=8D?= =?utf8?q?=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF=E0=B0=B5=E0=B0=BE=E0=B0=B8?= =?utf8?q?=E0=B1=8D=20=E0=B0=B0=E0=B1=86=E0=B0=A1=E0=B1=8D=E0=B0=A1?= =?utf8?q?=E0=B0=BF=20=E0=B0=A4=E0=B0=BE=E0=B0=9F=E0=B0=BF=E0=B0=AA?= =?utf8?q?=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF=29?= Date: Wed, 24 Jan 2018 13:19:58 +0530 Subject: [PATCH] bpo-32360: unittest.util: Use Counter instead of custom count function (GH-4994) --- Lib/unittest/util.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Lib/unittest/util.py b/Lib/unittest/util.py index 45485dcb0d..050eaed0b3 100644 --- a/Lib/unittest/util.py +++ b/Lib/unittest/util.py @@ -1,6 +1,6 @@ """Various utility functions.""" -from collections import namedtuple, OrderedDict +from collections import namedtuple, Counter from os.path import commonprefix __unittest = True @@ -153,17 +153,10 @@ def _count_diff_all_purpose(actual, expected): result.append(diff) return result -def _ordered_count(iterable): - 'Return dict of element counts, in the order they were first seen' - c = OrderedDict() - for elem in iterable: - c[elem] = c.get(elem, 0) + 1 - return c - def _count_diff_hashable(actual, expected): 'Returns list of (cnt_act, cnt_exp, elem) triples where the counts differ' # elements must be hashable - s, t = _ordered_count(actual), _ordered_count(expected) + s, t = Counter(actual), Counter(expected) result = [] for elem, cnt_s in s.items(): cnt_t = t.get(elem, 0) -- 2.40.0