MCPcopy Index your code
hub / github.com/python/mypy / assert_string_arrays_equal

Function assert_string_arrays_equal

mypy/test/helpers.py:152–194  ·  view source on GitHub ↗

Assert that two string arrays are equal. Display any differences in a human-readable form.

(
    expected: list[str],
    actual: list[str],
    msg: str,
    *,
    traceback: bool = False,
    ignore_modules_order: bool = False,
)

Source from the content-addressed store, hash-verified

150
151
152def assert_string_arrays_equal(
153 expected: list[str],
154 actual: list[str],
155 msg: str,
156 *,
157 traceback: bool = False,
158 ignore_modules_order: bool = False,
159) -> None:
160 """Assert that two string arrays are equal.
161
162 Display any differences in a human-readable form.
163 """
164 actual = clean_up(actual)
165 if ignore_modules_order:
166 expected_module_order = module_order(expected)
167 actual = match_module_order(actual, expected_module_order)
168 if expected != actual:
169 expected_ranges, actual_ranges = diff_ranges(expected, actual)
170 sys.stderr.write("Expected:\n")
171 red = "\033[31m" if sys.platform != "win32" else None
172 render_diff_range(expected_ranges, expected, colour=red)
173 sys.stderr.write("Actual:\n")
174 green = "\033[32m" if sys.platform != "win32" else None
175 render_diff_range(actual_ranges, actual, colour=green)
176
177 sys.stderr.write("\n")
178 first_diff = next(
179 (i for i, (a, b) in enumerate(zip(expected, actual)) if a != b),
180 max(len(expected), len(actual)),
181 )
182 if 0 <= first_diff < len(actual) and (
183 len(expected[first_diff]) >= MIN_LINE_LENGTH_FOR_ALIGNMENT
184 or len(actual[first_diff]) >= MIN_LINE_LENGTH_FOR_ALIGNMENT
185 ):
186 # Display message that helps visualize the differences between two
187 # long lines.
188 show_align_message(expected[first_diff], actual[first_diff])
189
190 sys.stderr.write(
191 "Update the test output using --update-data "
192 "(implies -n0; you can additionally use the -k selector to update only specific tests)\n"
193 )
194 pytest.fail(msg, pytrace=traceback)
195
196
197def assert_module_equivalence(name: str, expected: Iterable[str], actual: Iterable[str]) -> None:

Callers 15

test_semanalFunction · 0.90
test_semanal_errorFunction · 0.90
run_caseMethod · 0.90
run_caseMethod · 0.90
run_caseMethod · 0.90
test_error_streamFunction · 0.90
test_python_evaluationFunction · 0.90
run_caseMethod · 0.90
test_parserFunction · 0.90
test_parser_importsFunction · 0.90
run_caseMethod · 0.90
run_caseMethod · 0.90

Calls 13

clean_upFunction · 0.85
module_orderFunction · 0.85
match_module_orderFunction · 0.85
diff_rangesFunction · 0.85
render_diff_rangeFunction · 0.85
nextFunction · 0.85
enumerateFunction · 0.85
zipFunction · 0.85
maxFunction · 0.85
lenFunction · 0.85
show_align_messageFunction · 0.85
writeMethod · 0.45

Tested by 15

test_semanalFunction · 0.72
test_semanal_errorFunction · 0.72
run_caseMethod · 0.72
run_caseMethod · 0.72
run_caseMethod · 0.72
test_error_streamFunction · 0.72
test_python_evaluationFunction · 0.72
run_caseMethod · 0.72
test_parserFunction · 0.72
test_parser_importsFunction · 0.72
run_caseMethod · 0.72
run_caseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…