File: test_len_leak.py

package info (click to toggle)
python-pybedtools 0.8.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,140 kB
  • sloc: python: 9,589; cpp: 899; makefile: 149; sh: 116
file content (60 lines) | stat: -rw-r--r-- 1,423 bytes parent folder | download | duplicates (2)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pybedtools

fn = pybedtools.example_filename('a.bed')


def show_open_fds(func):
    doc = func.__doc__
    print()
    print(doc)
    print("." * len(doc))
    orig_fds = pybedtools.helpers.n_open_fds()
    obs = max(func(fn)) - orig_fds
    assert obs == 0, obs


def func1(src):
    "create bedtool in loop"
    for i in range(10):
        x = pybedtools.BedTool(src)
        yield pybedtools.helpers.n_open_fds()


def func2(src):
    'create bedtool in loop and check length'
    for i in range(10):
        x = pybedtools.BedTool(src)
        len(x)
        yield pybedtools.helpers.n_open_fds()


def func3(src):
    'create bedtool outside of loop; check length inside'
    x = pybedtools.BedTool(src)
    for i in range(10):
        len(x)
        yield pybedtools.helpers.n_open_fds()


def func4(src):
    'create and len in loop; don\'t assign to var'
    for i in range(10):
        len(pybedtools.BedTool(src))
        yield pybedtools.helpers.n_open_fds()


def func0(src):
    'check field count'
    x = pybedtools.BedTool(src)
    for i in range(10):
        # since the test file is only 4 lines, set `n` to make sure we're
        # not exhausting the iterator.
        fc = x.field_count(n=2)
        assert fc == 6
        yield pybedtools.helpers.n_open_fds()


if __name__ == "__main__":
    for k, v in sorted(locals().items()):
        if k.startswith('func'):
            show_open_fds(v)