File: test_extensions.py

package info (click to toggle)
python-wsproto 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: python: 3,840; makefile: 17
file content (54 lines) | stat: -rw-r--r-- 1,630 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
53
54
from __future__ import annotations

from typing import Union

from wsproto import extensions as wpext
from wsproto import frame_protocol as fp


class ConcreteExtension(wpext.Extension):
    def offer(self) -> Union[bool, str]:
        return "myext"


class TestExtension:
    def test_enabled(self) -> None:
        ext = ConcreteExtension()
        assert not ext.enabled()

    def test_offer(self) -> None:
        ext = ConcreteExtension()
        assert ext.offer() == "myext"

    def test_accept(self) -> None:
        ext = ConcreteExtension()
        offer = "myext"
        assert ext.accept(offer) is None

    def test_finalize(self) -> None:
        ext = ConcreteExtension()
        offer = "myext"
        ext.finalize(offer)

    def test_frame_inbound_header(self) -> None:
        ext = ConcreteExtension()
        result = ext.frame_inbound_header(None, None, None, None)  # type: ignore[arg-type]
        assert result == fp.RsvBits(False, False, False)

    def test_frame_inbound_payload_data(self) -> None:
        ext = ConcreteExtension()
        data = b""
        assert ext.frame_inbound_payload_data(None, data) == data  # type: ignore[arg-type]

    def test_frame_inbound_complete(self) -> None:
        ext = ConcreteExtension()
        assert ext.frame_inbound_complete(None, None) is None  # type: ignore[arg-type]

    def test_frame_outbound(self) -> None:
        ext = ConcreteExtension()
        rsv = fp.RsvBits(True, True, True)
        data = b""
        assert ext.frame_outbound(None, None, rsv, data, None) == (  # type: ignore[arg-type]
            rsv,
            data,
        )