<s> import unittest2 as unittest <EOL> import socket <EOL> from testfixtures import log_capture <EOL> from slimta . logging import getSocketLogger <EOL> class FakeSocket ( object ) : <EOL> def __init__ ( self , fd , peer = None ) : <EOL> self . fd = fd <EOL> self . peer = peer <EOL> def fileno ( self ) : <EOL> return self . fd <EOL> def getpeername ( self ) : <EOL> return self . peer <EOL> class TestSocketLogger ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . log = getSocketLogger ( '<STR_LIT:test>' ) <EOL> @ log_capture ( ) <EOL> def test_send ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> ) <EOL> self . log . send ( sock , '<STR_LIT>' ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_recv ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> ) <EOL> self . log . recv ( sock , '<STR_LIT>' ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_accept ( self , l ) : <EOL> server = FakeSocket ( <NUM_LIT> ) <EOL> client = FakeSocket ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . log . accept ( server , client ) <EOL> self . log . accept ( server , client , '<STR_LIT>' ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_connect ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . log . connect ( sock ) <EOL> self . log . connect ( sock , '<STR_LIT>' ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_encrypt ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> ) <EOL> self . log . encrypt ( sock , { '<STR_LIT>' : '<STR_LIT:test>' , '<STR_LIT>' : True } ) <EOL> self . log . encrypt ( sock , { '<STR_LIT>' : '<STR_LIT:test>' } ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_shutdown ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> ) <EOL> self . log . shutdown ( sock , socket . SHUT_RD ) <EOL> self . log . shutdown ( sock , socket . SHUT_WR ) <EOL> self . log . shutdown ( sock , socket . SHUT_RDWR ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> @ log_capture ( ) <EOL> def test_close ( self , l ) : <EOL> sock = FakeSocket ( <NUM_LIT> ) <EOL> self . log . close ( sock ) <EOL> l . check ( ( '<STR_LIT:test>' , '<STR_LIT>' , '<STR_LIT>' ) ) </s>
