File: test_wsgilib.py

package info (click to toggle)
paste 3.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,472 kB
  • sloc: python: 19,960; javascript: 8,028; makefile: 47; sh: 24
file content (41 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (4)
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
import pytest

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


@pytest.mark.parametrize("app_iterable_func,expected", [
    (app_iterable_func_bytes, [b'a', b'b', b'c']),
    (app_iterable_func_unicode, ['a', 'b', 'c']),
])
def test_add_close(app_iterable_func, expected):
    global close_func_called

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

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

    assert lst == expected
    assert close_func_called
    assert obj._closed