diff options
-rw-r--r-- | test/http/http2/test_frames.py | 332 | ||||
-rw-r--r-- | test/http/test_cookies.py | 24 | ||||
-rw-r--r-- | test/websockets/test_websockets.py | 9 |
3 files changed, 167 insertions, 198 deletions
diff --git a/test/http/http2/test_frames.py b/test/http/http2/test_frames.py index 4c89b023..9f41c74d 100644 --- a/test/http/http2/test_frames.py +++ b/test/http/http2/test_frames.py @@ -1,5 +1,4 @@ from io import BytesIO -from nose.tools import assert_equal from netlib import tcp, tutils from netlib.http.http2.frame import * @@ -30,7 +29,7 @@ def test_frame_equality(): flags=Frame.FLAG_END_STREAM, stream_id=0x1234567, payload='foobar') - assert_equal(a, b) + assert a == b def test_too_large_frames(): @@ -48,7 +47,7 @@ def test_data_frame_to_bytes(): flags=Frame.FLAG_END_STREAM, stream_id=0x1234567, payload='foobar') - assert_equal(f.to_bytes().encode('hex'), '000006000101234567666f6f626172') + assert f.to_bytes().encode('hex') == '000006000101234567666f6f626172' f = DataFrame( length=11, @@ -56,9 +55,7 @@ def test_data_frame_to_bytes(): stream_id=0x1234567, payload='foobar', pad_length=3) - assert_equal( - f.to_bytes().encode('hex'), - '00000a00090123456703666f6f626172000000') + assert f.to_bytes().encode('hex') == '00000a00090123456703666f6f626172000000' f = DataFrame( length=6, @@ -71,19 +68,19 @@ def test_data_frame_to_bytes(): def test_data_frame_from_bytes(): f = Frame.from_file(hex_to_file('000006000101234567666f6f626172')) assert isinstance(f, DataFrame) - assert_equal(f.length, 6) - assert_equal(f.TYPE, DataFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_END_STREAM) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.payload, 'foobar') + assert f.length == 6 + assert f.TYPE == DataFrame.TYPE + assert f.flags == Frame.FLAG_END_STREAM + assert f.stream_id == 0x1234567 + assert f.payload == 'foobar' f = Frame.from_file(hex_to_file('00000a00090123456703666f6f626172000000')) assert isinstance(f, DataFrame) - assert_equal(f.length, 10) - assert_equal(f.TYPE, DataFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_END_STREAM | Frame.FLAG_PADDED) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.payload, 'foobar') + assert f.length == 10 + assert f.TYPE == DataFrame.TYPE + assert f.flags == Frame.FLAG_END_STREAM | Frame.FLAG_PADDED + assert f.stream_id == 0x1234567 + assert f.payload == 'foobar' def test_data_frame_human_readable(): @@ -102,7 +99,7 @@ def test_headers_frame_to_bytes(): flags=(Frame.FLAG_NO_FLAGS), stream_id=0x1234567, header_block_fragment='668594e75e31d9'.decode('hex')) - assert_equal(f.to_bytes().encode('hex'), '000007010001234567668594e75e31d9') + assert f.to_bytes().encode('hex') == '000007010001234567668594e75e31d9' f = HeadersFrame( length=10, @@ -110,9 +107,7 @@ def test_headers_frame_to_bytes(): stream_id=0x1234567, header_block_fragment='668594e75e31d9'.decode('hex'), pad_length=3) - assert_equal( - f.to_bytes().encode('hex'), - '00000b01080123456703668594e75e31d9000000') + assert f.to_bytes().encode('hex') == '00000b01080123456703668594e75e31d9000000' f = HeadersFrame( length=10, @@ -122,9 +117,7 @@ def test_headers_frame_to_bytes(): exclusive=True, stream_dependency=0x7654321, weight=42) - assert_equal( - f.to_bytes().encode('hex'), - '00000c012001234567876543212a668594e75e31d9') + assert f.to_bytes().encode('hex') == '00000c012001234567876543212a668594e75e31d9' f = HeadersFrame( length=14, @@ -135,9 +128,7 @@ def test_headers_frame_to_bytes(): exclusive=True, stream_dependency=0x7654321, weight=42) - assert_equal( - f.to_bytes().encode('hex'), - '00001001280123456703876543212a668594e75e31d9000000') + assert f.to_bytes().encode('hex') == '00001001280123456703876543212a668594e75e31d9000000' f = HeadersFrame( length=14, @@ -148,9 +139,7 @@ def test_headers_frame_to_bytes(): exclusive=False, stream_dependency=0x7654321, weight=42) - assert_equal( - f.to_bytes().encode('hex'), - '00001001280123456703076543212a668594e75e31d9000000') + assert f.to_bytes().encode('hex') == '00001001280123456703076543212a668594e75e31d9000000' f = HeadersFrame( length=6, @@ -164,56 +153,56 @@ def test_headers_frame_from_bytes(): f = Frame.from_file(hex_to_file( '000007010001234567668594e75e31d9')) assert isinstance(f, HeadersFrame) - assert_equal(f.length, 7) - assert_equal(f.TYPE, HeadersFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex')) + assert f.length == 7 + assert f.TYPE == HeadersFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == '668594e75e31d9'.decode('hex') f = Frame.from_file(hex_to_file( '00000b01080123456703668594e75e31d9000000')) assert isinstance(f, HeadersFrame) - assert_equal(f.length, 11) - assert_equal(f.TYPE, HeadersFrame.TYPE) - assert_equal(f.flags, HeadersFrame.FLAG_PADDED) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex')) + assert f.length == 11 + assert f.TYPE == HeadersFrame.TYPE + assert f.flags == HeadersFrame.FLAG_PADDED + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == '668594e75e31d9'.decode('hex') f = Frame.from_file(hex_to_file( '00000c012001234567876543212a668594e75e31d9')) assert isinstance(f, HeadersFrame) - assert_equal(f.length, 12) - assert_equal(f.TYPE, HeadersFrame.TYPE) - assert_equal(f.flags, HeadersFrame.FLAG_PRIORITY) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex')) - assert_equal(f.exclusive, True) - assert_equal(f.stream_dependency, 0x7654321) - assert_equal(f.weight, 42) + assert f.length == 12 + assert f.TYPE == HeadersFrame.TYPE + assert f.flags == HeadersFrame.FLAG_PRIORITY + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == '668594e75e31d9'.decode('hex') + assert f.exclusive == True + assert f.stream_dependency == 0x7654321 + assert f.weight == 42 f = Frame.from_file(hex_to_file( '00001001280123456703876543212a668594e75e31d9000000')) assert isinstance(f, HeadersFrame) - assert_equal(f.length, 16) - assert_equal(f.TYPE, HeadersFrame.TYPE) - assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex')) - assert_equal(f.exclusive, True) - assert_equal(f.stream_dependency, 0x7654321) - assert_equal(f.weight, 42) + assert f.length == 16 + assert f.TYPE == HeadersFrame.TYPE + assert f.flags == HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == '668594e75e31d9'.decode('hex') + assert f.exclusive == True + assert f.stream_dependency == 0x7654321 + assert f.weight == 42 f = Frame.from_file(hex_to_file( '00001001280123456703076543212a668594e75e31d9000000')) assert isinstance(f, HeadersFrame) - assert_equal(f.length, 16) - assert_equal(f.TYPE, HeadersFrame.TYPE) - assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex')) - assert_equal(f.exclusive, False) - assert_equal(f.stream_dependency, 0x7654321) - assert_equal(f.weight, 42) + assert f.length == 16 + assert f.TYPE == HeadersFrame.TYPE + assert f.flags == HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == '668594e75e31d9'.decode('hex') + assert f.exclusive == False + assert f.stream_dependency == 0x7654321 + assert f.weight == 42 def test_headers_frame_human_readable(): @@ -248,7 +237,7 @@ def test_priority_frame_to_bytes(): exclusive=True, stream_dependency=0x0, weight=42) - assert_equal(f.to_bytes().encode('hex'), '000005020001234567800000002a') + assert f.to_bytes().encode('hex') == '000005020001234567800000002a' f = PriorityFrame( length=5, @@ -257,7 +246,7 @@ def test_priority_frame_to_bytes(): exclusive=False, stream_dependency=0x7654321, weight=21) - assert_equal(f.to_bytes().encode('hex'), '0000050200012345670765432115') + assert f.to_bytes().encode('hex') == '0000050200012345670765432115' f = PriorityFrame( length=5, @@ -270,23 +259,23 @@ def test_priority_frame_to_bytes(): def test_priority_frame_from_bytes(): f = Frame.from_file(hex_to_file('000005020001234567876543212a')) assert isinstance(f, PriorityFrame) - assert_equal(f.length, 5) - assert_equal(f.TYPE, PriorityFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.exclusive, True) - assert_equal(f.stream_dependency, 0x7654321) - assert_equal(f.weight, 42) + assert f.length == 5 + assert f.TYPE == PriorityFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x1234567 + assert f.exclusive == True + assert f.stream_dependency == 0x7654321 + assert f.weight == 42 f = Frame.from_file(hex_to_file('0000050200012345670765432115')) assert isinstance(f, PriorityFrame) - assert_equal(f.length, 5) - assert_equal(f.TYPE, PriorityFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.exclusive, False) - assert_equal(f.stream_dependency, 0x7654321) - assert_equal(f.weight, 21) + assert f.length == 5 + assert f.TYPE == PriorityFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x1234567 + assert f.exclusive == False + assert f.stream_dependency == 0x7654321 + assert f.weight == 21 def test_priority_frame_human_readable(): @@ -306,7 +295,7 @@ def test_rst_stream_frame_to_bytes(): flags=Frame.FLAG_NO_FLAGS, stream_id=0x1234567, error_code=0x7654321) - assert_equal(f.to_bytes().encode('hex'), '00000403000123456707654321') + assert f.to_bytes().encode('hex') == '00000403000123456707654321' f = RstStreamFrame( length=4, @@ -318,11 +307,11 @@ def test_rst_stream_frame_to_bytes(): def test_rst_stream_frame_from_bytes(): f = Frame.from_file(hex_to_file('00000403000123456707654321')) assert isinstance(f, RstStreamFrame) - assert_equal(f.length, 4) - assert_equal(f.TYPE, RstStreamFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.error_code, 0x07654321) + assert f.length == 4 + assert f.TYPE == RstStreamFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x1234567 + assert f.error_code == 0x07654321 def test_rst_stream_frame_human_readable(): @@ -339,13 +328,13 @@ def test_settings_frame_to_bytes(): length=0, flags=Frame.FLAG_NO_FLAGS, stream_id=0x0) - assert_equal(f.to_bytes().encode('hex'), '000000040000000000') + assert f.to_bytes().encode('hex') == '000000040000000000' f = SettingsFrame( length=0, flags=SettingsFrame.FLAG_ACK, stream_id=0x0) - assert_equal(f.to_bytes().encode('hex'), '000000040100000000') + assert f.to_bytes().encode('hex') == '000000040100000000' f = SettingsFrame( length=6, @@ -353,7 +342,7 @@ def test_settings_frame_to_bytes(): stream_id=0x0, settings={ SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1}) - assert_equal(f.to_bytes().encode('hex'), '000006040100000000000200000001') + assert f.to_bytes().encode('hex') == '000006040100000000000200000001' f = SettingsFrame( length=12, @@ -362,9 +351,7 @@ def test_settings_frame_to_bytes(): settings={ SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1, SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678}) - assert_equal( - f.to_bytes().encode('hex'), - '00000c040000000000000200000001000312345678') + assert f.to_bytes().encode('hex') == '00000c040000000000000200000001000312345678' f = SettingsFrame( length=0, @@ -376,40 +363,37 @@ def test_settings_frame_to_bytes(): def test_settings_frame_from_bytes(): f = Frame.from_file(hex_to_file('000000040000000000')) assert isinstance(f, SettingsFrame) - assert_equal(f.length, 0) - assert_equal(f.TYPE, SettingsFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) + assert f.length == 0 + assert f.TYPE == SettingsFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 f = Frame.from_file(hex_to_file('000000040100000000')) assert isinstance(f, SettingsFrame) - assert_equal(f.length, 0) - assert_equal(f.TYPE, SettingsFrame.TYPE) - assert_equal(f.flags, SettingsFrame.FLAG_ACK) - assert_equal(f.stream_id, 0x0) + assert f.length == 0 + assert f.TYPE == SettingsFrame.TYPE + assert f.flags == SettingsFrame.FLAG_ACK + assert f.stream_id == 0x0 f = Frame.from_file(hex_to_file('000006040100000000000200000001')) assert isinstance(f, SettingsFrame) - assert_equal(f.length, 6) - assert_equal(f.TYPE, SettingsFrame.TYPE) - assert_equal(f.flags, SettingsFrame.FLAG_ACK, 0x0) - assert_equal(f.stream_id, 0x0) - assert_equal(len(f.settings), 1) - assert_equal(f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH], 1) + assert f.length == 6 + assert f.TYPE == SettingsFrame.TYPE + assert f.flags == SettingsFrame.FLAG_ACK, 0x0 + assert f.stream_id == 0x0 + assert len(f.settings) == 1 + assert f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH] == 1 f = Frame.from_file(hex_to_file( '00000c040000000000000200000001000312345678')) assert isinstance(f, SettingsFrame) - assert_equal(f.length, 12) - assert_equal(f.TYPE, SettingsFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) - assert_equal(len(f.settings), 2) - assert_equal(f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH], 1) - assert_equal( - f.settings[ - SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS], - 0x12345678) + assert f.length == 12 + assert f.TYPE == SettingsFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 + assert len(f.settings) == 2 + assert f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH] == 1 + assert f.settings[SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS] == 0x12345678 def test_settings_frame_human_readable(): @@ -437,9 +421,7 @@ def test_push_promise_frame_to_bytes(): stream_id=0x1234567, promised_stream=0x7654321, header_block_fragment='foobar') - assert_equal( - f.to_bytes().encode('hex'), - '00000a05000123456707654321666f6f626172') + assert f.to_bytes().encode('hex') == '00000a05000123456707654321666f6f626172' f = PushPromiseFrame( length=14, @@ -448,9 +430,7 @@ def test_push_promise_frame_to_bytes(): promised_stream=0x7654321, header_block_fragment='foobar', pad_length=3) - assert_equal( - f.to_bytes().encode('hex'), - '00000e0508012345670307654321666f6f626172000000') + assert f.to_bytes().encode('hex') == '00000e0508012345670307654321666f6f626172000000' f = PushPromiseFrame( length=4, @@ -470,20 +450,20 @@ def test_push_promise_frame_to_bytes(): def test_push_promise_frame_from_bytes(): f = Frame.from_file(hex_to_file('00000a05000123456707654321666f6f626172')) assert isinstance(f, PushPromiseFrame) - assert_equal(f.length, 10) - assert_equal(f.TYPE, PushPromiseFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, 'foobar') + assert f.length == 10 + assert f.TYPE == PushPromiseFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == 'foobar' f = Frame.from_file(hex_to_file( '00000e0508012345670307654321666f6f626172000000')) assert isinstance(f, PushPromiseFrame) - assert_equal(f.length, 14) - assert_equal(f.TYPE, PushPromiseFrame.TYPE) - assert_equal(f.flags, PushPromiseFrame.FLAG_PADDED) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, 'foobar') + assert f.length == 14 + assert f.TYPE == PushPromiseFrame.TYPE + assert f.flags == PushPromiseFrame.FLAG_PADDED + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == 'foobar' def test_push_promise_frame_human_readable(): @@ -503,18 +483,14 @@ def test_ping_frame_to_bytes(): flags=PingFrame.FLAG_ACK, stream_id=0x0, payload=b'foobar') - assert_equal( - f.to_bytes().encode('hex'), - '000008060100000000666f6f6261720000') + assert f.to_bytes().encode('hex') == '000008060100000000666f6f6261720000' f = PingFrame( length=8, flags=Frame.FLAG_NO_FLAGS, stream_id=0x0, payload=b'foobardeadbeef') - assert_equal( - f.to_bytes().encode('hex'), - '000008060000000000666f6f6261726465') + assert f.to_bytes().encode('hex') == '000008060000000000666f6f6261726465' f = PingFrame( length=8, @@ -526,19 +502,19 @@ def test_ping_frame_to_bytes(): def test_ping_frame_from_bytes(): f = Frame.from_file(hex_to_file('000008060100000000666f6f6261720000')) assert isinstance(f, PingFrame) - assert_equal(f.length, 8) - assert_equal(f.TYPE, PingFrame.TYPE) - assert_equal(f.flags, PingFrame.FLAG_ACK) - assert_equal(f.stream_id, 0x0) - assert_equal(f.payload, b'foobar\0\0') + assert f.length == 8 + assert f.TYPE == PingFrame.TYPE + assert f.flags == PingFrame.FLAG_ACK + assert f.stream_id == 0x0 + assert f.payload == b'foobar\0\0' f = Frame.from_file(hex_to_file('000008060000000000666f6f6261726465')) assert isinstance(f, PingFrame) - assert_equal(f.length, 8) - assert_equal(f.TYPE, PingFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) - assert_equal(f.payload, b'foobarde') + assert f.length == 8 + assert f.TYPE == PingFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 + assert f.payload == b'foobarde' def test_ping_frame_human_readable(): @@ -558,9 +534,7 @@ def test_goaway_frame_to_bytes(): last_stream=0x1234567, error_code=0x87654321, data=b'') - assert_equal( - f.to_bytes().encode('hex'), - '0000080700000000000123456787654321') + assert f.to_bytes().encode('hex') == '0000080700000000000123456787654321' f = GoAwayFrame( length=14, @@ -569,9 +543,7 @@ def test_goaway_frame_to_bytes(): last_stream=0x1234567, error_code=0x87654321, data=b'foobar') - assert_equal( - f.to_bytes().encode('hex'), - '00000e0700000000000123456787654321666f6f626172') + assert f.to_bytes().encode('hex') == '00000e0700000000000123456787654321666f6f626172' f = GoAwayFrame( length=8, @@ -586,24 +558,24 @@ def test_goaway_frame_from_bytes(): f = Frame.from_file(hex_to_file( '0000080700000000000123456787654321')) assert isinstance(f, GoAwayFrame) - assert_equal(f.length, 8) - assert_equal(f.TYPE, GoAwayFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) - assert_equal(f.last_stream, 0x1234567) - assert_equal(f.error_code, 0x87654321) - assert_equal(f.data, b'') + assert f.length == 8 + assert f.TYPE == GoAwayFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 + assert f.last_stream == 0x1234567 + assert f.error_code == 0x87654321 + assert f.data == b'' f = Frame.from_file(hex_to_file( '00000e0700000000000123456787654321666f6f626172')) assert isinstance(f, GoAwayFrame) - assert_equal(f.length, 14) - assert_equal(f.TYPE, GoAwayFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) - assert_equal(f.last_stream, 0x1234567) - assert_equal(f.error_code, 0x87654321) - assert_equal(f.data, b'foobar') + assert f.length == 14 + assert f.TYPE == GoAwayFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 + assert f.last_stream == 0x1234567 + assert f.error_code == 0x87654321 + assert f.data == b'foobar' def test_go_away_frame_human_readable(): @@ -623,14 +595,14 @@ def test_window_update_frame_to_bytes(): flags=Frame.FLAG_NO_FLAGS, stream_id=0x0, window_size_increment=0x1234567) - assert_equal(f.to_bytes().encode('hex'), '00000408000000000001234567') + assert f.to_bytes().encode('hex') == '00000408000000000001234567' f = WindowUpdateFrame( length=4, flags=Frame.FLAG_NO_FLAGS, stream_id=0x1234567, window_size_increment=0x7654321) - assert_equal(f.to_bytes().encode('hex'), '00000408000123456707654321') + assert f.to_bytes().encode('hex') == '00000408000123456707654321' f = WindowUpdateFrame( length=4, @@ -646,11 +618,11 @@ def test_window_update_frame_to_bytes(): def test_window_update_frame_from_bytes(): f = Frame.from_file(hex_to_file('00000408000000000001234567')) assert isinstance(f, WindowUpdateFrame) - assert_equal(f.length, 4) - assert_equal(f.TYPE, WindowUpdateFrame.TYPE) - assert_equal(f.flags, Frame.FLAG_NO_FLAGS) - assert_equal(f.stream_id, 0x0) - assert_equal(f.window_size_increment, 0x1234567) + assert f.length == 4 + assert f.TYPE == WindowUpdateFrame.TYPE + assert f.flags == Frame.FLAG_NO_FLAGS + assert f.stream_id == 0x0 + assert f.window_size_increment == 0x1234567 def test_window_update_frame_human_readable(): @@ -668,7 +640,7 @@ def test_continuation_frame_to_bytes(): flags=ContinuationFrame.FLAG_END_HEADERS, stream_id=0x1234567, header_block_fragment='foobar') - assert_equal(f.to_bytes().encode('hex'), '000006090401234567666f6f626172') + assert f.to_bytes().encode('hex') == '000006090401234567666f6f626172' f = ContinuationFrame( length=6, @@ -681,11 +653,11 @@ def test_continuation_frame_to_bytes(): def test_continuation_frame_from_bytes(): f = Frame.from_file(hex_to_file('000006090401234567666f6f626172')) assert isinstance(f, ContinuationFrame) - assert_equal(f.length, 6) - assert_equal(f.TYPE, ContinuationFrame.TYPE) - assert_equal(f.flags, ContinuationFrame.FLAG_END_HEADERS) - assert_equal(f.stream_id, 0x1234567) - assert_equal(f.header_block_fragment, 'foobar') + assert f.length == 6 + assert f.TYPE == ContinuationFrame.TYPE + assert f.flags == ContinuationFrame.FLAG_END_HEADERS + assert f.stream_id == 0x1234567 + assert f.header_block_fragment == 'foobar' def test_continuation_frame_human_readable(): diff --git a/test/http/test_cookies.py b/test/http/test_cookies.py index 4f99593a..413b6241 100644 --- a/test/http/test_cookies.py +++ b/test/http/test_cookies.py @@ -1,5 +1,3 @@ -import nose.tools - from netlib.http import cookies @@ -13,7 +11,7 @@ def test_read_token(): [(" foo=bar", 1), ("foo", 4)], ] for q, a in tokens: - nose.tools.eq_(cookies._read_token(*q), a) + assert cookies._read_token(*q) == a def test_read_quoted_string(): @@ -25,7 +23,7 @@ def test_read_quoted_string(): [('"fo\\\"" x', 0), ("fo\"", 6)], ] for q, a in tokens: - nose.tools.eq_(cookies._read_quoted_string(*q), a) + assert cookies._read_quoted_string(*q) == a def test_read_pairs(): @@ -61,7 +59,7 @@ def test_read_pairs(): ] for s, lst in vals: ret, off = cookies._read_pairs(s) - nose.tools.eq_(ret, lst) + assert ret == lst def test_pairs_roundtrips(): @@ -109,10 +107,10 @@ def test_pairs_roundtrips(): ] for s, lst in pairs: ret, off = cookies._read_pairs(s) - nose.tools.eq_(ret, lst) + assert ret == lst s2 = cookies._format_pairs(lst) ret, off = cookies._read_pairs(s2) - nose.tools.eq_(ret, lst) + assert ret == lst def test_cookie_roundtrips(): @@ -128,10 +126,10 @@ def test_cookie_roundtrips(): ] for s, lst in pairs: ret = cookies.parse_cookie_header(s) - nose.tools.eq_(ret.lst, lst) + assert ret.lst == lst s2 = cookies.format_cookie_header(ret) ret = cookies.parse_cookie_header(s2) - nose.tools.eq_(ret.lst, lst) + assert ret.lst == lst def test_parse_set_cookie_pairs(): @@ -181,10 +179,10 @@ def test_parse_set_cookie_pairs(): ] for s, lst in pairs: ret = cookies._parse_set_cookie_pairs(s) - nose.tools.eq_(ret, lst) + assert ret == lst s2 = cookies._format_set_cookie_pairs(ret) ret2 = cookies._parse_set_cookie_pairs(s2) - nose.tools.eq_(ret2, lst) + assert ret2 == lst def test_parse_set_cookie_header(): @@ -209,11 +207,11 @@ def test_parse_set_cookie_header(): if expected: assert ret[0] == expected[0] assert ret[1] == expected[1] - nose.tools.eq_(ret[2].lst, expected[2]) + assert ret[2].lst == expected[2] s2 = cookies.format_set_cookie_header(*ret) ret2 = cookies.parse_set_cookie_header(s2) assert ret2[0] == expected[0] assert ret2[1] == expected[1] - nose.tools.eq_(ret2[2].lst, expected[2]) + assert ret2[2].lst == expected[2] else: assert ret is None diff --git a/test/websockets/test_websockets.py b/test/websockets/test_websockets.py index 6f67b84d..48acc2d6 100644 --- a/test/websockets/test_websockets.py +++ b/test/websockets/test_websockets.py @@ -1,6 +1,5 @@ import os -from nose.tools import raises from netlib.http.http1 import read_response, read_request from netlib import tcp, tutils, websockets, http @@ -176,11 +175,11 @@ class TestBadHandshake(tservers.ServerTestBase): """ handler = BadHandshakeHandler - @raises(TcpDisconnect) def test(self): - client = WebSocketsClient(("127.0.0.1", self.port)) - client.connect() - client.send_message(b"hello") + with tutils.raises(TcpDisconnect): + client = WebSocketsClient(("127.0.0.1", self.port)) + client.connect() + client.send_message(b"hello") class TestFrameHeader: |