Check redirection of messages and log diagnostics with environment variables PYMUPDF_LOG and PYMUPDF_MESSAGE.
()
| 1071 | f'expected/actual lines mismatch: {len(expected_regexes)=} {len(actual)=}.' |
| 1072 | |
| 1073 | def test_cli_out(): |
| 1074 | ''' |
| 1075 | Check redirection of messages and log diagnostics with environment |
| 1076 | variables PYMUPDF_LOG and PYMUPDF_MESSAGE. |
| 1077 | ''' |
| 1078 | if os.environ.get('PYODIDE_ROOT'): |
| 1079 | print('test_cli_out(): not running on Pyodide - cannot run child processes.') |
| 1080 | return |
| 1081 | |
| 1082 | import platform |
| 1083 | import re |
| 1084 | import subprocess |
| 1085 | log_prefix = None |
| 1086 | if os.environ.get('PYMUPDF_USE_EXTRA') == '0': |
| 1087 | log_prefix = f'.+Using non-default setting from PYMUPDF_USE_EXTRA: \'0\'' |
| 1088 | |
| 1089 | sys.path.append(os.path.normpath(f'{__file__}/../..')) |
| 1090 | try: |
| 1091 | import pipcl |
| 1092 | finally: |
| 1093 | del sys.path[0] |
| 1094 | pipcl.show_system() |
| 1095 | def check( |
| 1096 | expect_out, |
| 1097 | expect_err, |
| 1098 | message=None, |
| 1099 | log=None, |
| 1100 | ): |
| 1101 | ''' |
| 1102 | Sets PYMUPDF_MESSAGE to `message` and PYMUPDF_LOG to `log`, runs |
| 1103 | `pymupdf internal`, and checks lines stdout and stderr match regexes in |
| 1104 | `expect_out` and `expect_err`. Note that we enclose regexes in `^...$`. |
| 1105 | ''' |
| 1106 | env = dict() |
| 1107 | if log: |
| 1108 | env['PYMUPDF_LOG'] = log |
| 1109 | if message: |
| 1110 | env['PYMUPDF_MESSAGE'] = message |
| 1111 | command = 'pymupdf internal' |
| 1112 | print(f'Running: {command}', flush=1) |
| 1113 | if env: |
| 1114 | print(f'with:') |
| 1115 | for key in sorted(env.keys()): |
| 1116 | print(f' {key}={shlex.quote(env[key])}') |
| 1117 | env = os.environ | env |
| 1118 | cp = subprocess.run(command, shell=1, check=1, capture_output=1, env=env, text=True) |
| 1119 | |
| 1120 | check_lines(expect_out, cp.stdout) |
| 1121 | check_lines(expect_err, cp.stderr) |
| 1122 | |
| 1123 | print(f'test_cli_out(): {Py_GIL_DISABLED=}') |
| 1124 | print(f'test_cli_out(): {gil_enabled=}') |
| 1125 | |
| 1126 | print(f'Checking default, all output to stdout.') |
| 1127 | regex_gil_stderr = None |
| 1128 | if Py_GIL_DISABLED and gil_enabled: |
| 1129 | regex_gil_stderr = '.*The global interpreter lock.*' |
| 1130 | check( |
nothing calls this directly
no test coverage detected
searching dependent graphs…