1 | from bx.misc.cdb import * |
---|
2 | from tempfile import NamedTemporaryFile |
---|
3 | |
---|
4 | def test(): |
---|
5 | |
---|
6 | d = {} |
---|
7 | for i in range( 10000 ): |
---|
8 | d[ 'foo' + str( i ) ] = 'bar' + str( i ) |
---|
9 | |
---|
10 | # Open temporary file and get name |
---|
11 | file = NamedTemporaryFile() |
---|
12 | file_name = file.name |
---|
13 | |
---|
14 | # Write cdb to file |
---|
15 | FileCDBDict.to_file( d, file ) |
---|
16 | file.flush() |
---|
17 | |
---|
18 | # Open on disk |
---|
19 | file2 = open( file_name ) |
---|
20 | cdb = FileCDBDict( file2 ) |
---|
21 | |
---|
22 | for key, value in d.iteritems(): |
---|
23 | assert cdb[key] == value |
---|
24 | |
---|
25 | try: |
---|
26 | cdb['notin'] |
---|
27 | assert False, "KeyError was not raised" |
---|
28 | except KeyError, e: |
---|
29 | pass |
---|
30 | |
---|
31 | # Close everything (deletes the temporary file) |
---|
32 | file2.close() |
---|
33 | file.close() |
---|
34 | |
---|