Skip to content

Commit c44d8e5

Browse files
authored
bpo-33901: Better test_dbm_gnu.test_reorganize() fix (GH-7795)
Fix test_dbm_gnu.test_reorganize() on macOS with gdbm 1.15: add a larger value to make sure that the file size changes.
1 parent c7f02a9 commit c44d8e5

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Lib/test/test_dbm_gnu.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,21 @@ def test_reorganize(self):
7272
self.g = gdbm.open(filename, 'c')
7373
size0 = os.path.getsize(filename)
7474

75-
self.g['x'] = 'x' * 10000
75+
# bpo-33901: on macOS with gdbm 1.15, an empty database uses 16 MiB
76+
# and adding an entry of 10,000 B has no effect on the file size.
77+
# Add size0 bytes to make sure that the file size changes.
78+
value_size = max(size0, 10000)
79+
self.g['x'] = 'x' * value_size
7680
size1 = os.path.getsize(filename)
77-
self.assertGreaterEqual(size1, size0)
81+
self.assertGreater(size1, size0)
7882

7983
del self.g['x']
8084
# 'size' is supposed to be the same even after deleting an entry.
8185
self.assertEqual(os.path.getsize(filename), size1)
8286

8387
self.g.reorganize()
8488
size2 = os.path.getsize(filename)
85-
self.assertLessEqual(size2, size1)
89+
self.assertLess(size2, size1)
8690
self.assertGreaterEqual(size2, size0)
8791

8892
def test_context_manager(self):
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
Fix test_dbm_gnu for gdbm 1.15. Using gdbm 1.15, creating a database creates
2-
a file of 16 MiB. Adding a small entry and then modifying the small entry
3-
doesn't change the file size. Modify test_dbm_gnu to be less strict: allow
4-
that the file size doesn't change.
1+
Fix test_dbm_gnu on macOS with gdbm 1.15: add a larger value to make sure that
2+
the file size changes.

0 commit comments

Comments
 (0)