Checks lines in match regexes in .
(expected_regexes, actual)
| 1022 | |
| 1023 | |
| 1024 | def check_lines(expected_regexes, actual): |
| 1025 | ''' |
| 1026 | Checks lines in <actual> match regexes in <expected_regexes>. |
| 1027 | ''' |
| 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 | |
| 1073 | def test_cli_out(): |
| 1074 | ''' |
no test coverage detected
searching dependent graphs…