File: test_wsgilib.py

package info (click to toggle)
paste 2.0.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,396 kB
  • ctags: 2,615
  • sloc: python: 18,659; makefile: 17; sh: 7
file content (52 lines) | stat: -rw-r--r-- 1,003 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from paste.wsgilib import add_close


def app_iterable_func_bytes():
    yield b'a'
    yield b'b'
    yield b'c'


def app_iterable_func_unicode():
    yield b'a'.decode('ascii')
    yield b'b'.decode('ascii')
    yield b'c'.decode('ascii')


def close_func():
    global close_func_called
    close_func_called = True


def test_add_close_bytes():
    global close_func_called

    close_func_called = False
    lst = []
    app_iterable = app_iterable_func_bytes()

    obj = add_close(app_iterable, close_func)
    for x in obj:
        lst.append(x)
    obj.close()

    assert lst == [b'a', b'b', b'c']
    assert close_func_called
    assert obj._closed


def test_add_close_unicode():
    global close_func_called

    close_func_called = False
    lst = []
    app_iterable = app_iterable_func_unicode()

    obj = add_close(app_iterable, close_func)
    for x in obj:
        lst.append(x)
    obj.close()

    assert lst == ['a', 'b', 'c']
    assert close_func_called
    assert obj._closed