Skip to content

Commit 6fb258e

Browse files
gh-155207: Fix the dry run tests on Windows
The path of the default destination file is built from the "{dirname}/clinic/{basename}.h" template, so it always uses forward slashes, unlike os.path.join(). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 40894ce commit 6fb258e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/test/test_clinic.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,14 @@ def make_dry_run_file(self, tmp_dir):
30593059
f.write(self.DRY_RUN_CODE)
30603060
return fn
30613061

3062+
@staticmethod
3063+
def dest_file(fn):
3064+
# The default destination for the generated code. Its path is
3065+
# built from the "{dirname}/clinic/{basename}.h" template, so it
3066+
# always uses forward slashes, even on Windows.
3067+
dirname, basename = os.path.split(fn)
3068+
return f"{dirname}/clinic/{basename}.h"
3069+
30623070
def check_unchanged(self, tmp_dir, fn, pre_mtime):
30633071
# Neither the source file nor the destination file
30643072
# nor its directory is created or modified.
@@ -3073,7 +3081,7 @@ def test_cli_dry_run(self):
30733081
pre_mtime = os.stat(fn).st_mtime_ns
30743082
out = self.expect_success("--dry-run", fn)
30753083
self.assertEqual(out.splitlines(), [
3076-
f"would create {os.path.join(tmp_dir, 'clinic', 'test.c.h')}",
3084+
f"would create {self.dest_file(fn)}",
30773085
f"would update {fn}",
30783086
])
30793087
self.check_unchanged(tmp_dir, fn, pre_mtime)
@@ -3118,7 +3126,7 @@ def test_cli_dry_run_verbose(self):
31183126
# contains only the report.
31193127
self.assertEqual(err.splitlines(), [fn])
31203128
self.assertEqual(out.splitlines(), [
3121-
f"would create {os.path.join(tmp_dir, 'clinic', 'test.c.h')}",
3129+
f"would create {self.dest_file(fn)}",
31223130
f"would update {fn}",
31233131
])
31243132

@@ -3155,7 +3163,7 @@ def test_cli_diff(self):
31553163
self.check_unchanged(tmp_dir, fn, pre_mtime)
31563164

31573165
# A new file is created by the patch.
3158-
dest_fn = os.path.join(tmp_dir, "clinic", "test.c.h")
3166+
dest_fn = self.dest_file(fn)
31593167
self.assertStartsWith(out, f"--- /dev/null\n+++ {dest_fn}\n@@ -0,0 +1,")
31603168
self.assertIn(f"--- {fn}\n+++ {fn}\n", out)
31613169
self.assertIn("+/*[clinic end generated code:", out)

0 commit comments

Comments
 (0)