<s> import socket <EOL> import unittest <EOL> from mock import call , MagicMock <EOL> from pants . stream import Stream <EOL> class TestStream ( unittest . TestCase ) : <EOL> def test_stream_constructor_with_invalid_socket ( self ) : <EOL> sock = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> self . assertRaises ( TypeError , Stream , socket = sock ) <EOL> sock . close ( ) <EOL> def test_stream_set_read_delimiter_invalid_value ( self ) : <EOL> stream = Stream ( ) <EOL> passed = False <EOL> try : <EOL> stream . read_delimiter = [ ] <EOL> except TypeError : <EOL> passed = True <EOL> self . assertTrue ( passed ) <EOL> def test_stream_handle_read_event_processes_recv_buffer_before_closing ( self ) : <EOL> stream = Stream ( ) <EOL> stream . _socket_recv = MagicMock ( return_value = None ) <EOL> manager = MagicMock ( ) <EOL> stream . _process_recv_buffer = manager . _process_recv_buffer <EOL> stream . close = manager . close <EOL> stream . _handle_read_event ( ) <EOL> expected_calls = [ call . _process_recv_buffer ( ) , call . close ( flush = False ) ] <EOL> self . assertTrue ( manager . mock_calls == expected_calls ) </s>
