mirror of
https://github.com/samba-team/samba.git
synced 2025-06-21 03:17:08 +03:00
The reason I do it is that when using older python-tdb as shipped in Debian Lenny, python interpreter crashes on this test: (gdb) bt #0 0xb7f8c424 in __kernel_vsyscall () #1 0xb7df5640 in raise () from /lib/i686/cmov/libc.so.6 #2 0xb7df7018 in abort () from /lib/i686/cmov/libc.so.6 #3 0xb7e3234d in __libc_message () from /lib/i686/cmov/libc.so.6 #4 0xb7e38624 in malloc_printerr () from /lib/i686/cmov/libc.so.6 #5 0xb7e3a826 in free () from /lib/i686/cmov/libc.so.6 #6 0xb7b39c84 in tdb_close () from /usr/lib/libtdb.so.1 #7 0xb7b43e14 in ?? () from /var/lib/python-support/python2.5/_tdb.so #8 0x0a038d08 in ?? () #9 0x00000000 in ?? () master's pytdb does not (we have a check for self->closed in obj_close()), but still... Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
134 lines
3.7 KiB
Python
134 lines
3.7 KiB
Python
#!/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-2008 Jelmer Vernooij <jelmer@samba.org>
|
|
# Published under the GNU LGPLv3 or later
|
|
|
|
import tdb
|
|
from unittest import TestCase
|
|
import os, tempfile
|
|
|
|
|
|
class OpenTdbTests(TestCase):
|
|
def test_nonexistant_read(self):
|
|
self.assertRaises(IOError, tdb.Tdb, "/some/nonexistant/file", 0, tdb.DEFAULT, os.O_RDWR)
|
|
|
|
class CloseTdbTests(TestCase):
|
|
def test_double_close(self):
|
|
self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR)
|
|
self.assertNotEqual(None, self.tdb)
|
|
|
|
# ensure that double close does not crash python
|
|
self.tdb.close()
|
|
self.tdb.close()
|
|
|
|
|
|
class SimpleTdbTests(TestCase):
|
|
def setUp(self):
|
|
super(SimpleTdbTests, self).setUp()
|
|
self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR)
|
|
self.assertNotEqual(None, self.tdb)
|
|
|
|
def tearDown(self):
|
|
del self.tdb
|
|
|
|
def test_repr(self):
|
|
self.assertTrue(repr(self.tdb).startswith("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.get("bar"))
|
|
|
|
def test_getitem(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.filename
|
|
|
|
def test_iterator(self):
|
|
self.tdb["bla"] = "1"
|
|
self.tdb["brainslug"] = "2"
|
|
self.assertEquals(["bla", "brainslug"], list(self.tdb))
|
|
|
|
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()]))
|
|
|
|
def test_iterkeys(self):
|
|
self.tdb["bloe"] = "2"
|
|
self.tdb["bla"] = "25"
|
|
i = self.tdb.iterkeys()
|
|
self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()]))
|
|
|
|
def test_clear(self):
|
|
self.tdb["bloe"] = "2"
|
|
self.tdb["bla"] = "25"
|
|
self.assertEquals(2, len(list(self.tdb)))
|
|
self.tdb.clear()
|
|
self.assertEquals(0, len(list(self.tdb)))
|
|
|
|
def test_len(self):
|
|
self.assertEquals(0, len(list(self.tdb)))
|
|
self.tdb["entry"] = "value"
|
|
self.assertEquals(1, len(list(self.tdb)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import unittest
|
|
unittest.TestProgram()
|