root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/bx/misc/cdb_tests.py

リビジョン 3, 0.7 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1from bx.misc.cdb import *
2from tempfile import NamedTemporaryFile
3
4def 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   
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。