MCPcopy Index your code
hub / github.com/python/cpython / assertSequenceEqual

Method assertSequenceEqual

Lib/unittest/case.py:1016–1113  ·  view source on GitHub ↗

An equality assertion for ordered sequences (like lists and tuples). For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator. Args: seq1: The first sequence to compare.

(self, seq1, seq2, msg=None, seq_type=None)

Source from the content-addressed store, hash-verified

1014 raise self.failureException(msg)
1015
1016 def assertSequenceEqual(self, seq1, seq2, msg=None, seq_type=None):
1017 """An equality assertion for ordered sequences (like lists and tuples).
1018
1019 For the purposes of this function, a valid ordered sequence type is one
1020 which can be indexed, has a length, and has an equality operator.
1021
1022 Args:
1023 seq1: The first sequence to compare.
1024 seq2: The second sequence to compare.
1025 seq_type: The expected datatype of the sequences, or None if no
1026 datatype should be enforced.
1027 msg: Optional message to use on failure instead of a list of
1028 differences.
1029 """
1030 if seq_type is not None:
1031 seq_type_name = seq_type.__name__
1032 if not isinstance(seq1, seq_type):
1033 raise self.failureException('First sequence is not a %s: %s'
1034 % (seq_type_name, safe_repr(seq1)))
1035 if not isinstance(seq2, seq_type):
1036 raise self.failureException('Second sequence is not a %s: %s'
1037 % (seq_type_name, safe_repr(seq2)))
1038 else:
1039 seq_type_name = "sequence"
1040
1041 differing = None
1042 try:
1043 len1 = len(seq1)
1044 except (TypeError, NotImplementedError):
1045 differing = 'First %s has no length. Non-sequence?' % (
1046 seq_type_name)
1047
1048 if differing is None:
1049 try:
1050 len2 = len(seq2)
1051 except (TypeError, NotImplementedError):
1052 differing = 'Second %s has no length. Non-sequence?' % (
1053 seq_type_name)
1054
1055 if differing is None:
1056 if seq1 == seq2:
1057 return
1058
1059 differing = '%ss differ: %s != %s\n' % (
1060 (seq_type_name.capitalize(),) +
1061 _common_shorten_repr(seq1, seq2))
1062
1063 for i in range(min(len1, len2)):
1064 try:
1065 item1 = seq1[i]
1066 except (TypeError, IndexError, NotImplementedError):
1067 differing += ('\nUnable to index element %d of first %s\n' %
1068 (i, seq_type_name))
1069 break
1070
1071 try:
1072 item2 = seq2[i]
1073 except (TypeError, IndexError, NotImplementedError):

Callers 15

assertListEqualMethod · 0.95
assertTupleEqualMethod · 0.95
test_urlMethod · 0.80
test_leaf_generatorMethod · 0.80
split_exception_groupMethod · 0.80
test_ne_high_priorityMethod · 0.80
test_ne_low_priorityMethod · 0.80
test_excepthookMethod · 0.80
test_winregMethod · 0.80
test_syslogMethod · 0.80

Calls 9

_truncateMessageMethod · 0.95
_formatMessageMethod · 0.95
failMethod · 0.95
safe_reprFunction · 0.85
_common_shorten_reprFunction · 0.85
pformatMethod · 0.80
capitalizeMethod · 0.45
joinMethod · 0.45
splitlinesMethod · 0.45

Tested by 15

test_urlMethod · 0.64
test_leaf_generatorMethod · 0.64
split_exception_groupMethod · 0.64
test_ne_high_priorityMethod · 0.64
test_ne_low_priorityMethod · 0.64
test_excepthookMethod · 0.64
test_winregMethod · 0.64
test_syslogMethod · 0.64
test_http_1_1Method · 0.64