<s> import math <EOL> import time <EOL> import rpyc <EOL> import unittest <EOL> on_connect_called = False <EOL> on_disconnect_called = False <EOL> class MyMeta ( type ) : <EOL> def spam ( self ) : <EOL> return self . __name__ * <NUM_LIT:5> <EOL> class MyClass ( object ) : <EOL> __metaclass__ = MyMeta <EOL> if not isinstance ( MyMeta , MyMeta ) : <EOL> MyClass = MyMeta ( MyClass . __name__ , MyClass . __bases__ , dict ( MyClass . __dict__ ) ) <EOL> class MyService ( rpyc . Service ) : <EOL> def on_connect ( self ) : <EOL> global on_connect_called <EOL> on_connect_called = True <EOL> def on_disconnect ( self ) : <EOL> global on_disconnect_called <EOL> on_disconnect_called = True <EOL> def exposed_distance ( self , p1 , p2 ) : <EOL> x1 , y1 = p1 <EOL> x2 , y2 = p2 <EOL> return math . sqrt ( ( x2 - x1 ) ** <NUM_LIT:2> + ( y2 - y1 ) ** <NUM_LIT:2> ) <EOL> def exposed_getlist ( self ) : <EOL> return [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> def foobar ( self ) : <EOL> assert False <EOL> def exposed_getmeta ( self ) : <EOL> return MyClass ( ) <EOL> class TestCustomService ( unittest . TestCase ) : <EOL> config = { } <EOL> def setUp ( self ) : <EOL> global on_connect_called <EOL> self . conn = rpyc . connect_thread ( remote_service = MyService ) <EOL> self . conn . root <EOL> self . assertTrue ( on_connect_called ) <EOL> on_connect_called = False <EOL> def tearDown ( self ) : <EOL> global on_disconnect_called <EOL> self . conn . close ( ) <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> self . assertTrue ( on_disconnect_called ) <EOL> on_disconnect_called = False <EOL> def test_aliases ( self ) : <EOL> print ( "<STR_LIT>" % ( self . conn . root . get_service_name ( ) , ) ) <EOL> def test_distance ( self ) : <EOL> assert self . conn . root . distance ( ( <NUM_LIT:2> , <NUM_LIT:7> ) , ( <NUM_LIT:5> , <NUM_LIT:11> ) ) == <NUM_LIT:5> <EOL> def test_attributes ( self ) : <EOL> self . conn . root . distance <EOL> self . conn . root . exposed_distance <EOL> self . conn . root . getlist <EOL> self . conn . root . exposed_getlist <EOL> self . assertRaises ( AttributeError , lambda : self . conn . root . foobar ( ) ) <EOL> def test_safeattrs ( self ) : <EOL> x = self . conn . root . getlist ( ) <EOL> self . assertEqual ( [ y * <NUM_LIT:2> for y in x ] , [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) <EOL> def test_metaclasses ( self ) : <EOL> x = self . conn . root . getmeta ( ) <EOL> print ( x ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
