diff options
author | Tim Potter <tpot@samba.org> | 2006-04-02 01:56:22 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:59:43 -0500 |
commit | e29489d9b6c9089d63667541bb8cff4637089d75 (patch) | |
tree | a07409e7851c0ce634b6004a0885686090ae49d9 /source4/scripting/swig/torture | |
parent | 0bc6e7a090dd92465d905ffb0a2530d67d0bcc9c (diff) | |
download | samba-e29489d9b6c9089d63667541bb8cff4637089d75.tar.gz samba-e29489d9b6c9089d63667541bb8cff4637089d75.tar.bz2 samba-e29489d9b6c9089d63667541bb8cff4637089d75.zip |
r14854: Finish off swig wrapper and torture tests for tdb.
(This used to be commit 1c4042e23f3e99f95133313607e2c2904503cf74)
Diffstat (limited to 'source4/scripting/swig/torture')
-rwxr-xr-x | source4/scripting/swig/torture/torture_tdb.py | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/source4/scripting/swig/torture/torture_tdb.py b/source4/scripting/swig/torture/torture_tdb.py index d9ca4dedba..59eb5fe1f0 100755 --- a/source4/scripting/swig/torture/torture_tdb.py +++ b/source4/scripting/swig/torture/torture_tdb.py @@ -1,6 +1,82 @@ #!/usr/bin/python -import Tdb, os +import sys, os +import Tdb -t = Tdb.Tdb('foo.tdb') -os.unlink('foo.tdb') +def fail(msg): + print 'FAILED:', msg + sys.exit(1) + +tdb_file = '/tmp/torture_tdb.tdb' + +# Create temporary tdb file + +t = Tdb.Tdb(tdb_file, flags = Tdb.CLEAR_IF_FIRST) + +# Check non-existent key throws KeyError exception + +try: + t['__none__'] +except KeyError: + pass +else: + fail('non-existent key did not throw KeyError') + +# Check storing key + +t['bar'] = '1234' +if t['bar'] != '1234': + fail('store key failed') + +# Check key exists + +if not t.has_key('bar'): + fail('has_key() failed for existing key') + +if t.has_key('__none__'): + fail('has_key() succeeded for non-existent key') + +# Delete key + +try: + del(t['__none__']) +except KeyError: + pass +else: + fail('delete of non-existent key did not throw KeyError') + +del t['bar'] +if t.has_key('bar'): + fail('delete of existing key did not delete key') + +# Clear all keys + +t.clear() +if len(t) != 0: + fail('clear failed to remove all keys') + +# Other dict functions + +t['a'] = '1' +t['ab'] = '12' +t['abc'] = '123' + +if len(t) != 3: + fail('len method produced wrong value') + +keys = t.keys() +values = t.values() +items = t.items() + +if set(keys) != set(['a', 'ab', 'abc']): + fail('keys method produced wrong values') + +if set(values) != set(['1', '12', '123']): + fail('values method produced wrong values') + +if set(items) != set([('a', '1'), ('ab', '12'), ('abc', '123')]): + fail('values method produced wrong values') + +# Clean up + +os.unlink(tdb_file) |