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

Method assertSequenceEqual

Lib/unittest/case.py:1021–1118  ·  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

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

_truncateMessageMethod · 0.95
_formatMessageMethod · 0.95
failMethod · 0.95
isinstanceFunction · 0.85
safe_reprFunction · 0.85
lenFunction · 0.85
_common_shorten_reprFunction · 0.85
minFunction · 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