@@ -460,6 +460,48 @@ def test_serialize_env_with_enum_import_appearing_in_two_functions() -> None:
460460 assert serialized_env == expected_env
461461
462462
463+ class ReferencedClass :
464+ def __init__ (self , value : int ):
465+ self .value = value
466+
467+ def get_value (self ) -> int :
468+ return self .value
469+
470+
471+ class ClassThatReferencesAnother :
472+ def __init__ (self , x : int ):
473+ self .helper = ReferencedClass (x * 2 )
474+
475+ def compute (self ) -> int :
476+ return self .helper .get_value () + 10
477+
478+
479+ def function_using_class_with_reference (y : int ) -> int :
480+ obj = ClassThatReferencesAnother (y )
481+ return obj .compute ()
482+
483+
484+ def test_serialize_env_with_class_referencing_another_class () -> None :
485+ # firstly we can confirm that func_globals picks up the reference
486+ init_globals = func_globals (ClassThatReferencesAnother .__init__ )
487+ assert "ReferencedClass" in init_globals
488+
489+ path = Path ("tests/utils" )
490+ env : t .Dict [str , t .Tuple [t .Any , t .Optional [bool ]]] = {}
491+
492+ # build ajd serialize environment for the function that uses the class
493+ build_env (function_using_class_with_reference , env = env , name = "test_func" , path = path )
494+ serialized_env = serialize_env (env , path = path )
495+
496+ # both classes should be in the serialized environment
497+ assert "ClassThatReferencesAnother" in serialized_env
498+ assert "ReferencedClass" in serialized_env
499+
500+ prepared_env = prepare_env (serialized_env )
501+ result = eval ("test_func(33)" , prepared_env )
502+ assert result == 76
503+
504+
463505def test_dict_sort_basic_types ():
464506 """Test dict_sort with basic Python types."""
465507 # Test basic types that should use standard repr
0 commit comments