diff options
author | Tim Potter <tpot@samba.org> | 2008-01-06 23:17:55 -0600 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2008-01-06 17:21:02 -0600 |
commit | e45c7ffb800448c41ee0fd69e6ebd87446b116e5 (patch) | |
tree | 4b848308cace264b1aa28e43b8065108809d4bb3 | |
parent | 9d09a06920c2de8c6312f3c0a0280faee65fd432 (diff) | |
download | samba-e45c7ffb800448c41ee0fd69e6ebd87446b116e5.tar.gz samba-e45c7ffb800448c41ee0fd69e6ebd87446b116e5.tar.bz2 samba-e45c7ffb800448c41ee0fd69e6ebd87446b116e5.zip |
r26677: Implement and test iter{keys,values,items} for tdb bindings.
Use tempfile.mkstemp() instead of os.tmpnam() in tests.
(This used to be commit 5c3c131d174ba0f162c210d3e6ca30f2ed2a3ec0)
-rw-r--r-- | source4/lib/tdb/python/tests/simple.py | 23 | ||||
-rw-r--r-- | source4/lib/tdb/tdb.i | 12 |
2 files changed, 32 insertions, 3 deletions
diff --git a/source4/lib/tdb/python/tests/simple.py b/source4/lib/tdb/python/tests/simple.py index 698a77f942..1cc51aea07 100644 --- a/source4/lib/tdb/python/tests/simple.py +++ b/source4/lib/tdb/python/tests/simple.py @@ -8,7 +8,7 @@ import tdb from unittest import TestCase -import os +import os, tempfile class OpenTdbTests(TestCase): @@ -19,7 +19,7 @@ class OpenTdbTests(TestCase): 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.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR) self.assertNotEqual(None, self.tdb) def tearDown(self): @@ -82,6 +82,13 @@ class SimpleTdbTests(TestCase): self.tdb["brainslug"] = "2" self.assertEquals([("bla", "1"), ("brainslug", "2")], self.tdb.items()) + def test_iteritems(self): + self.tdb["bloe"] = "2" + self.tdb["bla"] = "25" + i = self.tdb.iteritems() + self.assertEquals(set([("bla", "25"), ("bloe", "2")]), + set([i.next(), i.next()])) + def test_transaction_cancel(self): self.tdb["bloe"] = "2" self.tdb.transaction_start() @@ -107,11 +114,23 @@ class SimpleTdbTests(TestCase): self.tdb["bla"] = "25" self.assertEquals(["bla", "bloe"], self.tdb.keys()) + 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_values(self): self.tdb["bloe"] = "2" self.tdb["bla"] = "25" self.assertEquals(["25", "2"], self.tdb.values()) + def test_itervalues(self): + self.tdb["bloe"] = "2" + self.tdb["bla"] = "25" + i = self.tdb.itervalues() + self.assertEquals(set(["25", "2"]), set([i.next(), i.next()])) + def test_clear(self): self.tdb["bloe"] = "2" self.tdb["bla"] = "25" diff --git a/source4/lib/tdb/tdb.i b/source4/lib/tdb/tdb.i index 5e928941de..c82d2d0a6d 100644 --- a/source4/lib/tdb/tdb.i +++ b/source4/lib/tdb/tdb.i @@ -263,7 +263,17 @@ typedef struct tdb_context { for k in iter(self): del(self[k]) - # TODO: iterkeys, itervalues, iteritems + def iterkeys(self): + for k in iter(self): + yield k + + def itervalues(self): + for k in iter(self): + yield self[k] + + def iteritems(self): + for k in iter(self): + yield (k, self[k]) # TODO: any other missing methods for container types } |