MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / check_lines

Function check_lines

tests/test_general.py:1024–1071  ·  view source on GitHub ↗

Checks lines in match regexes in .

(expected_regexes, actual)

Source from the content-addressed store, hash-verified

1022
1023
1024def check_lines(expected_regexes, actual):
1025 '''
1026 Checks lines in <actual> match regexes in <expected_regexes>.
1027 ''&#x27;
1028 print(f'### check_lines():', flush=1)
1029 def str_to_list(s):
1030 if s is None:
1031 return list()
1032 if isinstance(s, str):
1033 return s.split('\n') if s else list()
1034 return s
1035 expected_regexes = str_to_list(expected_regexes)
1036 actual = str_to_list(actual)
1037 if expected_regexes and expected_regexes[-1]:
1038 expected_regexes.append('') # Always expect a trailing empty line.
1039 # Remove `None` regexes and make all regexes match entire lines.
1040 expected_regexes = [f'^{i}$' for i in expected_regexes if i is not None]
1041
1042 print(f'expected_regexes ({len(expected_regexes)}):')
1043 for i in expected_regexes:
1044 print(f' {i!r}')
1045
1046 print(f'actual ({len(actual)}):')
1047 for i in actual:
1048 print(f' {i!r}')
1049
1050 i_expected = 0
1051 i_actual = 0
1052 while 1:
1053 if i_expected == len(expected_regexes) and i_actual == len(actual):
1054 break
1055 print(f'expected {i_expected+1}/{len(expected_regexes)}')
1056 print(f'actual {i_actual+1}/{len(actual)}')
1057 assert i_expected < len(expected_regexes) and i_actual < len(actual)
1058 expected_regex_line = expected_regexes[i_expected]
1059 actual_line = actual[i_actual]
1060 if expected_regex_line is None:
1061 i_expected += 1
1062 continue
1063 print(f' expected_regex: {expected_regex_line!r}', flush=1)
1064 print(f' actual: {actual!r}', flush=1)
1065 match = re.match(expected_regex_line, actual_line)
1066 print(f' {match=}')
1067 assert match
1068 i_expected += 1
1069 i_actual += 1
1070 assert len(expected_regexes) == len(actual), \
1071 f'expected/actual lines mismatch: {len(expected_regexes)=} {len(actual)=}.'
1072
1073def test_cli_out():
1074 ''&#x27;

Callers 2

checkFunction · 0.85
test_cli_outFunction · 0.85

Calls 2

str_to_listFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…