How to use load_module method in Slash

Best Python code snippet using slash

test_plugin_registry.py

Source:test_plugin_registry.py Github

copy

Full Screen

1import pytest2from unittest.mock import call3from asynctest import TestCase as AsyncTestCase, mock as async_mock, call4from ...config.injection_context import InjectionContext5from ...utils.classloader import ClassLoader, ModuleLoadError6from ..plugin_registry import PluginRegistry7from ..protocol_registry import ProtocolRegistry8from ..error import ProtocolDefinitionValidationError9class TestPluginRegistry(AsyncTestCase):10 def setUp(self):11 self.registry = PluginRegistry()12 self.context = InjectionContext(enforce_typing=False)13 self.proto_registry = async_mock.MagicMock(14 register_message_types=async_mock.MagicMock(),15 register_controllers=async_mock.MagicMock(),16 )17 self.context.injector.bind_instance(ProtocolRegistry, self.proto_registry)18 async def test_setup(self):19 mod_name = "test_mod"20 mod = async_mock.MagicMock()21 mod.__name__ = mod_name22 ctx = async_mock.MagicMock()23 self.registry._plugins[mod_name] = mod24 assert list(self.registry.plugin_names) == [mod_name]25 assert list(self.registry.plugins) == [mod]26 mod.setup = async_mock.CoroutineMock()27 await self.registry.init_context(ctx)28 mod.setup.assert_awaited_once_with(ctx)29 async def test_register_routes(self):30 mod_name = "test_mod"31 mod = async_mock.MagicMock()32 mod.__name__ = mod_name33 app = async_mock.MagicMock()34 self.registry._plugins[mod_name] = mod35 mod.routes.register = async_mock.CoroutineMock()36 definition = async_mock.MagicMock()37 definition.versions = [38 {39 "major_version": 1,40 "minimum_minor_version": 0,41 "current_minor_version": 0,42 "path": "v1_0",43 }44 ]45 with async_mock.patch.object(46 ClassLoader,47 "load_module",48 async_mock.MagicMock(side_effect=[definition, mod.routes]),49 ) as load_module:50 await self.registry.register_admin_routes(app)51 calls = [52 call("definition", mod_name),53 call(f"{mod_name}.{definition.versions[0]['path']}.routes"),54 ]55 load_module.assert_has_calls(calls)56 assert mod.routes.register.call_count == 157 with async_mock.patch.object(58 ClassLoader,59 "load_module",60 async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]),61 ) as load_module:62 await self.registry.register_admin_routes(app)63 calls = [64 call("definition", mod_name),65 call(f"{mod_name}.{definition.versions[0]['path']}.routes"),66 ]67 load_module.assert_has_calls(calls)68 assert mod.routes.register.call_count == 169 async def test_register_routes_mod_no_version(self):70 mod_name = "test_mod"71 mod = async_mock.MagicMock()72 mod.__name__ = mod_name73 app = async_mock.MagicMock()74 self.registry._plugins[mod_name] = mod75 mod.routes.register = async_mock.CoroutineMock()76 with async_mock.patch.object(77 ClassLoader,78 "load_module",79 async_mock.MagicMock(side_effect=[None, mod.routes]),80 ) as load_module:81 await self.registry.register_admin_routes(app)82 calls = [call("definition", mod_name), call(f"{mod_name}.routes")]83 load_module.assert_has_calls(calls)84 assert mod.routes.register.call_count == 185 with async_mock.patch.object(86 ClassLoader,87 "load_module",88 async_mock.MagicMock(side_effect=[None, ModuleLoadError()]),89 ) as load_module:90 await self.registry.register_admin_routes(app)91 calls = [92 call("definition", mod_name),93 call(f"{mod_name}.routes"),94 ]95 load_module.assert_has_calls(calls)96 assert mod.routes.register.call_count == 197 async def test_post_process_routes(self):98 mod_name = "test_mod"99 mod = async_mock.MagicMock()100 mod.__name__ = mod_name101 app = async_mock.MagicMock()102 self.registry._plugins[mod_name] = mod103 mod.routes.post_process_routes = async_mock.MagicMock()104 definition = async_mock.MagicMock()105 definition.versions = [106 {107 "major_version": 1,108 "minimum_minor_version": 0,109 "current_minor_version": 0,110 "path": "v1_0",111 }112 ]113 with async_mock.patch.object(114 ClassLoader,115 "load_module",116 async_mock.MagicMock(side_effect=[definition, mod.routes]),117 ) as load_module:118 self.registry.post_process_routes(app)119 calls = [120 call("definition", mod_name),121 call(f"{mod_name}.{definition.versions[0]['path']}.routes"),122 ]123 load_module.assert_has_calls(calls)124 assert mod.routes.post_process_routes.call_count == 1125 with async_mock.patch.object(126 ClassLoader,127 "load_module",128 async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]),129 ) as load_module:130 self.registry.post_process_routes(app)131 calls = [132 call("definition", mod_name),133 call(f"{mod_name}.{definition.versions[0]['path']}.routes"),134 ]135 load_module.assert_has_calls(calls)136 assert mod.routes.post_process_routes.call_count == 1137 async def test_post_process_routes_mod_no_version(self):138 mod_name = "test_mod"139 mod = async_mock.MagicMock()140 mod.__name__ = mod_name141 app = async_mock.MagicMock()142 self.registry._plugins[mod_name] = mod143 mod.routes.register = async_mock.CoroutineMock()144 with async_mock.patch.object(145 ClassLoader,146 "load_module",147 async_mock.MagicMock(side_effect=[None, mod.routes]),148 ) as load_module:149 self.registry.post_process_routes(app)150 calls = [call("definition", mod_name), call(f"{mod_name}.routes")]151 load_module.assert_has_calls(calls)152 assert mod.routes.post_process_routes.call_count == 1153 with async_mock.patch.object(154 ClassLoader,155 "load_module",156 async_mock.MagicMock(side_effect=[None, ModuleLoadError()]),157 ) as load_module:158 self.registry.post_process_routes(app)159 calls = [call("definition", mod_name), call(f"{mod_name}.routes")]160 load_module.assert_has_calls(calls)161 assert mod.routes.post_process_routes.call_count == 1162 async def test_validate_version_not_a_list(self):163 mod_name = "test_mod"164 mod = async_mock.MagicMock()165 mod.__name__ = mod_name166 versions_not_a_list = {}167 with async_mock.patch.object(168 ClassLoader, "load_module", async_mock.MagicMock()169 ) as load_module:170 with pytest.raises(ProtocolDefinitionValidationError):171 self.registry.validate_version(versions_not_a_list, mod_name)172 async def test_validate_version_list_element_not_an_object(self):173 mod_name = "test_mod"174 mod = async_mock.MagicMock()175 mod.__name__ = mod_name176 versions = [{}, []]177 with async_mock.patch.object(178 ClassLoader, "load_module", async_mock.MagicMock()179 ) as load_module:180 with pytest.raises(ProtocolDefinitionValidationError):181 self.registry.validate_version(versions, mod_name)182 async def test_validate_version_list_element_empty(self):183 mod_name = "test_mod"184 mod = async_mock.MagicMock()185 mod.__name__ = mod_name186 versions = []187 with async_mock.patch.object(188 ClassLoader, "load_module", async_mock.MagicMock()189 ) as load_module:190 with pytest.raises(ProtocolDefinitionValidationError):191 self.registry.validate_version(versions, mod_name)192 async def test_validate_version_list_missing_attribute(self):193 mod_name = "test_mod"194 mod = async_mock.MagicMock()195 mod.__name__ = mod_name196 versions = [197 {198 "major_version": 1,199 "minimum_minor_version": 0,200 "current_minor_version": 0,201 # "path": "v1_0", # missing202 }203 ]204 with async_mock.patch.object(205 ClassLoader, "load_module", async_mock.MagicMock()206 ) as load_module:207 with pytest.raises(ProtocolDefinitionValidationError):208 self.registry.validate_version(versions, mod_name)209 async def test_validate_version_negative_version(self):210 mod_name = "test_mod"211 mod = async_mock.MagicMock()212 mod.__name__ = mod_name213 versions = [214 {215 "major_version": -1,216 "minimum_minor_version": 0,217 "current_minor_version": 0,218 "path": "v1_0",219 }220 ]221 with async_mock.patch.object(222 ClassLoader, "load_module", async_mock.MagicMock()223 ) as load_module:224 with pytest.raises(ProtocolDefinitionValidationError):225 self.registry.validate_version(versions, mod_name)226 async def test_validate_version_min_greater_current(self):227 mod_name = "test_mod"228 mod = async_mock.MagicMock()229 mod.__name__ = mod_name230 versions = [231 {232 "major_version": 1,233 "minimum_minor_version": 1,234 "current_minor_version": 0,235 "path": "v1_0",236 }237 ]238 with async_mock.patch.object(239 ClassLoader, "load_module", async_mock.MagicMock()240 ) as load_module:241 with pytest.raises(ProtocolDefinitionValidationError):242 self.registry.validate_version(versions, mod_name)243 async def test_validate_version_multiple_major(self):244 mod_name = "test_mod"245 mod = async_mock.MagicMock()246 mod.__name__ = mod_name247 versions = [248 {249 "major_version": 1,250 "minimum_minor_version": 0,251 "current_minor_version": 0,252 "path": "v1_0",253 },254 {255 "major_version": 1,256 "minimum_minor_version": 0,257 "current_minor_version": 1,258 "path": "v1_1",259 },260 ]261 with async_mock.patch.object(262 ClassLoader, "load_module", async_mock.MagicMock()263 ) as load_module:264 with pytest.raises(ProtocolDefinitionValidationError):265 self.registry.validate_version(versions, mod_name)266 async def test_validate_version_bad_path(self):267 mod_name = "test_mod"268 mod = async_mock.MagicMock()269 mod.__name__ = mod_name270 versions = [271 {272 "major_version": 1,273 "minimum_minor_version": 1,274 "current_minor_version": 0,275 "path": "v1_0",276 }277 ]278 with async_mock.patch.object(279 ClassLoader, "load_module", async_mock.MagicMock(return_value=None)280 ) as load_module:281 with pytest.raises(ProtocolDefinitionValidationError):282 self.registry.validate_version(versions, mod_name)283 async def test_validate_version_list_correct(self):284 mod_name = "test_mod"285 mod = async_mock.MagicMock()286 mod.__name__ = mod_name287 versions = [288 {289 "major_version": 1,290 "minimum_minor_version": 0,291 "current_minor_version": 0,292 "path": "v1_0",293 },294 {295 "major_version": 2,296 "minimum_minor_version": 0,297 "current_minor_version": 0,298 "path": "v2_0",299 },300 ]301 with async_mock.patch.object(302 ClassLoader, "load_module", async_mock.MagicMock()303 ) as load_module:304 assert self.registry.validate_version(versions, mod_name) is True305 load_module.has_calls(306 call(versions[0]["path"], mod_name),307 call(versions[1]["path"], mod_name),308 )309 async def test_validate_version_list_extra_attributes_ok(self):310 mod_name = "test_mod"311 mod = async_mock.MagicMock()312 mod.__name__ = mod_name313 versions = [314 {315 "major_version": 1,316 "minimum_minor_version": 0,317 "current_minor_version": 0,318 "path": "v1_0",319 "not": "an attribute",320 }321 ]322 with async_mock.patch.object(323 ClassLoader, "load_module", async_mock.MagicMock()324 ) as load_module:325 assert self.registry.validate_version(versions, mod_name) is True326 async def test_validate_version_no_such_mod(self):327 mod_name = "no_mod"328 mod = async_mock.MagicMock()329 mod.__name__ = mod_name330 versions = [331 {332 "major_version": 1,333 "minimum_minor_version": 0,334 "current_minor_version": 0,335 "path": "v1_0",336 }337 ]338 with async_mock.patch.object(339 ClassLoader, "load_module", async_mock.MagicMock()340 ) as load_module:341 load_module.return_value = None342 with self.assertRaises(ProtocolDefinitionValidationError):343 self.registry.validate_version(versions, mod_name)344 async def test_register_plugin_already_present(self):345 mod_name = "test_mod"346 mod = async_mock.MagicMock()347 self.registry._plugins[mod_name] = mod348 assert mod == self.registry.register_plugin(mod_name)349 async def test_register_plugin_load_x(self):350 with async_mock.patch.object(351 ClassLoader, "load_module", async_mock.MagicMock()352 ) as load_module:353 load_module.side_effect = ModuleLoadError("failure to load")354 assert self.registry.register_plugin("dummy") is None355 async def test_register_plugin_no_mod(self):356 with async_mock.patch.object(357 ClassLoader, "load_module", async_mock.MagicMock()358 ) as load_module:359 load_module.return_value = None360 assert self.registry.register_plugin("dummy") is None361 async def test_register_plugin_no_definition(self):362 class MODULE:363 no_setup = "no setup attr"364 obj = MODULE()365 with async_mock.patch.object(366 ClassLoader, "load_module", async_mock.MagicMock()367 ) as load_module:368 load_module.side_effect = [369 obj, # module370 None, # routes371 None, # message types372 None, # definition373 ]374 assert self.registry.register_plugin("dummy") is None375 async def test_register_plugin_no_versions(self):376 class MODULE:377 no_setup = "no setup attr"378 obj = MODULE()379 with async_mock.patch.object(380 ClassLoader, "load_module", async_mock.MagicMock()381 ) as load_module:382 load_module.side_effect = [383 obj, # module384 None, # routes385 None, # message types386 "str-has-no-versions-attr", # definition without versions attr387 ]388 assert self.registry.register_plugin("dummy") is None389 async def test_register_plugin_has_setup(self):390 class MODULE:391 setup = "present"392 obj = MODULE()393 with async_mock.patch.object(394 ClassLoader, "load_module", async_mock.MagicMock()395 ) as load_module:396 load_module.side_effect = [397 obj, # module398 None, # routes399 None, # message types400 None, # definition without versions attr401 ]402 assert self.registry.register_plugin("dummy") == obj403 async def test_register_definitions_malformed(self):404 class MODULE:405 no_setup = "no setup attr"406 obj = MODULE()407 with async_mock.patch.object(408 ClassLoader, "load_module", async_mock.MagicMock()409 ) as load_module:410 load_module.side_effect = [411 obj, # module412 None, # routes413 None, # message types414 async_mock.MagicMock(versions="not-a-list"),415 ]416 assert self.registry.register_plugin("dummy") is None417 async def test_register_package_x(self):418 with async_mock.patch.object(419 ClassLoader, "scan_subpackages", async_mock.MagicMock()420 ) as load_module:421 load_module.side_effect = ModuleLoadError()422 assert not self.registry.register_package("dummy")423 async def test_load_protocols_load_x(self):424 mock_plugin = async_mock.MagicMock(__name__="dummy")425 with async_mock.patch.object(426 ClassLoader, "load_module", async_mock.MagicMock()427 ) as load_module:428 load_module.side_effect = ModuleLoadError()429 await self.registry.load_protocols(None, mock_plugin)430 assert load_module.call_count == 1431 async def test_load_protocols_load_mod(self):432 mock_plugin = async_mock.MagicMock(__name__="dummy")433 mock_mod = async_mock.MagicMock()434 mock_mod.MESSAGE_TYPES = async_mock.MagicMock()435 mock_mod.CONTROLLERS = async_mock.MagicMock()436 with async_mock.patch.object(437 ClassLoader, "load_module", async_mock.MagicMock()438 ) as load_module:439 load_module.return_value = mock_mod440 await self.registry.load_protocols(self.context, mock_plugin)441 async def test_load_protocols_no_mod_load_x(self):442 mock_plugin = async_mock.MagicMock(__name__="dummy")443 with async_mock.patch.object(444 ClassLoader, "load_module", async_mock.MagicMock()445 ) as load_module:446 load_module.side_effect = [None, ModuleLoadError()]447 await self.registry.load_protocols(self.context, mock_plugin)448 assert load_module.call_count == 2449 async def test_load_protocols_no_mod_def_no_message_types(self):450 mock_plugin = async_mock.MagicMock(__name__="dummy")451 mock_def = async_mock.MagicMock(452 versions=[453 {454 "major_version": 1,455 "minimum_minor_version": 0,456 "current_minor_version": 0,457 "path": "v1_0",458 }459 ]460 )461 with async_mock.patch.object(462 ClassLoader, "load_module", async_mock.MagicMock()463 ) as load_module:464 load_module.side_effect = [None, mock_def, ModuleLoadError()]465 await self.registry.load_protocols(self.context, mock_plugin)466 assert load_module.call_count == 3467 async def test_load_protocols_no_mod_def_message_types(self):468 mock_plugin = async_mock.MagicMock(__name__="dummy")469 mock_def = async_mock.MagicMock(470 versions=[471 {472 "major_version": 1,473 "minimum_minor_version": 0,474 "current_minor_version": 0,475 "path": "v1_0",476 },477 {478 "major_version": 2,479 "minimum_minor_version": 0,480 "current_minor_version": 0,481 "path": "v2_0",482 },483 ]484 )485 mock_mod = async_mock.MagicMock()486 mock_mod.MESSAGE_TYPES = async_mock.MagicMock()487 mock_mod.CONTROLLERS = async_mock.MagicMock()488 with async_mock.patch.object(489 ClassLoader, "load_module", async_mock.MagicMock()490 ) as load_module:491 load_module.side_effect = [None, mock_def, mock_mod, mock_mod]492 await self.registry.load_protocols(self.context, mock_plugin)493 assert load_module.call_count == 4494 def test_repr(self):...

Full Screen

Full Screen

test_all_examples.py

Source:test_all_examples.py Github

copy

Full Screen

1import numpy as np2from .utils import TestUtils3def test__acados__cube():4 bioptim_folder = TestUtils.bioptim_folder()5 module = TestUtils.load_module(bioptim_folder + "/examples/acados/cube.py")6 module.prepare_ocp(biorbd_model_path=bioptim_folder + "/examples/acados/cube.bioMod", n_shooting=10, tf=2)7def test__acados__pendulum():8 bioptim_folder = TestUtils.bioptim_folder()9 module = TestUtils.load_module(bioptim_folder + "/examples/acados/pendulum.py")10 module.prepare_ocp(11 biorbd_model_path=bioptim_folder + "/examples/acados/pendulum.bioMod", n_shooting=41, final_time=312 )13def test__acados__static_arm():14 bioptim_folder = TestUtils.bioptim_folder()15 module = TestUtils.load_module(bioptim_folder + "/examples/acados/static_arm.py")16 module.prepare_ocp(17 biorbd_model_path=bioptim_folder + "/examples/acados/arm26.bioMod",18 final_time=2,19 x_warm=None,20 n_shooting=51,21 use_sx=False,22 n_threads=6,23 )24def test__getting_started__custom_bounds():25 bioptim_folder = TestUtils.bioptim_folder()26 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_bounds.py")27 module.prepare_ocp(28 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod", n_shooting=30, final_time=229 )30def test__getting_started__custom_constraints():31 bioptim_folder = TestUtils.bioptim_folder()32 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_constraint.py")33 module.prepare_ocp(34 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod",35 )36def test__getting_started__custom_dynamics():37 bioptim_folder = TestUtils.bioptim_folder()38 dynamics = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_dynamics.py")39 dynamics.prepare_ocp(40 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod",41 )42def test__getting_started__custom_initial_guess():43 bioptim_folder = TestUtils.bioptim_folder()44 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_initial_guess.py")45 module.prepare_ocp(46 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod", n_shooting=30, final_time=247 )48def test__getting_started__custom_objectives():49 bioptim_folder = TestUtils.bioptim_folder()50 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_objectives.py")51 module.prepare_ocp(52 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod",53 )54def test__getting_started__custom_parameters():55 bioptim_folder = TestUtils.bioptim_folder()56 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_parameters.py")57 module.prepare_ocp(58 biorbd_model_path=bioptim_folder + "/examples/getting_started/pendulum.bioMod",59 final_time=3,60 n_shooting=100,61 optim_gravity=True,62 optim_mass=True,63 min_g=np.array([-1, -1, -10]),64 max_g=np.array([1, 1, -5]),65 min_m=10,66 max_m=30,67 target_g=np.array([0, 0, -9.81]),68 target_m=20,69 )70def test__getting_started__custom_phase_transitions():71 bioptim_folder = TestUtils.bioptim_folder()72 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_phase_transitions.py")73 module.prepare_ocp(biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod")74def test__getting_started__custom_plotting():75 bioptim_folder = TestUtils.bioptim_folder()76 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/custom_plotting.py")77 module.prepare_ocp(78 biorbd_model_path=bioptim_folder + "/examples/getting_started/pendulum.bioMod", final_time=2, n_shooting=5079 )80def test__getting_started__example_cyclic_movement():81 bioptim_folder = TestUtils.bioptim_folder()82 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_cyclic_movement.py")83 module.prepare_ocp(84 biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod",85 n_shooting=30,86 final_time=2,87 loop_from_constraint=True,88 )89def test__getting_started__example_external_forces():90 bioptim_folder = TestUtils.bioptim_folder()91 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_external_forces.py")92 module.prepare_ocp(biorbd_model_path=bioptim_folder + "/examples/getting_started/cube_with_forces.bioMod")93def test__getting_started__example_inequality_constraint():94 bioptim_folder = TestUtils.bioptim_folder()95 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_inequality_constraint.py")96 module.prepare_ocp(97 biorbd_model_path=bioptim_folder + "/examples/torque_driven_ocp/2segments_4dof_2contacts.bioMod",98 phase_time=0.3,99 n_shooting=10,100 min_bound=50,101 max_bound=np.inf,102 mu=0.2,103 )104def test__getting_started__example_mapping():105 bioptim_folder = TestUtils.bioptim_folder()106 TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_mapping.py")107def test__getting_started__example_multiphase():108 bioptim_folder = TestUtils.bioptim_folder()109 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_multiphase.py")110 module.prepare_ocp(biorbd_model_path=bioptim_folder + "/examples/getting_started/cube.bioMod", long_optim=True)111def test__getting_started__example_optimal_time():112 bioptim_folder = TestUtils.bioptim_folder()113 TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_optimal_time.py")114def test__getting_started__example_save_and_load():115 bioptim_folder = TestUtils.bioptim_folder()116 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_save_and_load.py")117 module.prepare_ocp(118 biorbd_model_path=bioptim_folder + "/examples/getting_started/pendulum.bioMod",119 final_time=3,120 n_shooting=100,121 n_threads=4,122 )123def test__getting_started__example_simulation():124 bioptim_folder = TestUtils.bioptim_folder()125 TestUtils.load_module(bioptim_folder + "/examples/getting_started/example_optimal_time.py")126def test__getting_started__pendulum():127 bioptim_folder = TestUtils.bioptim_folder()128 module = TestUtils.load_module(bioptim_folder + "/examples/getting_started/pendulum.py")129 module.prepare_ocp(130 biorbd_model_path=bioptim_folder + "/examples/getting_started/pendulum.bioMod", final_time=3, n_shooting=100131 )132def test__moving_horizon_estimation__mhe():133 bioptim_folder = TestUtils.bioptim_folder()134 TestUtils.load_module(bioptim_folder + "/examples/moving_horizon_estimation/mhe.py")135 # Todo: Complete when the example is more clear136def test__muscle_driven_ocp__muscle_activations_tracker():137 bioptim_folder = TestUtils.bioptim_folder()138 TestUtils.load_module(bioptim_folder + "/examples/muscle_driven_ocp/muscle_activations_tracker.py")139def test__muscle_driven_ocp__muscle_excitations_tracker():140 bioptim_folder = TestUtils.bioptim_folder()141 TestUtils.load_module(bioptim_folder + "/examples/muscle_driven_ocp/muscle_excitations_tracker.py")142def test__muscle_driven_ocp__static_arm():143 bioptim_folder = TestUtils.bioptim_folder()144 module = TestUtils.load_module(bioptim_folder + "/examples/muscle_driven_ocp/static_arm.py")145 module.prepare_ocp(146 biorbd_model_path=bioptim_folder + "/examples/muscle_driven_ocp/arm26.bioMod",147 final_time=3,148 n_shooting=50,149 weight=1000,150 )151def test__muscle_driven_ocp__static_arm_with_contact():152 bioptim_folder = TestUtils.bioptim_folder()153 module = TestUtils.load_module(bioptim_folder + "/examples/muscle_driven_ocp/static_arm_with_contact.py")154 module.prepare_ocp(155 biorbd_model_path=bioptim_folder + "/examples/muscle_driven_ocp/arm26_with_contact.bioMod",156 final_time=3,157 n_shooting=50,158 weight=1000,159 )160def test__muscle_driven_with_contact__contact_forces_inequality_constraint_muscle():161 bioptim_folder = TestUtils.bioptim_folder()162 module = TestUtils.load_module(163 bioptim_folder + "/examples/muscle_driven_with_contact/contact_forces_inequality_constraint_muscle.py"164 )165 module.prepare_ocp(166 biorbd_model_path=bioptim_folder167 + "/examples/muscle_driven_with_contact/2segments_4dof_2contacts_1muscle.bioMod",168 phase_time=0.3,169 n_shooting=10,170 min_bound=50,171 max_bound=np.inf,172 )173def test__muscle_driven_with_contact__contact_forces_inequality_constraint_muscle_excitations():174 bioptim_folder = TestUtils.bioptim_folder()175 module = TestUtils.load_module(176 bioptim_folder177 + "/examples/muscle_driven_with_contact/contact_forces_inequality_constraint_muscle_excitations.py"178 )179 module.prepare_ocp(180 biorbd_model_path=bioptim_folder181 + "/examples/muscle_driven_with_contact/2segments_4dof_2contacts_1muscle.bioMod",182 phase_time=0.3,183 n_shooting=10,184 min_bound=50,185 )186def test__muscle_driven_with_contact__muscle_activations_contacts_tracker():187 bioptim_folder = TestUtils.bioptim_folder()188 module = TestUtils.load_module(189 bioptim_folder + "/examples/muscle_driven_with_contact/muscle_activations_contacts_tracker.py"190 )191def test__optimal_time_ocp__multiphase_time_constraint():192 bioptim_folder = TestUtils.bioptim_folder()193 module = TestUtils.load_module(bioptim_folder + "/examples/optimal_time_ocp/multiphase_time_constraint.py")194 final_time = [2, 5, 4]195 time_min = [1, 3, 0.1]196 time_max = [2, 4, 0.8]197 ns = [20, 30, 20]198 module.prepare_ocp(199 biorbd_model_path=bioptim_folder + "/examples/optimal_time_ocp/cube.bioMod",200 final_time=final_time,201 time_min=time_min,202 time_max=time_max,203 n_shooting=ns,204 )205def test__optimal_time_ocp__pendulum_min_time_Lagrange():206 bioptim_folder = TestUtils.bioptim_folder()207 module = TestUtils.load_module(bioptim_folder + "/examples/optimal_time_ocp/pendulum_min_time_Lagrange.py")208 module.prepare_ocp(209 biorbd_model_path=bioptim_folder + "/examples/optimal_time_ocp/pendulum.bioMod",210 final_time=2,211 n_shooting=50,212 )213def test__optimal_time_ocp__pendulum_min_time_Mayer():214 bioptim_folder = TestUtils.bioptim_folder()215 module = TestUtils.load_module(bioptim_folder + "/examples/optimal_time_ocp/pendulum_min_time_Mayer.py")216 module.prepare_ocp(217 biorbd_model_path=bioptim_folder + "/examples/optimal_time_ocp/pendulum.bioMod",218 final_time=2,219 n_shooting=50,220 )221def test__optimal_time_ocp__time_constraint():222 bioptim_folder = TestUtils.bioptim_folder()223 module = TestUtils.load_module(bioptim_folder + "/examples/optimal_time_ocp/time_constraint.py")224 module.prepare_ocp(225 biorbd_model_path=bioptim_folder + "/examples/optimal_time_ocp/pendulum.bioMod",226 final_time=2,227 n_shooting=50,228 time_min=0.6,229 time_max=1,230 )231def test__symmetrical_torque_driven_ocp__symmetry_by_constraint():232 bioptim_folder = TestUtils.bioptim_folder()233 module = TestUtils.load_module(bioptim_folder + "/examples/symmetrical_torque_driven_ocp/symmetry_by_constraint.py")234 module.prepare_ocp(235 biorbd_model_path=bioptim_folder + "/examples/symmetrical_torque_driven_ocp/cubeSym.bioMod",236 )237def test__symmetrical_torque_driven_ocp__symmetry_by_mapping():238 bioptim_folder = TestUtils.bioptim_folder()239 module = TestUtils.load_module(bioptim_folder + "/examples/symmetrical_torque_driven_ocp/symmetry_by_mapping.py")240 module.prepare_ocp(241 biorbd_model_path=bioptim_folder + "/examples/symmetrical_torque_driven_ocp/cubeSym.bioMod",242 )243def test__torque_driven_ocp__maximize_predicted_height_CoM():244 bioptim_folder = TestUtils.bioptim_folder()245 module = TestUtils.load_module(bioptim_folder + "/examples/torque_driven_ocp/maximize_predicted_height_CoM.py")246 module.prepare_ocp(247 biorbd_model_path=bioptim_folder + "/examples/torque_driven_ocp/2segments_4dof_2contacts.bioMod",248 phase_time=0.5,249 n_shooting=20,250 use_actuators=False,251 objective_name="MINIMIZE_COM_VELOCITY",252 com_constraints=True,253 )254def test__torque_driven_ocp__spring_load():255 bioptim_folder = TestUtils.bioptim_folder()256 module = TestUtils.load_module(bioptim_folder + "/examples/torque_driven_ocp/spring_load.py")257 module.prepare_ocp(biorbd_model_path=bioptim_folder + "/examples/torque_driven_ocp/mass_point.bioMod")258def test__torque_driven_ocp__track_markers_2D_pendulum():259 bioptim_folder = TestUtils.bioptim_folder()260 TestUtils.load_module(bioptim_folder + "/examples/torque_driven_ocp/track_markers_2D_pendulum.py")261def test__torque_driven_ocp__track_markers_with_torque_actuators():262 bioptim_folder = TestUtils.bioptim_folder()263 module = TestUtils.load_module(264 bioptim_folder + "/examples/torque_driven_ocp/track_markers_with_torque_actuators.py"265 )266 module.prepare_ocp(267 biorbd_model_path=bioptim_folder + "/examples/torque_driven_ocp/cube.bioMod",268 n_shooting=30,269 final_time=2,270 actuator_type=1,271 )272def test__torque_driven_ocp__trampo_quaternions():273 bioptim_folder = TestUtils.bioptim_folder()274 module = TestUtils.load_module(bioptim_folder + "/examples/torque_driven_ocp/trampo_quaternions.py")275 module.prepare_ocp(276 biorbd_model_path=bioptim_folder + "/examples/torque_driven_ocp/TruncAnd2Arm_Quaternion.bioMod",277 n_shooting=5,278 final_time=0.25,279 )280def test__track__track_marker_on_segment():281 bioptim_folder = TestUtils.bioptim_folder()282 module = TestUtils.load_module(bioptim_folder + "/examples/track/track_marker_on_segment.py")283 module.prepare_ocp(284 biorbd_model_path=bioptim_folder + "/examples/track/cube_and_line.bioMod",285 n_shooting=30,286 final_time=2,287 initialize_near_solution=True,288 )289def test__track__track_segment_on_rt():290 bioptim_folder = TestUtils.bioptim_folder()291 module = TestUtils.load_module(bioptim_folder + "/examples/track/track_segment_on_rt.py")292 module.prepare_ocp(293 biorbd_model_path=bioptim_folder + "/examples/track/cube_and_line.bioMod",294 n_shooting=30,295 final_time=1,...

