Skip to content

Commit 64efa3b

Browse files
winterheartjgm
authored andcommitted
Fix running tests on Python 3.14
In Python 3.14 multiprocessing module changed start method from fork to forkserver. Now child processes don't have access to parent's memory objects, and pathological_tests.py fails. This change move required objects (mostly object initialization) into child's area.
1 parent 7c38779 commit 64efa3b

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

test/pathological_tests.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
import re
54
import argparse
6-
import sys
7-
import platform
85
import itertools
96
import multiprocessing
7+
import re
8+
import sys
109
import queue
11-
import time
1210
from cmark import CMark
1311

14-
TIMEOUT = 5
15-
16-
parser = argparse.ArgumentParser(description='Run cmark tests.')
17-
parser.add_argument('--program', dest='program', nargs='?', default=None,
18-
help='program to test')
19-
parser.add_argument('--library-dir', dest='library_dir', nargs='?',
20-
default=None, help='directory containing dynamic library')
21-
args = parser.parse_args(sys.argv[1:])
22-
23-
allowed_failures = {"many references": True}
24-
25-
cmark = CMark(prog=args.program, library_dir=args.library_dir)
26-
2712
def hash_collisions():
2813
REFMAP_SIZE = 16
2914
COUNT = 25000
@@ -133,13 +118,18 @@ def badhash(ref):
133118

134119
whitespace_re = re.compile('/s+/')
135120

136-
def run_pathological(q, inp):
121+
def run_pathological(q, inp, prog, lib_dir):
122+
cmark = CMark(prog=prog, library_dir=lib_dir)
137123
q.put(cmark.to_html(inp))
138124

139-
def run_pathological_cmark(q, inp):
125+
def run_pathological_cmark(q, inp, prog, lib_dir):
126+
cmark = CMark(prog=prog, library_dir=lib_dir)
140127
q.put(cmark.to_commonmark(inp))
141128

142-
def run_tests():
129+
def run_tests(args):
130+
allowed_failures = {"many references": True}
131+
TIMEOUT = 5
132+
143133
q = multiprocessing.Queue()
144134
passed = []
145135
errored = []
@@ -150,12 +140,16 @@ def run_tests():
150140
for description in (*pathological, *pathological_cmark):
151141
if description in pathological:
152142
(inp, regex) = pathological[description]
153-
p = multiprocessing.Process(target=run_pathological,
154-
args=(q, inp))
143+
p = multiprocessing.Process(
144+
target=run_pathological,
145+
args=(q, inp, args.program, args.library_dir)
146+
)
155147
else:
156148
(inp, regex) = pathological_cmark[description]
157-
p = multiprocessing.Process(target=run_pathological_cmark,
158-
args=(q, inp))
149+
p = multiprocessing.Process(
150+
target=run_pathological_cmark,
151+
args=(q, inp, args.program, args.library_dir)
152+
)
159153
p.start()
160154
try:
161155
# wait TIMEOUT seconds or until it finishes
@@ -199,4 +193,10 @@ def run_tests():
199193
exit(0)
200194

201195
if __name__ == "__main__":
202-
run_tests()
196+
parser = argparse.ArgumentParser(description='Run cmark tests.')
197+
parser.add_argument('--program', dest='program', nargs='?', default=None,
198+
help='program to test')
199+
parser.add_argument('--library-dir', dest='library_dir', nargs='?',
200+
default=None, help='directory containing dynamic library')
201+
args = parser.parse_args(sys.argv[1:])
202+
run_tests(args)

0 commit comments

Comments
 (0)