<s> from __future__ import unicode_literals <EOL> import unittest <EOL> from irc3 . testing import MagicMock <EOL> import irc3 <EOL> class TestProtocol ( unittest . TestCase ) : <EOL> def callFTU ( self ) : <EOL> conn = irc3 . IrcConnection ( ) <EOL> conn . encoding = '<STR_LIT:utf8>' <EOL> conn . factory = MagicMock ( ) <EOL> conn . connection_made ( MagicMock ( ) ) <EOL> return conn <EOL> def test_buffer ( self ) : <EOL> conn = self . callFTU ( ) <EOL> conn . data_received ( b'<STR_LIT:message>' ) <EOL> self . assertEqual ( conn . queue . popleft ( ) , '<STR_LIT:message>' ) <EOL> def test_no_buffer ( self ) : <EOL> conn = self . callFTU ( ) <EOL> conn . data_received ( b'<STR_LIT>' ) <EOL> conn . factory . dispatch . assert_called_with ( '<STR_LIT:message>' ) <EOL> self . assertEqual ( conn . queue . popleft ( ) , '<STR_LIT>' ) <EOL> def test_with_buffer ( self ) : <EOL> conn = self . callFTU ( ) <EOL> conn . data_received ( b'<STR_LIT>' ) <EOL> conn . data_received ( b'<STR_LIT>' ) <EOL> buf = conn . queue . popleft ( ) <EOL> self . assertEqual ( buf , '<STR_LIT>' ) <EOL> conn . queue . append ( buf ) <EOL> conn . data_received ( b'<STR_LIT>' ) <EOL> conn . factory . dispatch . assert_called_with ( '<STR_LIT>' ) <EOL> self . assertEqual ( conn . queue . popleft ( ) , '<STR_LIT>' ) <EOL> def test_write ( self ) : <EOL> conn = self . callFTU ( ) <EOL> conn . write ( '<STR_LIT>' ) <EOL> conn . transport . write . assert_called_with ( b'<STR_LIT>' ) <EOL> conn . write ( '<STR_LIT>' ) <EOL> conn . transport . write . assert_called_with ( b'<STR_LIT>' ) <EOL> conn . write ( b'<STR_LIT>' ) <EOL> conn . transport . write . assert_called_with ( b'<STR_LIT>' ) </s>
