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

Method assertSetEqual

Lib/unittest/case.py:1149–1190  ·  view source on GitHub ↗

A set-specific equality assertion. Args: set1: The first set to compare. set2: The second set to compare. msg: Optional message to use on failure instead of a list of differences. assertSetEqual uses ducktyping to support diff

(self, set1, set2, msg=None)

Source from the content-addressed store, hash-verified

1147 self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
1148
1149 def assertSetEqual(self, set1, set2, msg=None):
1150 """A set-specific equality assertion.
1151
1152 Args:
1153 set1: The first set to compare.
1154 set2: The second set to compare.
1155 msg: Optional message to use on failure instead of a list of
1156 differences.
1157
1158 assertSetEqual uses ducktyping to support different types of sets, and
1159 is optimized for sets specifically (parameters must support a
1160 difference method).
1161 """
1162 try:
1163 difference1 = set1.difference(set2)
1164 except TypeError as e:
1165 self.fail('invalid type when attempting set difference: %s' % e)
1166 except AttributeError as e:
1167 self.fail('first argument does not support set difference: %s' % e)
1168
1169 try:
1170 difference2 = set2.difference(set1)
1171 except TypeError as e:
1172 self.fail('invalid type when attempting set difference: %s' % e)
1173 except AttributeError as e:
1174 self.fail('second argument does not support set difference: %s' % e)
1175
1176 if not (difference1 or difference2):
1177 return
1178
1179 lines = []
1180 if difference1:
1181 lines.append('Items in the first set but not the second:')
1182 for item in difference1:
1183 lines.append(repr(item))
1184 if difference2:
1185 lines.append('Items in the second set but not the first:')
1186 for item in difference2:
1187 lines.append(repr(item))
1188
1189 standardMsg = '\n'.join(lines)
1190 self.fail(self._formatMessage(msg, standardMsg))
1191
1192 def assertIn(self, member, container, msg=None):
1193 """Just like self.assertTrue(a in b), but with a nicer default message."""

Callers 15

_events_waitany_testMethod · 0.80
assertSameSetMethod · 0.80
test___all__Method · 0.80
test_uuid6_uniquenessMethod · 0.80
test_uuid7_uniquenessMethod · 0.80
test_uuid8_uniquenessMethod · 0.80
test_listdrivesMethod · 0.80
test_listvolumesMethod · 0.80
test_listmountsMethod · 0.80

Calls 6

failMethod · 0.95
_formatMessageMethod · 0.95
reprFunction · 0.85
differenceMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by 15

_events_waitany_testMethod · 0.64
assertSameSetMethod · 0.64
test___all__Method · 0.64
test_uuid6_uniquenessMethod · 0.64
test_uuid7_uniquenessMethod · 0.64
test_uuid8_uniquenessMethod · 0.64
test_listdrivesMethod · 0.64
test_listvolumesMethod · 0.64
test_listmountsMethod · 0.64