4
4
import struct
5
5
from binascii import unhexlify
6
6
from codecs import getincrementaldecoder
7
- from typing import Optional , Tuple , Union
7
+ from typing import Dict , Optional , Tuple , Union
8
8
9
9
import pytest
10
10
@@ -98,7 +98,6 @@ def test_follow_on_binary_frame(self) -> None:
98
98
payload = b"x" * 23
99
99
decoder = fp .MessageDecoder ()
100
100
decoder .opcode = fp .Opcode .BINARY
101
- decoder .seen_first_frame = True # type: ignore
102
101
frame = fp .Frame (
103
102
opcode = fp .Opcode .CONTINUATION ,
104
103
payload = payload ,
@@ -132,7 +131,6 @@ def test_follow_on_text_frame(self) -> None:
132
131
binary_payload = text_payload .encode ("utf8" )
133
132
decoder = fp .MessageDecoder ()
134
133
decoder .opcode = fp .Opcode .TEXT
135
- decoder .seen_first_frame = True # type: ignore
136
134
decoder .decoder = getincrementaldecoder ("utf-8" )()
137
135
138
136
assert decoder .decoder .decode (binary_payload [:4 ]) == text_payload [:2 ]
@@ -156,7 +154,6 @@ def test_final_text_frame(self) -> None:
156
154
binary_payload = text_payload .encode ("utf8" )
157
155
decoder = fp .MessageDecoder ()
158
156
decoder .opcode = fp .Opcode .TEXT
159
- decoder .seen_first_frame = True # type: ignore
160
157
decoder .decoder = getincrementaldecoder ("utf-8" )()
161
158
162
159
assert decoder .decoder .decode (binary_payload [:- 2 ]) == text_payload [:- 1 ]
@@ -192,7 +189,6 @@ def test_missing_continuation_1(self) -> None:
192
189
payload = b"x" * 23
193
190
decoder = fp .MessageDecoder ()
194
191
decoder .opcode = fp .Opcode .BINARY
195
- decoder .seen_first_frame = True # type: ignore
196
192
frame = fp .Frame (
197
193
opcode = fp .Opcode .BINARY ,
198
194
payload = payload ,
@@ -887,21 +883,21 @@ def test_outbound_handling_single_frame(self) -> None:
887
883
proto = fp .FrameProtocol (client = False , extensions = [ext ])
888
884
payload = "😃😄🙃😉"
889
885
data = proto .send_data (payload , fin = True )
890
- payload = (payload + "®" ).encode ("utf8" ) # type: ignore
891
- assert data == b"\x91 " + bytearray ([len (payload )]) + payload # type: ignore
886
+ payload_bytes = (payload + "®" ).encode ("utf8" )
887
+ assert data == b"\x91 " + bytearray ([len (payload_bytes )]) + payload_bytes
892
888
893
889
def test_outbound_handling_multiple_frames (self ) -> None :
894
890
ext = self .FakeExtension ()
895
891
proto = fp .FrameProtocol (client = False , extensions = [ext ])
896
892
payload = "😃😄🙃😉"
897
893
data = proto .send_data (payload , fin = False )
898
- payload = payload .encode ("utf8" ) # type: ignore
899
- assert data == b"\x11 " + bytearray ([len (payload )]) + payload # type: ignore
894
+ payload_bytes = payload .encode ("utf8" )
895
+ assert data == b"\x11 " + bytearray ([len (payload_bytes )]) + payload_bytes
900
896
901
897
payload = r"¯\_(ツ)_/¯"
902
898
data = proto .send_data (payload , fin = True )
903
- payload = (payload + "®" ).encode ("utf8" ) # type: ignore
904
- assert data == b"\x80 " + bytearray ([len (payload )]) + payload # type: ignore
899
+ payload_bytes = (payload + "®" ).encode ("utf8" )
900
+ assert data == b"\x80 " + bytearray ([len (payload_bytes )]) + payload_bytes
905
901
906
902
907
903
class TestFrameProtocolReceive :
@@ -1077,8 +1073,8 @@ def test_single_short_text_data(self) -> None:
1077
1073
proto = fp .FrameProtocol (client = False , extensions = [])
1078
1074
payload = "😃😄🙃😉"
1079
1075
data = proto .send_data (payload , fin = True )
1080
- payload = payload .encode ("utf8" ) # type: ignore
1081
- assert data == b"\x81 " + bytearray ([len (payload )]) + payload # type: ignore
1076
+ payload_bytes = payload .encode ("utf8" )
1077
+ assert data == b"\x81 " + bytearray ([len (payload_bytes )]) + payload_bytes
1082
1078
1083
1079
def test_multiple_short_binary_data (self ) -> None :
1084
1080
proto = fp .FrameProtocol (client = False , extensions = [])
@@ -1094,34 +1090,34 @@ def test_multiple_short_text_data(self) -> None:
1094
1090
proto = fp .FrameProtocol (client = False , extensions = [])
1095
1091
payload = "😃😄🙃😉"
1096
1092
data = proto .send_data (payload , fin = False )
1097
- payload = payload .encode ("utf8" ) # type: ignore
1098
- assert data == b"\x01 " + bytearray ([len (payload )]) + payload # type: ignore
1093
+ payload_bytes = payload .encode ("utf8" )
1094
+ assert data == b"\x01 " + bytearray ([len (payload_bytes )]) + payload_bytes
1099
1095
1100
1096
payload = "🙈🙉🙊"
1101
1097
data = proto .send_data (payload , fin = True )
1102
- payload = payload .encode ("utf8" ) # type: ignore
1103
- assert data == b"\x80 " + bytearray ([len (payload )]) + payload # type: ignore
1098
+ payload_bytes = payload .encode ("utf8" )
1099
+ assert data == b"\x80 " + bytearray ([len (payload_bytes )]) + payload_bytes
1104
1100
1105
1101
def test_mismatched_data_messages1 (self ) -> None :
1106
1102
proto = fp .FrameProtocol (client = False , extensions = [])
1107
1103
payload = "😃😄🙃😉"
1108
1104
data = proto .send_data (payload , fin = False )
1109
- payload = payload .encode ("utf8" ) # type: ignore
1110
- assert data == b"\x01 " + bytearray ([len (payload )]) + payload # type: ignore
1105
+ payload_bytes = payload .encode ("utf8" )
1106
+ assert data == b"\x01 " + bytearray ([len (payload_bytes )]) + payload_bytes
1111
1107
1112
- payload = b"seriously, all ascii" # type: ignore
1108
+ payload_bytes = b"seriously, all ascii"
1113
1109
with pytest .raises (TypeError ):
1114
- proto .send_data (payload )
1110
+ proto .send_data (payload_bytes )
1115
1111
1116
1112
def test_mismatched_data_messages2 (self ) -> None :
1117
1113
proto = fp .FrameProtocol (client = False , extensions = [])
1118
1114
payload = b"it's all just ascii, right?"
1119
1115
data = proto .send_data (payload , fin = False )
1120
1116
assert data == b"\x02 " + bytearray ([len (payload )]) + payload
1121
1117
1122
- payload = "✔️☑️✅✔︎☑" # type: ignore
1118
+ payload_str = "✔️☑️✅✔︎☑"
1123
1119
with pytest .raises (TypeError ):
1124
- proto .send_data (payload )
1120
+ proto .send_data (payload_str )
1125
1121
1126
1122
def test_message_length_max_short (self ) -> None :
1127
1123
proto = fp .FrameProtocol (client = False , extensions = [])
@@ -1188,7 +1184,8 @@ def test_control_frame_with_overly_long_payload(self) -> None:
1188
1184
1189
1185
def test_data_we_have_no_idea_what_to_do_with (self ) -> None :
1190
1186
proto = fp .FrameProtocol (client = False , extensions = [])
1191
- payload = dict () # type: ignore
1187
+ payload : Dict [ str , str ] = dict ()
1192
1188
1193
1189
with pytest .raises (ValueError ):
1190
+ # Intentionally passing illegal type.
1194
1191
proto .send_data (payload ) # type: ignore
0 commit comments