File: test_boundedstream.py

package info (click to toggle)
python-falcon 4.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 33,608; javascript: 92; sh: 50; makefile: 50
file content (29 lines) | stat: -rw-r--r-- 725 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
import io

import pytest

from falcon.stream import BoundedStream
from falcon.util.deprecation import DeprecatedWarning


@pytest.fixture
def bounded_stream():
    return BoundedStream(io.BytesIO(), 1024)


def test_not_writable(bounded_stream):
    assert not bounded_stream.writable()

    with pytest.raises(IOError):
        bounded_stream.write(b'something something')


def test_exhausted():
    bs = BoundedStream(io.BytesIO(b'foobar'), 6)
    assert not bs.eof
    with pytest.warns(DeprecatedWarning, match='Use `eof` instead'):
        assert not bs.is_exhausted
    assert bs.read() == b'foobar'
    assert bs.eof
    with pytest.warns(DeprecatedWarning, match='Use `eof` instead'):
        assert bs.is_exhausted