Skip to content

Commit

Permalink
use close instead of del in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Congyuwang committed Nov 1, 2024
1 parent 7f56149 commit 5766b58
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 24 deletions.
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Examples

The examples all work on CPython.

For PyPy, take care about reference counting and garbage collection
to ensure that database is released before reopening or destroying.
1 change: 1 addition & 0 deletions examples/batch_write_wide_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
]
)

test_dict.close()
del write_batch, it, default_cf_handle, test_dict
Rdict.destroy(path, opt)
2 changes: 1 addition & 1 deletion examples/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_checkpoint_example():
assert checkpoint_dict[i] == i * i

checkpoint_dict.close()
del test_dict
test_dict.close()

# Cleanup
Rdict.destroy(path, opt)
Expand Down
2 changes: 1 addition & 1 deletion examples/checkpoint_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run_checkpoint_raw_example():
assert entity == [(b"value", bytes(i * i))]

checkpoint_dict.close()
del test_dict
test_dict.close()

# Cleanup
Rdict.destroy(path, opt)
Expand Down
1 change: 1 addition & 0 deletions examples/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
assert snapshot[i] == i

# drop the snapshot
db.close()
del snapshot, db

Rdict.destroy("tmp")
2 changes: 1 addition & 1 deletion examples/sst_file_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
count += 1

# auto flush
del db
db.close()
rd.Rdict.destroy("test")
2 changes: 1 addition & 1 deletion examples/wide_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
]
assert [c for c in test_dict.columns()] == all_columns

del test_dict
test_dict.close()

Rdict.destroy(path)
2 changes: 1 addition & 1 deletion examples/wide_columns_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
]
assert [c for c in test_dict.columns()] == all_columns

del test_dict
test_dict.close()

Rdict.destroy(path)
39 changes: 20 additions & 19 deletions test/test_rdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def testDelItem(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
gc.collect()
Rdict.destroy(cls.path, Options())

Expand Down Expand Up @@ -105,7 +106,8 @@ def testDelItem(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
gc.collect()
Rdict.destroy(cls.path, Options())

Expand Down Expand Up @@ -359,7 +361,8 @@ def test_big_int(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
Expand Down Expand Up @@ -527,7 +530,8 @@ def test_string(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
Expand Down Expand Up @@ -603,7 +607,8 @@ def test_put_wide_columns(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
Expand Down Expand Up @@ -682,7 +687,8 @@ def test_put_wide_columns(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
Expand Down Expand Up @@ -757,7 +763,8 @@ def test_put_wide_columns(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
Expand Down Expand Up @@ -799,7 +806,6 @@ def test_column_families(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
gc.collect()
Rdict.destroy(cls.path)

Expand Down Expand Up @@ -844,7 +850,6 @@ def test_column_families_create(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
gc.collect()
Rdict.destroy(cls.path)

Expand Down Expand Up @@ -891,7 +896,6 @@ def test_column_families_custom_options_auto_reopen(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
gc.collect()
Rdict.destroy(cls.path)

Expand Down Expand Up @@ -941,7 +945,6 @@ def test_column_families_custom_options_auto_reopen(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
gc.collect()
Rdict.destroy(cls.path)

Expand Down Expand Up @@ -1015,7 +1018,6 @@ def test_column_families_custom_options_auto_reopen_override(self):

@classmethod
def tearDownClass(cls):
del cls.test_dict
gc.collect()
Rdict.destroy(cls.path)

Expand Down Expand Up @@ -1142,18 +1144,18 @@ def test_create_checkpoint(self):

# Verify the checkpoint data
for i in range(1000):
self.assertIn(i, checkpoint_dict)
self.assertTrue(i in checkpoint_dict)
self.assertEqual(checkpoint_dict[i], i * i)

checkpoint_dict.close()

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
assert cls.opt is not None
cls.test_dict.close()
gc.collect()
Rdict.destroy(cls.path, cls.opt)
gc.collect()
Rdict.destroy(cls.checkpoint_path, cls.opt)


Expand Down Expand Up @@ -1185,22 +1187,21 @@ def test_create_checkpoint(self):

# Verify the checkpoint data
for i in range(1000):
self.assertIn(bytes(i), checkpoint_dict)
self.assertTrue(bytes(i) in checkpoint_dict)
entity = checkpoint_dict.get_entity(bytes(i))
self.assertEqual(entity, [(b"value", bytes(i * i))])

checkpoint_dict.close()

@classmethod
def tearDownClass(cls):
del cls.test_dict
assert cls.test_dict is not None
cls.test_dict.close()
assert cls.opt is not None
gc.collect()
Rdict.destroy(cls.path, cls.opt)
gc.collect()
Rdict.destroy(cls.checkpoint_path, cls.opt)


if __name__ == "__main__":
unittest.main()

0 comments on commit 5766b58

Please sign in to comment.