File: cdb_tests.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (34 lines) | stat: -rw-r--r-- 696 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from tempfile import NamedTemporaryFile

from bx.misc.cdb import FileCDBDict


def test():
    d = {}
    for i in range(10000):
        d["foo" + str(i)] = "bar" + str(i)

    # Open temporary file and get name
    file = NamedTemporaryFile()
    file_name = file.name

    # Write cdb to file
    FileCDBDict.to_file(d, file)
    file.flush()

    # Open on disk
    file2 = open(file_name, "rb")
    cdb = FileCDBDict(file2)

    for key, value in d.items():
        assert cdb[key] == value

    try:
        cdb["notin"]
        assert False, "KeyError was not raised"
    except KeyError:
        pass

    # Close everything (deletes the temporary file)
    file2.close()
    file.close()