summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/python/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-11-21 12:31:38 +0100
committerStefan Metzmacher <metze@samba.org>2007-12-21 05:45:55 +0100
commit2a98fd770a2e35c3c297140ae04d29a955dbbba4 (patch)
treea817e13408510a5d50fcede4fe852e85169c640a /source4/lib/tdb/python/tests
parentd3a13a16fff6e9a9929109a37f04a0a8e91d82b7 (diff)
downloadsamba-2a98fd770a2e35c3c297140ae04d29a955dbbba4.tar.gz
samba-2a98fd770a2e35c3c297140ae04d29a955dbbba4.tar.bz2
samba-2a98fd770a2e35c3c297140ae04d29a955dbbba4.zip
r26077: Import updated TDB bindings.
(This used to be commit afe091d92ebb1dc15ae3d8df9a5ba8832933a83c)
Diffstat (limited to 'source4/lib/tdb/python/tests')
-rw-r--r--source4/lib/tdb/python/tests/simple.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/source4/lib/tdb/python/tests/simple.py b/source4/lib/tdb/python/tests/simple.py
new file mode 100644
index 0000000000..43d066c4a3
--- /dev/null
+++ b/source4/lib/tdb/python/tests/simple.py
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+# Some simple tests for the Python bindings for TDB
+# Note that this tests the interface of the Python bindings
+# It does not test tdb itself.
+#
+# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
+# Published under the GNU LGPL
+
+import tdb
+from unittest import TestCase
+import os
+
+class SimpleTdbTests(TestCase):
+ def setUp(self):
+ super(SimpleTdbTests, self).setUp()
+ self.tdb = tdb.Tdb(os.tmpnam(), 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR)
+ self.assertNotEqual(None, self.tdb)
+
+ def tearDown(self):
+ del self.tdb
+
+ def test_lockall(self):
+ self.tdb.lock_all()
+
+ def test_max_dead(self):
+ self.tdb.max_dead = 20
+
+ def test_unlockall(self):
+ self.tdb.lock_all()
+ self.tdb.unlock_all()
+
+ def test_lockall_read(self):
+ self.tdb.read_lock_all()
+ self.tdb.read_unlock_all()
+
+ def test_reopen(self):
+ self.tdb.reopen()
+
+ def test_store(self):
+ self.tdb.store("bar", "bla")
+ self.assertEquals("bla", self.tdb.fetch("bar"))
+
+ def test_fetch(self):
+ self.tdb["bar"] = "foo"
+ self.tdb.reopen()
+ self.assertEquals("foo", self.tdb["bar"])
+
+ def test_delete(self):
+ self.tdb["bar"] = "foo"
+ del self.tdb["bar"]
+ self.assertRaises(KeyError, lambda: self.tdb["bar"])
+
+ def test_contains(self):
+ self.tdb["bla"] = "bloe"
+ self.assertTrue("bla" in self.tdb)
+
+ def test_keyerror(self):
+ self.assertRaises(KeyError, lambda: self.tdb["bla"])
+
+ def test_hash_size(self):
+ self.tdb.hash_size
+
+ def test_map_size(self):
+ self.tdb.map_size
+
+ def test_name(self):
+ self.tdb.name
+
+ def test_iterator(self):
+ self.tdb["bla"] = "1"
+ self.tdb["brainslug"] = "2"
+ self.assertEquals(["bla", "brainslug"], list(self.tdb))
+
+ def test_items(self):
+ self.tdb["bla"] = "1"
+ self.tdb["brainslug"] = "2"
+ self.assertEquals([("bla", "1"), ("brainslug", "2")], self.tdb.items())
+
+ def test_transaction_cancel(self):
+ self.tdb["bloe"] = "2"
+ self.tdb.transaction_start()
+ self.tdb["bloe"] = "1"
+ self.tdb.transaction_cancel()
+ self.assertEquals("2", self.tdb["bloe"])
+
+ def test_transaction_commit(self):
+ self.tdb["bloe"] = "2"
+ self.tdb.transaction_start()
+ self.tdb["bloe"] = "1"
+ self.tdb.transaction_commit()
+ self.assertEquals("1", self.tdb["bloe"])
+
+ def test_iterator(self):
+ self.tdb["bloe"] = "2"
+ self.tdb["bla"] = "hoi"
+ i = iter(self.tdb)
+ self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()]))