Full Screen

Full Screen

test_module1.py

Source:test_module1.py Github

copy

Full Screen

...14 path_import = extensions.from_imports("pathlib", "Path")15 assert path_import, "Are you importing `Path` from `pathlib`?"16@pytest.mark.test_extensions_sys_path_module117def test_extensions_sys_path_module1(parse):18 # def load_module(directory, name):19 # sys.path.insert(0, directory)20 extensions = parse("extensions")21 assert extensions.success, extensions.message22 load_module = extensions.defines("load_module")23 load_module_exists = load_module.exists()24 assert load_module_exists, "Are you defining a function called `load_module`?"25 load_module.has_arg("directory")26 arguments_exist = load_module.has_arg("directory") and load_module.has_arg(27 "name", 128 )29 assert (30 arguments_exist31 ), "Does the `load_module` function have the correct arguments?"32 insert_call_exists = (33 load_module.calls()34 .match(35 {36 "value_func_value_value_id": "sys",37 "value_func_value_attr": "path",38 "value_func_attr": "insert",39 "value_args_0_value": 0,40 "value_args_1_id": "directory",41 }42 )43 .exists()44 )45 assert (46 insert_call_exists47 ), "Are you calling `sys.path.insert` and passing the correct parameters?"48@pytest.mark.test_extensions_import_pop_module149def test_extensions_import_pop_module1(parse):50 # importlib.import_module(name)51 # sys.path.pop(0)52 extensions = parse("extensions")53 assert extensions.success, extensions.message54 load_module = extensions.defines("load_module")55 load_module_exists = load_module.exists()56 assert load_module_exists, "Are you defining a function called `load_module`?"57 import_module_call_exists = (58 load_module.calls()59 .match(60 {61 "value_func_value_id": "importlib",62 "value_func_attr": "import_module",63 "value_args_0_id": "name",64 }65 )66 .exists()67 )68 assert (69 import_module_call_exists70 ), "Are you calling `importlib.import_module` and passing the correct parameters?"71 pop_call_exists = (72 load_module.calls()73 .match(74 {75 "value_func_value_value_id": "sys",76 "value_func_value_attr": "path",77 "value_func_attr": "pop",78 "value_args_0_value": 0,79 }80 )81 .exists()82 )83 assert (84 pop_call_exists85 ), "Are you calling `sys.path.pop` and passing the correct parameters?"86@pytest.mark.test_extensions_load_directory_module187def test_extensions_load_directory_module1(parse):88 # def load_directory(directory):89 # for path in directory.rglob("*.py"):90 # load_module(directory.as_posix(), path.stem)91 extensions = parse("extensions")92 assert extensions.success, extensions.message93 load_directory = extensions.defines("load_directory")94 load_directory_exists = load_directory.exists()95 assert load_directory_exists, "Are you defining a function called `load_directory`?"96 arguments_exist = load_directory.has_arg("directory")97 assert (98 arguments_exist99 ), "Does the `load_directory` function have the correct arguments?"100 for_exists = (101 load_directory.for_()102 .match(103 {104 "target_id": "path",...

