#NEWLINE# def testSocketUdpNb( self ) : #NEWLINE# #INDENT# '\n        Test Class SocketUdpNb\n        ' #NEWLINE# console . terse ( '{0}\n' . format ( self . testSocketUdpNb . __doc__ ) ) #NEWLINE# console . reinit ( verbosity = console . Wordage . profuse ) #NEWLINE# userDirpath = os . path . join ( '~' , '.ioflo' , 'test' ) #NEWLINE# userDirpath = os . path . abspath ( os . path . expanduser ( userDirpath ) ) #NEWLINE# if ( not os . path . exists ( userDirpath ) ) : #NEWLINE# #INDENT# os . makedirs ( src ) #NEWLINE# #UNINDENT# tempDirpath = tempfile . mkdtemp ( prefix = 'test' , suffix = 'log' , dir = userDirpath ) #NEWLINE# logDirpath = os . path . join ( tempDirpath , 'log' ) #NEWLINE# if ( not os . path . exists ( logDirpath ) ) : #NEWLINE# #INDENT# os . makedirs ( logDirpath ) #NEWLINE# #UNINDENT# wireLog = wiring . WireLog ( path = logDirpath ) #NEWLINE# result = wireLog . reopen ( prefix = 'alpha' , midfix = '6101' ) #NEWLINE# alpha = udping . SocketUdpNb ( port = 6101 , wlog = wireLog ) #NEWLINE# self . assertIs ( alpha . opened , False ) #NEWLINE# self . assertIs ( alpha . reopen ( ) , True ) #NEWLINE# self . assertIs ( alpha . opened , True ) #NEWLINE# beta = udping . SocketUdpNb ( port = 6102 ) #NEWLINE# self . assertIs ( beta . reopen ( ) , True ) #NEWLINE# console . terse ( 'Sending alpha to beta\n' ) #NEWLINE# msgOut = b'alpha sends to beta' #NEWLINE# alpha . send ( msgOut , beta . ha ) #NEWLINE# time . sleep ( 0.05 ) #NEWLINE# ( msgIn , src ) = beta . receive ( ) #NEWLINE# self . assertEqual ( msgOut , msgIn ) #NEWLINE# self . assertEqual ( src [ 1 ] , alpha . ha [ 1 ] ) #NEWLINE# console . terse ( 'Sending alpha to alpha\n' ) #NEWLINE# msgOut = b'alpha sends to alpha' #NEWLINE# alpha . send ( msgOut , alpha . ha ) #NEWLINE# time . sleep ( 0.05 ) #NEWLINE# ( msgIn , src ) = alpha . receive ( ) #NEWLINE# self . assertEqual ( msgOut , msgIn ) #NEWLINE# self . assertEqual ( src [ 1 ] , alpha . ha [ 1 ] ) #NEWLINE# console . terse ( 'Sending beta to alpha\n' ) #NEWLINE# msgOut = b'beta sends to alpha' #NEWLINE# beta . send ( msgOut , alpha . ha ) #NEWLINE# time . sleep ( 0.05 ) #NEWLINE# ( msgIn , src ) = alpha . receive ( ) #NEWLINE# self . assertEqual ( msgOut , msgIn ) #NEWLINE# self . assertEqual ( src [ 1 ] , beta . ha [ 1 ] ) #NEWLINE# console . terse ( 'Sending beta to beta\n' ) #NEWLINE# msgOut = b'beta sends to beta' #NEWLINE# beta . send ( msgOut , beta . ha ) #NEWLINE# time . sleep ( 0.05 ) #NEWLINE# ( msgIn , src ) = beta . receive ( ) #NEWLINE# self . assertEqual ( msgOut , msgIn ) #NEWLINE# self . assertEqual ( src [ 1 ] , beta . ha [ 1 ] ) #NEWLINE# alpha . close ( ) #NEWLINE# beta . close ( ) #NEWLINE# self . assertIs ( alpha . opened , False ) #NEWLINE# wireLog . close ( ) #NEWLINE# shutil . rmtree ( tempDirpath ) #NEWLINE# console . reinit ( verbosity = console . Wordage . concise )