~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/scripting/python/samba/torture/torture_tdb.py

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys, os
 
4
import Tdb
 
5
 
 
6
def fail(msg):
 
7
    print 'FAILED:', msg
 
8
    sys.exit(1)
 
9
 
 
10
tdb_file = '/tmp/torture_tdb.tdb'
 
11
 
 
12
# Create temporary tdb file
 
13
 
 
14
t = Tdb.Tdb(tdb_file, flags = Tdb.CLEAR_IF_FIRST)
 
15
 
 
16
# Check non-existent key throws KeyError exception
 
17
 
 
18
try:
 
19
    t['__none__']
 
20
except KeyError:
 
21
    pass
 
22
else:
 
23
    fail('non-existent key did not throw KeyError')
 
24
 
 
25
# Check storing key
 
26
 
 
27
t['bar'] = '1234'
 
28
if t['bar'] != '1234':
 
29
    fail('store key failed')
 
30
 
 
31
# Check key exists
 
32
 
 
33
if not t.has_key('bar'):
 
34
    fail('has_key() failed for existing key')
 
35
 
 
36
if t.has_key('__none__'):
 
37
    fail('has_key() succeeded for non-existent key')
 
38
 
 
39
# Delete key
 
40
 
 
41
try:
 
42
    del(t['__none__'])
 
43
except KeyError:
 
44
    pass
 
45
else:
 
46
    fail('delete of non-existent key did not throw KeyError')
 
47
 
 
48
del t['bar']
 
49
if t.has_key('bar'):
 
50
    fail('delete of existing key did not delete key')
 
51
 
 
52
# Clear all keys
 
53
 
 
54
t.clear()
 
55
if len(t) != 0:
 
56
    fail('clear failed to remove all keys')
 
57
 
 
58
# Other dict functions
 
59
 
 
60
t['a'] = '1'
 
61
t['ab'] = '12'
 
62
t['abc'] = '123'
 
63
 
 
64
if len(t) != 3:
 
65
    fail('len method produced wrong value')
 
66
 
 
67
keys = t.keys()
 
68
values = t.values()
 
69
items = t.items()
 
70
 
 
71
if set(keys) != set(['a', 'ab', 'abc']):
 
72
    fail('keys method produced wrong values')
 
73
 
 
74
if set(values) != set(['1', '12', '123']):
 
75
    fail('values method produced wrong values')
 
76
 
 
77
if set(items) != set([('a', '1'), ('ab', '12'), ('abc', '123')]):
 
78
    fail('values method produced wrong values')
 
79
 
 
80
t.close()
 
81
 
 
82
# Re-open read-only
 
83
 
 
84
t = Tdb.Tdb(tdb_file, open_flags = os.O_RDONLY)
 
85
t.keys()
 
86
t.close()
 
87
 
 
88
# Clean up
 
89
 
 
90
os.unlink(tdb_file)