How to use module_from_path method in prospector

Best Python code snippet using prospector_python

experimental_envs.py

Source:experimental_envs.py Github

copy

Full Screen

...5from costaware.experimental.util import module_from_path6# Obtain the mountain_car module so we can subclass MountainCarEnv7mount_car_file = deepcopy(*gym.envs.__path__) + '/classic_control/mountain_car.py'8mountain_car_path = os.path.abspath(mount_car_file)9MountainCarEnv = module_from_path('mountain_car', mountain_car_path).MountainCarEnv10acrobot_file = deepcopy(*gym.envs.__path__) + '/classic_control/acrobot.py'11acrobot_path = os.path.abspath(acrobot_file)12AcrobotEnv = module_from_path('acrobot', acrobot_path).AcrobotEnv13pendulum_file = deepcopy(*gym.envs.__path__) + '/classic_control/pendulum.py'14pendulum_path = os.path.abspath(pendulum_file)15PendulumEnv = module_from_path('pendulum', pendulum_path).PendulumEnv16cartpole_file = deepcopy(*gym.envs.__path__) + '/classic_control/cartpole.py'17cartpole_path = os.path.abspath(cartpole_file)18CartPoleEnv = module_from_path('cartpole', cartpole_path).CartPoleEnv19class MountainCarCostAwareEnv(MountainCarEnv):20 """21 Extension of the OpenAI MountainCarEnv to include a cost as well as22 a reward. Used to test RL algorithms that maximize the ratio of long-run23 average reward over long-run average cost.24 User can pass in a cost function that takes the current state as input25 and outputs a corresponding cost. Default cost function is 1.0, reducing26 to the reward-only case.27 """28 def __init__(self, goal_velocity=0, cost_fn=lambda x: 1.0):29 MountainCarEnv.__init__(self, goal_velocity)30 self.cost_fn = cost_fn31 def step(self, action):32 state, reward, done, d = MountainCarEnv.step(self, action)...

Full Screen

Full Screen

test_modules.py

Source:test_modules.py Github

copy

Full Screen

...3# You can obtain one at http://mozilla.org/MPL/2.0/.4import unittest5from libmozdata import modules6class ModulesTest(unittest.TestCase):7 def test_module_from_path(self):8 self.assertEqual(9 modules.module_from_path("xpcom/threads/nsEnvironment.cpp")["name"], "XPCOM"10 )11 self.assertEqual(modules.module_from_path("xpcom/strinFile")["name"], "XPCOM")12 self.assertEqual(13 modules.module_from_path("xpcom/tests/component/TestComponent.cpp")["name"],14 "XPCOM",15 )16 self.assertEqual(17 modules.module_from_path("xpcom/base/nsCycleCollector.h")["name"],18 "Cycle Collector",19 )20 self.assertEqual(21 modules.module_from_path("xpcom/string/nsString.cpp")["name"], "String"22 )23 self.assertEqual(modules.module_from_path("xpcom/string/")["name"], "String")24 self.assertEqual(modules.module_from_path("xpcom/string")["name"], "String")25 self.assertEqual(26 modules.module_from_path("tools/cvs2hg-import.py")["name"], "Build Config"27 )28 self.assertIsNone(modules.module_from_path("doesntexist"))29 # Test heuristics30 self.assertEqual(31 modules.module_from_path("old-configure.in")["name"], "Build Config"32 )33 self.assertEqual(34 modules.module_from_path("python/mach/mach/dispatcher.py")["name"],35 "Build Config",36 )37 self.assertEqual(38 modules.module_from_path("js/public/GCPolicyAPI.h")["name"], "JavaScript"39 )40 self.assertEqual(41 modules.module_from_path("security/certverifier/CertVerifier.cpp")["name"],42 "security",43 )44 self.assertEqual(45 modules.module_from_path("security/pkix/lib/pkixnames.cpp")["name"],46 "security",47 )48 self.assertEqual(49 modules.module_from_path("security/manager/")["name"],50 "Security - Mozilla PSM Glue",51 )52 self.assertEqual(53 modules.module_from_path("tools/profiler/core/platform.h")["name"],54 "Code Analysis and Debugging Tools",55 )56 self.assertEqual(57 modules.module_from_path("tools/update-packaging/")["name"],58 "Build and Release Tools",59 )60 def test_module_info(self):61 self.assertEqual(modules.module_info("XPCOM")["name"], "XPCOM")62 self.assertEqual(modules.module_info("xpcom")["name"], "XPCOM")63 self.assertIsNone(modules.module_info("DoesntExist"))64if __name__ == "__main__":...

Full Screen

Full Screen

test_module.py

Source:test_module.py Github

copy

Full Screen

...11sample_module = TEST_CONFIG_DIR / 'layers' / 'Group' / 'Subgroup' / 'examples.py'12sample_module_w_error = TEST_DATA_DIR / 'sample_module_zerodiv.py'13def test_module_from_path_nofile_raises():14 with pytest.raises(FileNotFoundError):15 module_from_path(TEST_DATA_DIR / 'foo.py')16def test_module_from_path_error_raises():17 with pytest.raises(ZeroDivisionError):18 module_from_path(sample_module_w_error)19def test_load_objects_from_paths_by_class():20 objs = load_objects_from_paths_by_class(21 [sample_module],22 target_class=Layer,23 )24 for obj in objs:...

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 prospector 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