MCPcopy Index your code
hub / github.com/RustPython/RustPython / assertCountEqual

Method assertCountEqual

Lib/unittest/case.py:1231–1261  ·  view source on GitHub ↗

Asserts that two iterables have the same elements, the same number of times, without regard to order. self.assertEqual(Counter(list(first)), Counter(list(second))) Example: - [0, 1, 1] and [1, 0, 1] compare equal. -

(self, first, second, msg=None)

Source from the content-addressed store, hash-verified

1229 self.fail(self._formatMessage(msg, standardMsg))
1230
1231 def assertCountEqual(self, first, second, msg=None):
1232 """Asserts that two iterables have the same elements, the same number of
1233 times, without regard to order.
1234
1235 self.assertEqual(Counter(list(first)),
1236 Counter(list(second)))
1237
1238 Example:
1239 - [0, 1, 1] and [1, 0, 1] compare equal.
1240 - [0, 0, 1] and [0, 1] compare unequal.
1241
1242 """
1243 first_seq, second_seq = list(first), list(second)
1244 try:
1245 first = collections.Counter(first_seq)
1246 second = collections.Counter(second_seq)
1247 except TypeError:
1248 # Handle case with unhashable elements
1249 differences = _count_diff_all_purpose(first_seq, second_seq)
1250 else:
1251 if first == second:
1252 return
1253 differences = _count_diff_hashable(first_seq, second_seq)
1254
1255 if differences:
1256 standardMsg = 'Element counts were not equal:\n'
1257 lines = ['First has %d, Second has %d: %r' % diff for diff in differences]
1258 diffMsg = '\n'.join(lines)
1259 standardMsg = self._truncateMessage(standardMsg, diffMsg)
1260 msg = self._formatMessage(msg, standardMsg)
1261 self.fail(msg)
1262
1263 def assertMultiLineEqual(self, first, second, msg=None):
1264 """Assert that two multi-line strings are equal."""

Callers 15

test_args_kwargsMethod · 0.95
test_allMethod · 0.80
test___all__Method · 0.80
test_allMethod · 0.80
globMethod · 0.80
test_make_tarfileMethod · 0.80
test_make_zipfileMethod · 0.80

Calls 7

_truncateMessageMethod · 0.95
_formatMessageMethod · 0.95
failMethod · 0.95
listClass · 0.85
_count_diff_all_purposeFunction · 0.85
_count_diff_hashableFunction · 0.85
joinMethod · 0.45

Tested by 15

test_args_kwargsMethod · 0.76
test_allMethod · 0.64
test___all__Method · 0.64
test_allMethod · 0.64
globMethod · 0.64
test_make_tarfileMethod · 0.64
test_make_zipfileMethod · 0.64