diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..9e85c0a --- /dev/null +++ b/examples/README.md @@ -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. diff --git a/examples/batch_write_wide_columns.py b/examples/batch_write_wide_columns.py index abab787..2b8e8b8 100644 --- a/examples/batch_write_wide_columns.py +++ b/examples/batch_write_wide_columns.py @@ -62,5 +62,6 @@ ] ) +test_dict.close() del write_batch, it, default_cf_handle, test_dict Rdict.destroy(path, opt) diff --git a/examples/checkpoint.py b/examples/checkpoint.py index 3607919..fda9a40 100644 --- a/examples/checkpoint.py +++ b/examples/checkpoint.py @@ -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) diff --git a/examples/checkpoint_raw.py b/examples/checkpoint_raw.py index 7c425a8..374693f 100644 --- a/examples/checkpoint_raw.py +++ b/examples/checkpoint_raw.py @@ -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) diff --git a/examples/snapshot.py b/examples/snapshot.py index 32779d1..b35c96b 100644 --- a/examples/snapshot.py +++ b/examples/snapshot.py @@ -22,6 +22,7 @@ assert snapshot[i] == i # drop the snapshot +db.close() del snapshot, db Rdict.destroy("tmp") diff --git a/examples/sst_file_write.py b/examples/sst_file_write.py index 105cbc1..5425081 100644 --- a/examples/sst_file_write.py +++ b/examples/sst_file_write.py @@ -38,5 +38,5 @@ count += 1 # auto flush -del db +db.close() rd.Rdict.destroy("test") diff --git a/examples/wide_columns.py b/examples/wide_columns.py index edbf40a..5bc87d4 100644 --- a/examples/wide_columns.py +++ b/examples/wide_columns.py @@ -50,6 +50,6 @@ ] assert [c for c in test_dict.columns()] == all_columns -del test_dict +test_dict.close() Rdict.destroy(path) diff --git a/examples/wide_columns_raw.py b/examples/wide_columns_raw.py index 6c16020..a996d25 100644 --- a/examples/wide_columns_raw.py +++ b/examples/wide_columns_raw.py @@ -50,6 +50,6 @@ ] assert [c for c in test_dict.columns()] == all_columns -del test_dict +test_dict.close() Rdict.destroy(path) diff --git a/test/test_rdict.py b/test/test_rdict.py index 0828194..96fa1f3 100644 --- a/test/test_rdict.py +++ b/test/test_rdict.py @@ -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()) @@ -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()) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -799,7 +806,6 @@ def test_column_families(self): @classmethod def tearDownClass(cls): - del cls.test_dict gc.collect() Rdict.destroy(cls.path) @@ -844,7 +850,6 @@ def test_column_families_create(self): @classmethod def tearDownClass(cls): - del cls.test_dict gc.collect() Rdict.destroy(cls.path) @@ -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) @@ -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) @@ -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) @@ -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) @@ -1185,7 +1187,7 @@ 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))]) @@ -1193,14 +1195,13 @@ def test_create_checkpoint(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) - gc.collect() Rdict.destroy(cls.checkpoint_path, cls.opt) if __name__ == "__main__": unittest.main() -