|
4 | 4 | import pymupdf |
5 | 5 | import subprocess |
6 | 6 | import sys |
| 7 | +import sysconfig |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def test_4767(): |
@@ -66,36 +67,51 @@ def get_paths(): |
66 | 67 | paths.append(path) |
67 | 68 | return paths |
68 | 69 |
|
| 70 | + def get_stdout(cp): |
| 71 | + ''' |
| 72 | + Strips free-threading warning. |
| 73 | + ''' |
| 74 | + stdout = cp.stdout |
| 75 | + if sysconfig.get_config_var('Py_GIL_DISABLED') == 1: |
| 76 | + line0, stdout = stdout.split('\n', 1) |
| 77 | + assert 'The global interpreter lock (GIL) has been enabled to load module \'pymupdf._extra\',' in line0 |
| 78 | + return stdout |
| 79 | + |
69 | 80 | cp = run(f'cd {testdir}/one/two && {sys.executable} -m pymupdf embed-extract {path} -name evil_entry') |
70 | | - print(cp.stdout) |
71 | 81 | assert cp.returncode |
72 | | - assert cp.stdout == 'refusing to write stored name outside current directory: ../../test.txt\n' |
| 82 | + stdout = get_stdout(cp) |
| 83 | + print(f'{stdout=}') |
| 84 | + assert stdout == 'refusing to write stored name outside current directory: ../../test.txt\n' |
73 | 85 | assert not get_paths() |
74 | 86 |
|
75 | 87 | cp = run(f'cd {testdir}/one/two && {sys.executable} -m pymupdf embed-extract {path} -name evil_entry -unsafe') |
76 | 88 | assert cp.returncode == 0 |
77 | | - assert cp.stdout == "saved entry 'evil_entry' as '../../test.txt'\n" |
| 89 | + stdout = get_stdout(cp) |
| 90 | + assert stdout == "saved entry 'evil_entry' as '../../test.txt'\n" |
78 | 91 | paths = get_paths() |
79 | 92 | print(f'{paths=}') |
80 | 93 | assert paths == [f'{testdir}/test.txt'] |
81 | 94 |
|
82 | 95 | cp = run(f'cd {testdir}/one/two && {sys.executable} -m pymupdf embed-extract {path} -name evil_entry2') |
83 | 96 | assert not cp.returncode |
84 | | - assert cp.stdout == "saved entry 'evil_entry2' as 'test2.txt'\n" |
| 97 | + stdout = get_stdout(cp) |
| 98 | + assert stdout == "saved entry 'evil_entry2' as 'test2.txt'\n" |
85 | 99 | paths = get_paths() |
86 | 100 | print(f'{paths=}') |
87 | 101 | assert paths == [f'{testdir}/test.txt', f'{testdir}/one/two/test2.txt'] |
88 | 102 |
|
89 | 103 | cp = run(f'cd {testdir}/one/two && {sys.executable} -m pymupdf embed-extract {path} -name evil_entry2') |
90 | 104 | assert cp.returncode |
91 | | - assert cp.stdout == "refusing to overwrite existing file with stored name: test2.txt\n" |
| 105 | + stdout = get_stdout(cp) |
| 106 | + assert stdout == "refusing to overwrite existing file with stored name: test2.txt\n" |
92 | 107 | paths = get_paths() |
93 | 108 | print(f'{paths=}') |
94 | 109 | assert paths == [f'{testdir}/test.txt', f'{testdir}/one/two/test2.txt'] |
95 | 110 |
|
96 | 111 | cp = run(f'cd {testdir}/one/two && {sys.executable} -m pymupdf embed-extract {path} -name evil_entry2 -unsafe') |
97 | 112 | assert not cp.returncode |
98 | | - assert cp.stdout == "saved entry 'evil_entry2' as 'test2.txt'\n" |
| 113 | + stdout = get_stdout(cp) |
| 114 | + assert stdout == "saved entry 'evil_entry2' as 'test2.txt'\n" |
99 | 115 | paths = get_paths() |
100 | 116 | print(f'{paths=}') |
101 | 117 | assert paths == [f'{testdir}/test.txt', f'{testdir}/one/two/test2.txt'] |
0 commit comments