Skip to content

Commit 1d6d33c

Browse files
gh-152260: Fix test_scr_dump() on macOS (GH-152340)
The dump format embeds raw pointers on some platforms, so two dumps of the same screen are not always byte-identical. Only compare dump files when the format proves deterministic. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bbf7786 commit 1d6d33c

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

Lib/test/test_curses.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,21 +1129,27 @@ def test_scr_dump(self):
11291129
with tempfile.TemporaryDirectory() as d:
11301130
dump = os.path.join(d, 'dump')
11311131
self.assertIsNone(curses.scr_dump(dump))
1132-
# Dumping the same screen again is deterministic.
1132+
with open(dump, 'rb') as f:
1133+
image = f.read()
1134+
self.assertTrue(image)
1135+
# The dump format embeds raw pointers on some platforms (such as
1136+
# macOS), so two dumps of the same screen are not always identical.
1137+
# Only compare dump files when the format proves deterministic.
11331138
dump2 = os.path.join(d, 'dump2')
11341139
curses.scr_dump(dump2)
1135-
with open(dump, 'rb') as f1, open(dump2, 'rb') as f2:
1136-
self.assertEqual(f1.read(), f2.read())
1140+
with open(dump2, 'rb') as f:
1141+
deterministic = f.read() == image
11371142
# scr_restore() reloads that virtual screen, so dumping it again
11381143
# reproduces the original file even after the screen has changed.
11391144
stdscr.erase()
11401145
stdscr.addstr(0, 0, 'something else')
11411146
stdscr.refresh()
11421147
self.assertIsNone(curses.scr_restore(dump))
1143-
restored = os.path.join(d, 'restored')
1144-
curses.scr_dump(restored)
1145-
with open(dump, 'rb') as f1, open(restored, 'rb') as f2:
1146-
self.assertEqual(f1.read(), f2.read())
1148+
if deterministic:
1149+
restored = os.path.join(d, 'restored')
1150+
curses.scr_dump(restored)
1151+
with open(restored, 'rb') as f:
1152+
self.assertEqual(f.read(), image)
11471153
# scr_init() and scr_set() accept a dump file and return None.
11481154
self.assertIsNone(curses.scr_init(dump))
11491155
self.assertIsNone(curses.scr_set(dump))

0 commit comments

Comments
 (0)