Skip to content

Commit bcdf419

Browse files
committed
add test for new Stream.end_stream exception behaviour
1 parent 700990e commit bcdf419

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ dev
88

99
- Support for Python 3.9 has been removed.
1010
- Support for PyPy 3.9 has been removed.
11+
- `Stream.end_stream()` now raises `NoSuchStreamError` or `StreamClosedError` exceptions, instead of a generic `KeyError`.
1112
- **backfill from v4.3.0** Convert emitted events into Python `dataclass`, which introduces new constructors with required arguments.
1213
Instantiating these events without arguments, as previously commonly used API pattern, will no longer work.
1314

14-
1515
**API Changes (Backward Compatible)**
1616

1717
- Support for Python 3.14 has been added.

tests/test_basic_logic.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,23 @@ def test_end_stream_without_data(self, frame_factory) -> None:
340340
assert not events
341341
assert c.data_to_send() == f.serialize()
342342

343+
def test_end_stream_exceptions(self, frame_factory) -> None:
344+
c = h2.connection.H2Connection()
345+
c.initiate_connection()
346+
c.send_headers(1, self.example_request_headers, end_stream=False)
347+
c.clear_outbound_data_buffer()
348+
349+
with pytest.raises(h2.exceptions.NoSuchStreamError):
350+
c.end_stream(42)
351+
352+
c.end_stream(1)
353+
354+
c.send_headers(5, self.example_request_headers, end_stream=False)
355+
356+
with pytest.raises(h2.exceptions.StreamClosedError):
357+
c.end_stream(3)
358+
359+
343360
def test_cannot_send_headers_on_lower_stream_id(self) -> None:
344361
"""
345362
Once stream ID x has been used, cannot use stream ID y where y < x.

0 commit comments

Comments
 (0)