Full Screen

Full Screen

test_loader.py

Source:test_loader.py Github

copy

Full Screen

...6import sys7import types8import unittest9class LoaderTests(abc.LoaderTests):10 """Test load_module() for extension modules."""11 def setUp(self):12 self.loader = self.machinery.ExtensionFileLoader(ext_util.NAME,13 ext_util.FILEPATH)14 def load_module(self, fullname):15 return self.loader.load_module(fullname)16 def test_load_module_API(self):17 # Test the default argument for load_module().18 self.loader.load_module()19 self.loader.load_module(None)20 with self.assertRaises(ImportError):21 self.load_module('XXX')22 def test_equality(self):23 other = self.machinery.ExtensionFileLoader(ext_util.NAME,24 ext_util.FILEPATH)25 self.assertEqual(self.loader, other)26 def test_inequality(self):27 other = self.machinery.ExtensionFileLoader('_' + ext_util.NAME,28 ext_util.FILEPATH)29 self.assertNotEqual(self.loader, other)30 def test_module(self):31 with util.uncache(ext_util.NAME):32 module = self.load_module(ext_util.NAME)33 for attr, value in [('__name__', ext_util.NAME),34 ('__file__', ext_util.FILEPATH),35 ('__package__', '')]:36 self.assertEqual(getattr(module, attr), value)37 self.assertIn(ext_util.NAME, sys.modules)38 self.assertIsInstance(module.__loader__,39 self.machinery.ExtensionFileLoader)40 # No extension module as __init__ available for testing.41 test_package = None42 # No extension module in a package available for testing.43 test_lacking_parent = None44 def test_module_reuse(self):45 with util.uncache(ext_util.NAME):46 module1 = self.load_module(ext_util.NAME)47 module2 = self.load_module(ext_util.NAME)48 self.assertIs(module1, module2)49 # No easy way to trigger a failure after a successful import.50 test_state_after_failure = None51 def test_unloadable(self):52 name = 'asdfjkl;'53 with self.assertRaises(ImportError) as cm:54 self.load_module(name)55 self.assertEqual(cm.exception.name, name)56 def test_is_package(self):57 self.assertFalse(self.loader.is_package(ext_util.NAME))58 for suffix in self.machinery.EXTENSION_SUFFIXES:59 path = os.path.join('some', 'path', 'pkg', '__init__' + suffix)60 loader = self.machinery.ExtensionFileLoader('pkg', path)61 self.assertTrue(loader.is_package('pkg'))62Frozen_LoaderTests, Source_LoaderTests = util.test_both(63 LoaderTests, machinery=machinery)64if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful