@@ -56,6 +56,19 @@ def copy_srcdir_to_tmpdir(srcdir: path, tmp: path) -> path:
56
56
return tmproot
57
57
58
58
59
+ def create_src_files_in_tmpdir (files : list [tuple [Path , str ]], tmp : path ) -> path :
60
+ """Create source files in a temporary directory under the subdir src."""
61
+ subdir = path ("src" )
62
+ tmproot = tmp .joinpath (generate_random_string ()) / subdir
63
+ tmproot .makedirs (exist_ok = True )
64
+ for file in files :
65
+ file_path , content = file
66
+ file_abs = tmproot .joinpath (str (file_path ))
67
+ file_abs .parent .makedirs (exist_ok = True )
68
+ file_abs .write_text (content )
69
+ return tmproot
70
+
71
+
59
72
def get_abspath (relpath : str ) -> str :
60
73
"""
61
74
Get the absolute path from a relative path.
@@ -266,9 +279,18 @@ def test_app(make_app, sphinx_test_tempdir, request):
266
279
)
267
280
sphinx_conf_overrides .update (plantuml = plantuml )
268
281
269
- # copy test srcdir to test temporary directory sphinx_test_tempdir
270
282
srcdir = builder_params .get ("srcdir" )
271
- src_dir = copy_srcdir_to_tmpdir (srcdir , sphinx_test_tempdir )
283
+ files = builder_params .get ("files" )
284
+ if (srcdir is None ) == (files is None ):
285
+ raise ValueError ("Exactly one of srcdir, files must not be None" )
286
+
287
+ if srcdir is not None :
288
+ # copy test srcdir to test temporary directory sphinx_test_tempdir
289
+ src_dir = copy_srcdir_to_tmpdir (srcdir , sphinx_test_tempdir )
290
+ else :
291
+ # create given files in tmpdir
292
+ src_dir = create_src_files_in_tmpdir (files , sphinx_test_tempdir )
293
+
272
294
parent_path = Path (str (src_dir .parent .abspath ()))
273
295
274
296
if version_info >= (7 , 2 ):
0 commit comments