upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_anim_index.py30
-rw-r--r--tests/test_audio_stage_resume.py6
-rw-r--r--tests/test_audio_wav.py6
-rw-r--r--tests/test_awc_manifest.py2
-rw-r--r--tests/test_gamedata_graph.py2
-rw-r--r--tests/test_hw_oracle.py5
-rw-r--r--tests/test_make_game_submodule.py3
-rw-r--r--tests/test_manifest_verifier.py1
-rw-r--r--tests/test_spirv_metal_set0_cli_errors.py4
-rw-r--r--tests/test_spirv_metal_set0_extra.py4
-rw-r--r--tests/test_user_sgpr_census.py4
-rw-r--r--tests/test_world_build.py4
-rw-r--r--tests/winbatch.py44
13 files changed, 82 insertions, 33 deletions
diff --git a/tests/test_anim_index.py b/tests/test_anim_index.py
index 5843d0b23..c8fed3049 100644
--- a/tests/test_anim_index.py
+++ b/tests/test_anim_index.py
@@ -320,7 +320,7 @@ class ArchiveTest(unittest.TestCase):
320 ("--limit", "-100", "must be at least 1")): 320 ("--limit", "-100", "must be at least 1")):
321 out = os.path.join(self.root, "bad.json") 321 out = os.path.join(self.root, "bad.json")
322 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--quiet", flag, value], 322 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--quiet", flag, value],
323 capture_output=True, text=True, encoding="utf-8", errors="replace") 323 capture_output=True, text=True, errors="replace")
324 self.assertEqual(p.returncode, 2, p.stderr) 324 self.assertEqual(p.returncode, 2, p.stderr)
325 self.assertIn(message, p.stderr) 325 self.assertIn(message, p.stderr)
326 self.assertNotIn("Traceback", p.stderr) 326 self.assertNotIn("Traceback", p.stderr)
@@ -333,7 +333,7 @@ class ArchiveTest(unittest.TestCase):
333 (self.rpf, out_in_missing, out_in_missing)): 333 (self.rpf, out_in_missing, out_in_missing)):
334 with self.subTest(path=os.path.relpath(path, self.root)): 334 with self.subTest(path=os.path.relpath(path, self.root)):
335 p = subprocess.run([sys.executable, "-I", TOOL, source, out, "--quiet"], 335 p = subprocess.run([sys.executable, "-I", TOOL, source, out, "--quiet"],
336 capture_output=True, text=True, encoding="utf-8", errors="replace") 336 capture_output=True, text=True, errors="replace")
337 self.assertEqual(p.returncode, 1, p.stderr) 337 self.assertEqual(p.returncode, 1, p.stderr)
338 self.assertTrue(p.stderr.startswith(path + ": "), p.stderr) 338 self.assertTrue(p.stderr.startswith(path + ": "), p.stderr)
339 self.assertNotIn("Traceback", p.stderr) 339 self.assertNotIn("Traceback", p.stderr)
@@ -343,7 +343,7 @@ class ArchiveTest(unittest.TestCase):
343 def test_cli(self): 343 def test_cli(self):
344 out = os.path.join(self.root, "cli.json") 344 out = os.path.join(self.root, "cli.json")
345 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--quiet"], 345 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--quiet"],
346 capture_output=True, text=True, encoding="utf-8", errors="replace") 346 capture_output=True, text=True, errors="replace")
347 self.assertEqual(p.returncode, 0, p.stdout + p.stderr) 347 self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
348 with open(out, encoding="utf-8") as f: 348 with open(out, encoding="utf-8") as f:
349 doc = json.load(f) 349 doc = json.load(f)
@@ -357,7 +357,7 @@ class ArchiveTest(unittest.TestCase):
357 with open(rigs, "w", encoding="utf-8") as f: 357 with open(rigs, "w", encoding="utf-8") as f:
358 f.write('{"previous": true}') 358 f.write('{"previous": true}')
359 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", rigs, "--quiet"], 359 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", rigs, "--quiet"],
360 capture_output=True, text=True, encoding="utf-8", errors="replace") 360 capture_output=True, text=True, errors="replace")
361 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 361 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
362 self.assertIn("no anim/rigset/ keys found", p.stderr) 362 self.assertIn("no anim/rigset/ keys found", p.stderr)
363 self.assertNotIn("Traceback", p.stderr) 363 self.assertNotIn("Traceback", p.stderr)
@@ -368,14 +368,14 @@ class ArchiveTest(unittest.TestCase):
368 folder_out = os.path.join(self.root, "out_folder") 368 folder_out = os.path.join(self.root, "out_folder")
369 os.makedirs(folder_out) 369 os.makedirs(folder_out)
370 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, folder_out, "--quiet"], 370 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, folder_out, "--quiet"],
371 capture_output=True, text=True, encoding="utf-8", errors="replace") 371 capture_output=True, text=True, errors="replace")
372 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 372 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
373 self.assertIn("is a folder, not a .csv or .json file", p.stderr) 373 self.assertIn("is a folder, not a .csv or .json file", p.stderr)
374 374
375 def test_cli_rejects_invalid_extension(self): 375 def test_cli_rejects_invalid_extension(self):
376 txt_out = os.path.join(self.root, "out.txt") 376 txt_out = os.path.join(self.root, "out.txt")
377 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, txt_out, "--quiet"], 377 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, txt_out, "--quiet"],
378 capture_output=True, text=True, encoding="utf-8", errors="replace") 378 capture_output=True, text=True, errors="replace")
379 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 379 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
380 self.assertIn("output must end in .json or .csv", p.stderr) 380 self.assertIn("output must end in .json or .csv", p.stderr)
381 381
@@ -392,25 +392,25 @@ class ArchiveTest(unittest.TestCase):
392 392
393 # Refuse to overwrite carve manifest via out 393 # Refuse to overwrite carve manifest via out
394 p = subprocess.run([sys.executable, "-I", TOOL, carve, manifest, "--quiet"], 394 p = subprocess.run([sys.executable, "-I", TOOL, carve, manifest, "--quiet"],
395 capture_output=True, text=True, encoding="utf-8", errors="replace") 395 capture_output=True, text=True, errors="replace")
396 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 396 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
397 self.assertIn("output would overwrite the carve manifest", p.stderr) 397 self.assertIn("output would overwrite the carve manifest", p.stderr)
398 398
399 # Refuse to overwrite carve manifest via --rigs 399 # Refuse to overwrite carve manifest via --rigs
400 p = subprocess.run([sys.executable, "-I", TOOL, carve, out_csv, "--rigs", manifest, "--quiet"], 400 p = subprocess.run([sys.executable, "-I", TOOL, carve, out_csv, "--rigs", manifest, "--quiet"],
401 capture_output=True, text=True, encoding="utf-8", errors="replace") 401 capture_output=True, text=True, errors="replace")
402 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 402 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
403 self.assertIn("--rigs would overwrite the carve manifest", p.stderr) 403 self.assertIn("--rigs would overwrite the carve manifest", p.stderr)
404 404
405 # Refuse to overwrite carved input file via out 405 # Refuse to overwrite carved input file via out
406 p = subprocess.run([sys.executable, "-I", TOOL, carve, bin_file, "--quiet"], 406 p = subprocess.run([sys.executable, "-I", TOOL, carve, bin_file, "--quiet"],
407 capture_output=True, text=True, encoding="utf-8", errors="replace") 407 capture_output=True, text=True, errors="replace")
408 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 408 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
409 self.assertIn("output would overwrite an input file", p.stderr) 409 self.assertIn("output would overwrite an input file", p.stderr)
410 410
411 # Refuse to overwrite carved input file via --rigs 411 # Refuse to overwrite carved input file via --rigs
412 p = subprocess.run([sys.executable, "-I", TOOL, carve, out_csv, "--rigs", bin_file, "--quiet"], 412 p = subprocess.run([sys.executable, "-I", TOOL, carve, out_csv, "--rigs", bin_file, "--quiet"],
413 capture_output=True, text=True, encoding="utf-8", errors="replace") 413 capture_output=True, text=True, errors="replace")
414 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 414 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
415 self.assertIn("--rigs would overwrite an input file", p.stderr) 415 self.assertIn("--rigs would overwrite an input file", p.stderr)
416 416
@@ -436,7 +436,7 @@ class ArchiveTest(unittest.TestCase):
436 with self.subTest(flags=flags): 436 with self.subTest(flags=flags):
437 out = os.path.join(self.root, f"bad{i}.json") 437 out = os.path.join(self.root, f"bad{i}.json")
438 p = subprocess.run([sys.executable, "-I", TOOL, folder, out, "--quiet", *flags], 438 p = subprocess.run([sys.executable, "-I", TOOL, folder, out, "--quiet", *flags],
439 capture_output=True, text=True, encoding="utf-8", errors="replace") 439 capture_output=True, text=True, errors="replace")
440 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 440 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
441 self.assertEqual(len(p.stderr.splitlines()), 1, p.stderr) 441 self.assertEqual(len(p.stderr.splitlines()), 1, p.stderr)
442 for flag in flags[::2]: 442 for flag in flags[::2]:
@@ -541,12 +541,12 @@ class RigArchiveTest(unittest.TestCase):
541 folder = os.path.join(self.root, "rig_folder") 541 folder = os.path.join(self.root, "rig_folder")
542 os.makedirs(folder) 542 os.makedirs(folder)
543 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", folder, "--quiet"], 543 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", folder, "--quiet"],
544 capture_output=True, text=True, encoding="utf-8", errors="replace") 544 capture_output=True, text=True, errors="replace")
545 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 545 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
546 self.assertIn("is a folder, not a JSON file", p.stderr) 546 self.assertIn("is a folder, not a JSON file", p.stderr)
547 547
548 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", os.path.join(self.root, "rigs.csv"), "--quiet"], 548 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", os.path.join(self.root, "rigs.csv"), "--quiet"],
549 capture_output=True, text=True, encoding="utf-8", errors="replace") 549 capture_output=True, text=True, errors="replace")
550 self.assertEqual(p.returncode, 2, p.stdout + p.stderr) 550 self.assertEqual(p.returncode, 2, p.stdout + p.stderr)
551 self.assertIn("--rigs must end in .json", p.stderr) 551 self.assertIn("--rigs must end in .json", p.stderr)
552 552
@@ -554,7 +554,7 @@ class RigArchiveTest(unittest.TestCase):
554 out = os.path.join(self.root, "index.json") 554 out = os.path.join(self.root, "index.json")
555 rigs = os.path.join(self.root, "rigs.json") 555 rigs = os.path.join(self.root, "rigs.json")
556 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", rigs, "--quiet"], 556 p = subprocess.run([sys.executable, "-I", TOOL, self.rpf, out, "--rigs", rigs, "--quiet"],
557 capture_output=True, text=True, encoding="utf-8", errors="replace") 557 capture_output=True, text=True, errors="replace")
558 self.assertEqual(p.returncode, 0, p.stdout + p.stderr) 558 self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
559 with open(rigs, encoding="utf-8") as f: 559 with open(rigs, encoding="utf-8") as f:
560 doc = json.load(f) 560 doc = json.load(f)
@@ -583,7 +583,7 @@ class RigArchiveTest(unittest.TestCase):
583 out = os.path.join(self.root, label + "-index.json") 583 out = os.path.join(self.root, label + "-index.json")
584 rigs = os.path.join(self.root, label + "-rigs.json") 584 rigs = os.path.join(self.root, label + "-rigs.json")
585 p = subprocess.run([sys.executable, "-I", TOOL, carved, out, "--rigs", rigs, "--quiet"], 585 p = subprocess.run([sys.executable, "-I", TOOL, carved, out, "--rigs", rigs, "--quiet"],
586 capture_output=True, text=True, encoding="utf-8", errors="replace") 586 capture_output=True, text=True, errors="replace")
587 self.assertEqual(p.returncode, 0, p.stdout + p.stderr) 587 self.assertEqual(p.returncode, 0, p.stdout + p.stderr)
588 with open(rigs, encoding="utf-8") as f: 588 with open(rigs, encoding="utf-8") as f:
589 summary = json.load(f)["rbf0"]["summary"] 589 summary = json.load(f)["rbf0"]["summary"]
diff --git a/tests/test_audio_stage_resume.py b/tests/test_audio_stage_resume.py
index 591d35d81..edf70f6b2 100644
--- a/tests/test_audio_stage_resume.py
+++ b/tests/test_audio_stage_resume.py
@@ -15,8 +15,10 @@ from unittest import mock
15ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 15ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
16sys.path.insert(0, ROOT) 16sys.path.insert(0, ROOT)
17sys.path.insert(0, os.path.join(ROOT, "tools")) 17sys.path.insert(0, os.path.join(ROOT, "tools"))
18sys.path.insert(0, os.path.join(ROOT, "tests"))
18import awc_opus # noqa: E402 19import awc_opus # noqa: E402
19import make_game # noqa: E402 20import make_game # noqa: E402
21import winbatch # noqa: E402
20 22
21 23
22class WriteFileTest(unittest.TestCase): 24class WriteFileTest(unittest.TestCase):
@@ -218,9 +220,7 @@ class DecodeXmaStdinTest(unittest.TestCase):
218 with open(script, "w", encoding="utf-8") as f: 220 with open(script, "w", encoding="utf-8") as f:
219 f.write(STDIN_FFMPEG) 221 f.write(STDIN_FFMPEG)
220 if os.name == "nt": 222 if os.name == "nt":
221 ffmpeg = os.path.join(d, "ffmpeg.cmd") 223 ffmpeg = winbatch.write_python_cmd(os.path.join(d, "ffmpeg.cmd"), sys.executable, script)
222 with open(ffmpeg, "w", encoding="utf-8") as f:
223 f.write(f'@"{sys.executable}" "{script}" %*\n')
224 else: 224 else:
225 ffmpeg = os.path.join(d, "ffmpeg") 225 ffmpeg = os.path.join(d, "ffmpeg")
226 with open(ffmpeg, "w", encoding="utf-8") as f: 226 with open(ffmpeg, "w", encoding="utf-8") as f:
diff --git a/tests/test_audio_wav.py b/tests/test_audio_wav.py
index 4b1308f8d..6535ac998 100644
--- a/tests/test_audio_wav.py
+++ b/tests/test_audio_wav.py
@@ -23,8 +23,10 @@ TOOL = os.path.join(ROOT, "tools", "audio_wav.py")
23FFMPEG = shutil.which("ffmpeg") 23FFMPEG = shutil.which("ffmpeg")
24 24
25sys.path.insert(0, os.path.join(ROOT, "tools")) 25sys.path.insert(0, os.path.join(ROOT, "tools"))
26sys.path.insert(0, os.path.join(ROOT, "tests"))
26import audio_wav # noqa: E402 27import audio_wav # noqa: E402
27import awc_opus # noqa: E402 28import awc_opus # noqa: E402
29import winbatch # noqa: E402
28 30
29 31
30@unittest.skipUnless(FFMPEG, "ffmpeg is not on PATH") 32@unittest.skipUnless(FFMPEG, "ffmpeg is not on PATH")
@@ -416,9 +418,7 @@ def write_fake_ffmpeg(directory, source=FAKE_FFMPEG):
416 with open(script, "w", encoding="utf-8") as f: 418 with open(script, "w", encoding="utf-8") as f:
417 f.write(source) 419 f.write(source)
418 if os.name == "nt": 420 if os.name == "nt":
419 ffmpeg = os.path.join(directory, "ffmpeg.cmd") 421 ffmpeg = winbatch.write_python_cmd(os.path.join(directory, "ffmpeg.cmd"), sys.executable, script)
420 with open(ffmpeg, "w", encoding="utf-8") as f:
421 f.write(f'@"{sys.executable}" "{script}" %*\n')
422 else: 422 else:
423 ffmpeg = os.path.join(directory, "ffmpeg") 423 ffmpeg = os.path.join(directory, "ffmpeg")
424 with open(ffmpeg, "w", encoding="utf-8") as f: 424 with open(ffmpeg, "w", encoding="utf-8") as f:
diff --git a/tests/test_awc_manifest.py b/tests/test_awc_manifest.py
index 6e8721868..f3747587b 100644
--- a/tests/test_awc_manifest.py
+++ b/tests/test_awc_manifest.py
@@ -89,7 +89,7 @@ class ManifestTest(unittest.TestCase):
89 89
90 def run_tool(self, *args): 90 def run_tool(self, *args):
91 return subprocess.run([sys.executable, "-I", TOOL, *args], capture_output=True, 91 return subprocess.run([sys.executable, "-I", TOOL, *args], capture_output=True,
92 text=True, encoding="utf-8", timeout=60) 92 text=True, errors="replace", timeout=60)
93 93
94 def test_csv_rows_codecs_and_bad_bank_skip(self): 94 def test_csv_rows_codecs_and_bad_bank_skip(self):
95 bank = self.write_bank() 95 bank = self.write_bank()
diff --git a/tests/test_gamedata_graph.py b/tests/test_gamedata_graph.py
index af2320bfb..62938e1af 100644
--- a/tests/test_gamedata_graph.py
+++ b/tests/test_gamedata_graph.py
@@ -95,7 +95,7 @@ class GamedataGraphTest(unittest.TestCase):
95 95
96 def run_tool(self, *args): 96 def run_tool(self, *args):
97 return subprocess.run([sys.executable, "-I", TOOL, *args], cwd=self.root, 97 return subprocess.run([sys.executable, "-I", TOOL, *args], cwd=self.root,
98 capture_output=True, text=True, encoding="utf-8", errors="replace") 98 capture_output=True, text=True, errors="replace")
99 99
100 def test_cli_reports_unwritable_graph_report(self): 100 def test_cli_reports_unwritable_graph_report(self):
101 self.finish() 101 self.finish()
diff --git a/tests/test_hw_oracle.py b/tests/test_hw_oracle.py
index c290f04ef..ea2f4ac78 100644
--- a/tests/test_hw_oracle.py
+++ b/tests/test_hw_oracle.py
@@ -338,7 +338,8 @@ class VcvarsScript(unittest.TestCase):
338 os.makedirs(work) 338 os.makedirs(work)
339 argv = runner.build_command("vcvars", "vcvars64.bat", "hw_oracle.c", "hw_oracle.exe", work) 339 argv = runner.build_command("vcvars", "vcvars64.bat", "hw_oracle.c", "hw_oracle.exe", work)
340 with open(os.path.join(work, argv[-1]), "rb") as f: 340 with open(os.path.join(work, argv[-1]), "rb") as f:
341 lines = f.read().decode("ascii").split("\r\n") 341 # UTF-8, not ASCII: the /Fo folder sits in %TEMP%, which can hold a non-ASCII user name.
342 lines = f.read().decode("utf-8").split("\r\n")
342 self.assertEqual(lines[3], 'call "vcvars64.bat" >nul || exit /b 1') 343 self.assertEqual(lines[3], 'call "vcvars64.bat" >nul || exit /b 1')
343 self.assertTrue(lines[4].startswith("cl /nologo /O1 hw_oracle.c /Fehw_oracle.exe /Fo")) 344 self.assertTrue(lines[4].startswith("cl /nologo /O1 hw_oracle.c /Fehw_oracle.exe /Fo"))
344 345
@@ -419,7 +420,7 @@ class Unavailable(unittest.TestCase):
419 with tempfile.TemporaryDirectory() as tmp: 420 with tempfile.TemporaryDirectory() as tmp:
420 argv = runner.build_command("vcvars", r"C:\VS 2022\vcvars64.bat", "a.c", "o.exe", tmp) 421 argv = runner.build_command("vcvars", r"C:\VS 2022\vcvars64.bat", "a.c", "o.exe", tmp)
421 self.assertEqual(argv[:3], ["cmd.exe", "/d", "/c"]) 422 self.assertEqual(argv[:3], ["cmd.exe", "/d", "/c"])
422 script = (Path(tmp) / argv[3]).read_text(encoding="ascii") 423 script = (Path(tmp) / argv[3]).read_text(encoding="utf-8") # UTF-8; tmp may be non-ASCII
423 self.assertIn('call "C:\\VS 2022\\vcvars64.bat"', script) # quoted: the path has a space 424 self.assertIn('call "C:\\VS 2022\\vcvars64.bat"', script) # quoted: the path has a space
424 self.assertIn("cl /nologo /O1 a.c /Feo.exe", script) 425 self.assertIn("cl /nologo /O1 a.c /Feo.exe", script)
425 self.assertIn("Installer", script) # vcvars needs vswhere on PATH 426 self.assertIn("Installer", script) # vcvars needs vswhere on PATH
diff --git a/tests/test_make_game_submodule.py b/tests/test_make_game_submodule.py
index 450228b40..0870ecb28 100644
--- a/tests/test_make_game_submodule.py
+++ b/tests/test_make_game_submodule.py
@@ -86,7 +86,8 @@ class EnsureSubmoduleTest(unittest.TestCase):
86 result = subprocess.run( 86 result = subprocess.run(
87 [sys.executable, "-I", str(Path(__file__).resolve()), 87 [sys.executable, "-I", str(Path(__file__).resolve()),
88 "EnsureSubmoduleTest.test_initializes_submodule_in_linked_worktree"], 88 "EnsureSubmoduleTest.test_initializes_submodule_in_linked_worktree"],
89 cwd=self.root, env=hook_env, capture_output=True, text=True, 89 # errors="replace": git prints paths in UTF-8, which the Windows ANSI code page can't always decode.
90 cwd=self.root, env=hook_env, capture_output=True, text=True, errors="replace",
90 ) 91 )
91 self.assertEqual(result.returncode, 0, result.stdout + result.stderr) 92 self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
92 93
diff --git a/tests/test_manifest_verifier.py b/tests/test_manifest_verifier.py
index b799cc1b1..88ac2f655 100644
--- a/tests/test_manifest_verifier.py
+++ b/tests/test_manifest_verifier.py
@@ -87,7 +87,6 @@ class TestManifestVerifier(unittest.TestCase):
87 cwd=self.root, 87 cwd=self.root,
88 capture_output=True, 88 capture_output=True,
89 text=True, 89 text=True,
90 encoding="utf-8",
91 errors="replace", 90 errors="replace",
92 ) 91 )
93 92
diff --git a/tests/test_spirv_metal_set0_cli_errors.py b/tests/test_spirv_metal_set0_cli_errors.py
index a7a3f966d..18a58e25a 100644
--- a/tests/test_spirv_metal_set0_cli_errors.py
+++ b/tests/test_spirv_metal_set0_cli_errors.py
@@ -39,8 +39,10 @@ class CliErrorTest(unittest.TestCase):
39 39
40 def run_tool(self, dis, asm, src=None): 40 def run_tool(self, dis, asm, src=None):
41 env = dict(os.environ, SPIRV_DIS=dis, SPIRV_AS=asm) 41 env = dict(os.environ, SPIRV_DIS=dis, SPIRV_AS=asm)
42 # The tool is a Python child: piped, it writes in the locale encoding (the ANSI code page on Windows), so read
43 # it back in that encoding. UTF-8 would turn a non-ASCII temp path into replacement characters.
42 return subprocess.run([sys.executable, "-I", TOOL, src or self.src, self.out], env=env, capture_output=True, 44 return subprocess.run([sys.executable, "-I", TOOL, src or self.src, self.out], env=env, capture_output=True,
43 text=True, encoding="utf-8", errors="replace") 45 text=True, errors="replace")
44 46
45 def assert_failed(self, result): 47 def assert_failed(self, result):
46 self.assertEqual(result.returncode, 1, result.stdout + result.stderr) 48 self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
diff --git a/tests/test_spirv_metal_set0_extra.py b/tests/test_spirv_metal_set0_extra.py
index 5b03f429e..5f8b63c62 100644
--- a/tests/test_spirv_metal_set0_extra.py
+++ b/tests/test_spirv_metal_set0_extra.py
@@ -343,7 +343,7 @@ def _make_fake_spirv_tools(dis_name="spirv-dis", asm_name="spirv-as"):
343 """Return a subprocess.run replacement backed by the synthetic SPIR-V binary codec.""" 343 """Return a subprocess.run replacement backed by the synthetic SPIR-V binary codec."""
344 calls: list[list[str]] = [] 344 calls: list[list[str]] = []
345 345
346 def fake_run(cmd, check=False, capture_output=False, text=False, input=None): 346 def fake_run(cmd, check=False, capture_output=False, text=False, input=None, errors=None):
347 calls.append(list(cmd)) 347 calls.append(list(cmd))
348 exe = cmd[0] 348 exe = cmd[0]
349 if exe == dis_name: 349 if exe == dis_name:
@@ -903,7 +903,7 @@ class TestMainAndCli(unittest.TestCase):
903 disasm = header_text + "OpCapability Shader\n" 903 disasm = header_text + "OpCapability Shader\n"
904 seen_cmds = [] 904 seen_cmds = []
905 905
906 def run_stub(cmd, check=False, capture_output=False, text=False, input=None): 906 def run_stub(cmd, check=False, capture_output=False, text=False, input=None, errors=None):
907 seen_cmds.append((list(cmd), check, capture_output, text, input)) 907 seen_cmds.append((list(cmd), check, capture_output, text, input))
908 if len(seen_cmds) == 1: 908 if len(seen_cmds) == 1:
909 return subprocess.CompletedProcess(cmd, 0, disasm, "") 909 return subprocess.CompletedProcess(cmd, 0, disasm, "")
diff --git a/tests/test_user_sgpr_census.py b/tests/test_user_sgpr_census.py
index 29f0207ee..cabfbb200 100644
--- a/tests/test_user_sgpr_census.py
+++ b/tests/test_user_sgpr_census.py
@@ -162,8 +162,10 @@ TOOL = os.path.join(ROOT, "tools", "user_sgpr_census.py")
162 162
163 163
164def run_cli(*args): 164def run_cli(*args):
165 # A piped Python child writes in the locale encoding (the ANSI code page on Windows): read it back in that
166 # encoding, or a non-ASCII temp path in the error line no longer matches.
165 return subprocess.run([sys.executable, "-I", TOOL, *map(str, args)], capture_output=True, text=True, 167 return subprocess.run([sys.executable, "-I", TOOL, *map(str, args)], capture_output=True, text=True,
166 encoding="utf-8", errors="replace") 168 errors="replace")
167 169
168 170
169def assert_one_error_line(result, *fragments): 171def assert_one_error_line(result, *fragments):
diff --git a/tests/test_world_build.py b/tests/test_world_build.py
index 82ebd2f8b..df0302e6c 100644
--- a/tests/test_world_build.py
+++ b/tests/test_world_build.py
@@ -1314,7 +1314,7 @@ class BaseColorParamTest(unittest.TestCase):
1314 1314
1315 def _run_cli(self, assets_dir, out_dir, *extra_args): 1315 def _run_cli(self, assets_dir, out_dir, *extra_args):
1316 cmd = [sys.executable, "-I", self.TOOL, assets_dir, "--out", out_dir, *extra_args] 1316 cmd = [sys.executable, "-I", self.TOOL, assets_dir, "--out", out_dir, *extra_args]
1317 return subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace") 1317 return subprocess.run(cmd, capture_output=True, text=True, errors="replace")
1318 1318
1319 def _read_world(self, out_dir): 1319 def _read_world(self, out_dir):
1320 with open(os.path.join(out_dir, "world.json"), encoding="utf-8") as f: 1320 with open(os.path.join(out_dir, "world.json"), encoding="utf-8") as f:
@@ -1422,7 +1422,7 @@ class WorldBuildTest(unittest.TestCase):
1422 1422
1423 def _run_cli(self, assets_dir: str, out_dir: str, *extra_args: str) -> subprocess.CompletedProcess: 1423 def _run_cli(self, assets_dir: str, out_dir: str, *extra_args: str) -> subprocess.CompletedProcess:
1424 cmd = [sys.executable, "-I", self.TOOL, assets_dir, "--out", out_dir, *extra_args] 1424 cmd = [sys.executable, "-I", self.TOOL, assets_dir, "--out", out_dir, *extra_args]
1425 return subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace") 1425 return subprocess.run(cmd, capture_output=True, text=True, errors="replace")
1426 1426
1427 @staticmethod 1427 @staticmethod
1428 def _output_snapshot(directory): 1428 def _output_snapshot(directory):
diff --git a/tests/winbatch.py b/tests/winbatch.py
new file mode 100644
index 000000000..55d302853
--- /dev/null
+++ b/tests/winbatch.py
@@ -0,0 +1,44 @@
1"""Write a one-line Windows batch file (a fake tool for a test) that cmd.exe can run from any user folder.
2
3cmd.exe decodes a batch file with the console's OEM code page, not UTF-8, so a path with non-ASCII letters (a
4user folder named in Cyrillic, say) written as UTF-8 becomes "The system cannot find the path specified".
5Standard library only.
6"""
7
8
9def batch_path(path):
10 """A spelling of path that cmd.exe reads correctly from a batch file: as is when ASCII, else its 8.3 short name
11 (ASCII). Falls back to the long path where the volume has 8.3 names turned off."""
12 if path.isascii():
13 return path
14 import ctypes
15 buf = ctypes.create_unicode_buffer(32768)
16 n = ctypes.windll.kernel32.GetShortPathNameW(path, buf, len(buf))
17 return buf.value if 0 < n < len(buf) else path
18
19
20def _encodes(char):
21 try:
22 char.encode("oem")
23 return True
24 except UnicodeEncodeError:
25 return False
26
27
28def write_python_cmd(cmd_path, python, script):
29 """Write cmd_path as a batch file that runs `python script` with the batch file's arguments.
30
31 Raises unittest.SkipTest when a path has no 8.3 name and letters outside the OEM code page (Cyrillic on a
32 cp850 machine with 8.3 names off, say): cmd.exe couldn't run such a file in any encoding."""
33 line = f'@"{batch_path(python)}" "{batch_path(script)}" %*\n'
34 try:
35 data = line.encode("oem") # the code page cmd.exe reads a batch file with
36 except UnicodeEncodeError:
37 import unittest
38 # Windows' "oem" codec doesn't report a useful position, so name the letters it can't encode here.
39 letters = "".join(sorted({c for c in line if not _encodes(c)}))
40 raise unittest.SkipTest(f"{letters!r} in a path has no 8.3 name and is outside the OEM code page,"
41 " so cmd.exe can't run a batch file that names it; use an ASCII TEMP") from None
42 with open(cmd_path, "wb") as f:
43 f.write(data)
44 return cmd_path