<s> import unittest <EOL> import azureml <EOL> import sys <EOL> from azureml . services import _serialize_func , _deserialize_func , _encode , _decode <EOL> def mutually_ref_f ( ) : <EOL> mutually_ref_g <EOL> return <NUM_LIT> , mutually_ref_g <EOL> def mutually_ref_g ( ) : <EOL> return <NUM_LIT:100> , mutually_ref_f <EOL> abc = <NUM_LIT:200> <EOL> def reads_global ( ) : <EOL> return abc <EOL> class MyClass ( ) : <EOL> pass <EOL> class BaseClass : pass <EOL> class DerivedClass ( BaseClass ) : <EOL> pass <EOL> def reads_class ( ) : <EOL> return MyClass ( ) <EOL> def reads_derived_class ( ) : <EOL> return DerivedClass ( ) <EOL> def aliased_function ( ) : <EOL> return <NUM_LIT> <EOL> alias = aliased_function <EOL> def calls_aliased_function ( ) : <EOL> return alias ( ) <EOL> def reads_module ( ) : <EOL> return sys . version <EOL> class Test_serialize_test ( unittest . TestCase ) : <EOL> def make_globals ( self ) : <EOL> return { '<STR_LIT>' : __builtins__ } <EOL> def test_module ( self ) : <EOL> serialized = _serialize_func ( reads_module ) <EOL> glbs = self . make_globals ( ) <EOL> f = _deserialize_func ( serialized , glbs ) <EOL> self . assertEqual ( f ( ) , sys . version ) <EOL> def test_aliasing ( self ) : <EOL> serialized = _serialize_func ( calls_aliased_function ) <EOL> glbs = self . make_globals ( ) <EOL> f = _deserialize_func ( serialized , glbs ) <EOL> self . assertEqual ( f ( ) , <NUM_LIT> ) <EOL> def test_mutually_ref ( self ) : <EOL> global mutually_ref_f , mutually_ref_g <EOL> glbs = self . make_globals ( ) <EOL> serialized = _serialize_func ( mutually_ref_f ) <EOL> del mutually_ref_f , mutually_ref_g <EOL> f = _deserialize_func ( serialized , glbs ) <EOL> self . assertEqual ( f ( ) [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEqual ( f ( ) [ <NUM_LIT:1> ] ( ) [ <NUM_LIT:0> ] , <NUM_LIT:100> ) <EOL> def test_reads_global ( self ) : <EOL> global abc , reads_global <EOL> glbs = self . make_globals ( ) <EOL> s = _serialize_func ( reads_global ) <EOL> del abc , reads_global <EOL> f = _deserialize_func ( s , glbs ) <EOL> self . assertEqual ( f ( ) , <NUM_LIT:200> ) <EOL> pass <EOL> def test_core_types ( self ) : <EOL> values = [ <NUM_LIT> , '<STR_LIT:abc>' , b'<STR_LIT:abc>' , <NUM_LIT> , True , False , <NUM_LIT> , None , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , { <NUM_LIT:2> : <NUM_LIT:3> } ] <EOL> for value in values : <EOL> self . assertEqual ( _decode ( _encode ( value ) ) , value ) <EOL> def test_other_types ( self ) : <EOL> try : <EOL> import numpy <EOL> self . assertTrue ( _decode ( _encode ( numpy . ndarray ( <NUM_LIT> ) ) ) . all ( ) ) <EOL> except : <EOL> return <EOL> def test_reads_class ( self ) : <EOL> global reads_class , MyClass <EOL> s = _serialize_func ( reads_class ) <EOL> del reads_class , MyClass <EOL> glbs = self . make_globals ( ) <EOL> f = _deserialize_func ( s , glbs ) <EOL> self . assertTrue ( repr ( f ( ) ) . startswith ( '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
