@@ -717,32 +717,8 @@ def invalid_controller_9_params( # pylint: disable=unused-argument
717717 )
718718
719719
720- def test_environment_methods_accessible_in_controller (
721- calisto_robust , example_plain_env
722- ):
723- """Test that all environment methods are accessible within the controller.
724-
725- This test verifies that the environment object passed to the controller
726- provides access to all necessary atmospheric and environmental data.
727-
728- Parameters
729- ----------
730- calisto_robust : rocketpy.Rocket
731- Calisto rocket without air brakes
732- example_plain_env : rocketpy.Environment
733- Environment object for the simulation
734- """
735- # Track which environment methods were successfully called
736- methods_called = {
737- "elevation" : False ,
738- "wind_velocity_x" : False ,
739- "wind_velocity_y" : False ,
740- "speed_of_sound" : False ,
741- "pressure" : False ,
742- "temperature" : False ,
743- }
744-
745- def _call_env_methods (environment , altitude_asl , methods_called ):
720+ def make_controller_test_environment_access (methods_called ):
721+ def _call_env_methods (environment , altitude_asl ):
746722 _ = environment .elevation
747723 methods_called ["elevation" ] = True
748724 _ = environment .wind_velocity_x (altitude_asl )
@@ -756,7 +732,7 @@ def _call_env_methods(environment, altitude_asl, methods_called):
756732 _ = environment .temperature (altitude_asl )
757733 methods_called ["temperature" ] = True
758734
759- def controller_test_environment_access ( # pylint: disable=unused-argument
735+ def controller ( # pylint: disable=unused-argument
760736 time ,
761737 sampling_rate ,
762738 state ,
@@ -773,18 +749,48 @@ def controller_test_environment_access( # pylint: disable=unused-argument
773749 return None
774750
775751 try :
776- _call_env_methods (environment , altitude_asl , methods_called )
752+ _call_env_methods (environment , altitude_asl )
777753 air_brakes .deployment_level = 0.3
778754 except AttributeError as e :
779755 raise AssertionError (f"Environment method not accessible: { e } " ) from e
780756
781757 return (time , air_brakes .deployment_level )
782758
759+ return controller
760+
761+
762+ def test_environment_methods_accessible_in_controller (
763+ calisto_robust , example_plain_env
764+ ):
765+ """Test that all environment methods are accessible within the controller.
766+
767+ This test verifies that the environment object passed to the controller
768+ provides access to all necessary atmospheric and environmental data.
769+
770+ Parameters
771+ ----------
772+ calisto_robust : rocketpy.Rocket
773+ Calisto rocket without air brakes
774+ example_plain_env : rocketpy.Environment
775+ Environment object for the simulation
776+ """
777+ # Track which environment methods were successfully called
778+ methods_called = {
779+ "elevation" : False ,
780+ "wind_velocity_x" : False ,
781+ "wind_velocity_y" : False ,
782+ "speed_of_sound" : False ,
783+ "pressure" : False ,
784+ "temperature" : False ,
785+ }
786+
787+ controller = make_controller_test_environment_access (methods_called )
788+
783789 # Add air brakes with environment-testing controller
784790 calisto_robust .parachutes = []
785791 calisto_robust .add_air_brakes (
786792 drag_coefficient_curve = "data/rockets/calisto/air_brakes_cd.csv" ,
787- controller_function = controller_test_environment_access ,
793+ controller_function = controller ,
788794 sampling_rate = 10 ,
789795 clamp = True ,
790796 )
0 commit comments