From 2a98fd770a2e35c3c297140ae04d29a955dbbba4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 21 Nov 2007 12:31:38 +0100 Subject: r26077: Import updated TDB bindings. (This used to be commit afe091d92ebb1dc15ae3d8df9a5ba8832933a83c) --- source4/lib/tdb/python/tests/simple.py | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 source4/lib/tdb/python/tests/simple.py (limited to 'source4/lib/tdb/python') 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 +# 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()])) -- cgit