<s> __author__ = '<STR_LIT>' <EOL> __version__ = '<STR_LIT>' <EOL> __doc__ = """<STR_LIT>""" <EOL> from unittest import TestCase <EOL> from log_calls import install_proxy_descriptor , ClassInstanceAttrProxy <EOL> class A ( ) : <EOL> def __init__ ( self , x ) : <EOL> self . x = x <EOL> self . _counter = <NUM_LIT:0> <EOL> @ property <EOL> def counter ( self ) : <EOL> self . _counter += <NUM_LIT:1> <EOL> return self . _counter <EOL> @ counter . setter <EOL> def counter ( self , val ) : <EOL> self . _counter = val <EOL> def my_method ( self ) : <EOL> return self . x * self . x <EOL> class B ( ) : <EOL> def __init__ ( self , A_instance ) : <EOL> self . A_instance = A_instance <EOL> class TestInstall_proxy_descriptor ( TestCase ) : <EOL> def test_install_proxy_descriptor ( self ) : <EOL> a = A ( <NUM_LIT:5> ) <EOL> b = B ( a ) <EOL> install_proxy_descriptor ( b , "<STR_LIT>" , "<STR_LIT>" , data = True , readonly = True ) <EOL> a_count = a . counter <EOL> self . assertEqual ( a_count , <NUM_LIT:1> ) <EOL> b_count = b . counter <EOL> self . assertEqual ( b_count , <NUM_LIT:2> ) <EOL> a . counter = <NUM_LIT:7> <EOL> self . assertEqual ( a . counter , <NUM_LIT:8> ) <EOL> def set_b_counter ( ) : <EOL> b . counter = <NUM_LIT> <EOL> self . assertRaises ( <EOL> AttributeError , <EOL> set_b_counter ) <EOL> b2 = B ( a ) <EOL> install_proxy_descriptor ( b , "<STR_LIT>" , "<STR_LIT>" , data = True , readonly = False ) <EOL> self . assertEqual ( b2 . counter , <NUM_LIT:9> ) <EOL> b2 . counter = - <NUM_LIT:1> <EOL> self . assertEqual ( a . counter , <NUM_LIT:0> ) <EOL> install_proxy_descriptor ( b , "<STR_LIT>" , "<STR_LIT>" , data = False ) <EOL> self . assertEqual ( b . my_method ( ) , <NUM_LIT> ) <EOL> class A1 ( A ) : <EOL> @ classmethod <EOL> def get_data_descriptor_names ( cls ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT:x>' ] <EOL> @ classmethod <EOL> def get_method_descriptor_names ( cls ) : <EOL> return [ '<STR_LIT>' ] <EOL> class A2 ( A1 ) : <EOL> @ classmethod <EOL> def get_data_descriptor_names ( cls ) : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] + super ( ) . get_data_descriptor_names ( ) <EOL> @ classmethod <EOL> def get_method_descriptor_names ( cls ) : <EOL> return super ( ) . get_method_descriptor_names ( ) <EOL> def __init__ ( self , x , filter = '<STR_LIT>' ) : <EOL> self . _filter = filter <EOL> super ( ) . __init__ ( x ) <EOL> @ property <EOL> def filter ( self ) : <EOL> return self . _filter <EOL> @ filter . setter <EOL> def filter ( self , val ) : <EOL> self . _filter = val <EOL> @ property <EOL> def inverse_filter ( self ) : <EOL> return self . _filter [ : : - <NUM_LIT:1> ] <EOL> class TestClassInstanceAttrProxy ( TestCase ) : <EOL> def test_ClassInstanceAttrProxy_1 ( self ) : <EOL> a1_1 = A1 ( <NUM_LIT:7> ) <EOL> a1_2 = A1 ( <NUM_LIT:1000> ) <EOL> proxy1 = ClassInstanceAttrProxy ( <EOL> class_instance = a1_1 , <EOL> data_descriptor_names = a1_1 . get_data_descriptor_names ( ) , <EOL> method_descriptor_names = a1_1 . get_method_descriptor_names ( ) <EOL> ) <EOL> proxy2 = ClassInstanceAttrProxy ( <EOL> class_instance = a1_2 , <EOL> data_descriptor_names = a1_2 . get_data_descriptor_names ( ) , <EOL> method_descriptor_names = a1_2 . get_method_descriptor_names ( ) <EOL> ) <EOL> self . assertEqual ( proxy1 . counter , <NUM_LIT:1> ) <EOL> self . assertEqual ( proxy1 . x , <NUM_LIT:7> ) <EOL> self . assertEqual ( proxy1 . my_method ( ) , <NUM_LIT> ) <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> proxy2 . counter <EOL> self . assertEqual ( proxy2 . counter , <NUM_LIT:5> ) <EOL> self . assertEqual ( proxy2 . x , <NUM_LIT:1000> ) <EOL> self . assertEqual ( proxy2 . my_method ( ) , <NUM_LIT> ) <EOL> self . assertEqual ( proxy1 . counter , <NUM_LIT:2> ) <EOL> def try_set_counter ( proxy ) : <EOL> proxy . counter = <NUM_LIT> <EOL> self . assertRaises ( AttributeError , <EOL> try_set_counter , <EOL> proxy1 ) <EOL> self . assertRaises ( AttributeError , <EOL> try_set_counter , <EOL> proxy2 ) <EOL> a2 = A2 ( <NUM_LIT> ) <EOL> proxy_a2 = ClassInstanceAttrProxy ( <EOL> class_instance = a2 , <EOL> data_descriptor_names = a2 . get_data_descriptor_names ( ) , <EOL> method_descriptor_names = a2 . get_method_descriptor_names ( ) <EOL> ) <EOL> a2 . counter <EOL> self . assertEqual ( proxy_a2 . counter , <NUM_LIT:2> ) <EOL> self . assertEqual ( proxy_a2 . x , <NUM_LIT> ) <EOL> self . assertEqual ( proxy_a2 . my_method ( ) , <NUM_LIT> * <NUM_LIT> ) <EOL> self . assertEqual ( proxy_a2 . filter , "<STR_LIT>" ) <EOL> self . assertEqual ( proxy_a2 . inverse_filter , "<STR_LIT>" ) </s>
