How to use _get_module method in pyresttest

Best Python code snippet using pyresttest_python

dynaport.py

Source:dynaport.py Github

copy

Full Screen

...3import os4if sys.version_info[0] >= 3:5 if sys.version_info[1] == 3 or sys.version_info[1] == 4:6 from importlib.machinery import SourceFileLoader7 def _get_module(name, location):8 module = SourceFileLoader(name, location).load_module()9 return module10 else:11 import importlib.util12 def _get_module(name, path):13 spec = importlib.util.spec_from_file_location(name, path)14 module = importlib.util.module_from_spec(spec)15 spec.loader.exec_module(module)16 return module17else:18 import imp19 def _get_module(name, location):20 module = imp.load_source(name, location)21 return module22class Dynaport:23 def __init__(self, **options):24 self.config = options.get("config", False)25 self.set_config(config=self.config)26 def _get_path(self, path):27 return os.path.expandvars(path)28 def _get_module(self, name, path):29 module = _get_module(name, self._get_path(path))30 return module31 def get_config(self, **options):32 return self.config33 def set_config(self, **options):34 if options.get("config", False) is False:35 return False36 if isinstance(options.get("config"), dict):37 self.config = options.get("config")38 else:39 with open(self._get_path(options.get("config")), "r") as f:40 self.config = json.load(f)41 def get_module(self, **options):42 if not options.get("name") and not options.get("path") and not self.config:43 raise AttributeError44 if options.get("name") and options.get("path"):45 return self._get_module(options.get("name"), options.get("path"))46 return self._get_module(47 options.get("name"), self.config.get("modules", {}).get(options.get("name"))48 )49 def get_modules(self, **options):50 if not self.config or not options.get("modules"):51 raise AttributeError52 if options.get("dict") is True:53 module_dict = {}54 for module in options.get("modules"):55 module_dict[module] = self._get_module(56 module, self.config.get("modules").get(module)57 )58 return module_dict59 module_list = []60 for module in options.get("modules"):61 module_list.append(62 self._get_module(module, self.config.get("modules").get(module))63 )...

Full Screen

Full Screen

test_module_proxy_wrapper.py

Source:test_module_proxy_wrapper.py Github

copy

Full Screen

...23 return self.linear(x)24 def get_xyz(self):25 return self.xyz26class TestModuleProxyWrapper(unittest.TestCase):27 def _get_module(self):28 module = Model()29 wrapped_module = MockDDPWrapper(module)30 wrapped_module = ModuleProxyWrapper(wrapped_module)31 return wrapped_module, module32 def test_getattr_forwarding(self):33 wrapped_module, module = self._get_module()34 assert module.xyz == "hello"35 assert module.get_xyz() == "hello"36 assert wrapped_module.xyz == "hello"37 wrapped_module.xyz = "world"38 assert wrapped_module.xyz == "world"39 assert module.get_xyz() == "hello"40 def test_state_dict(self):41 wrapped_module, module = self._get_module()42 assert objects_are_equal(wrapped_module.state_dict(), module.state_dict())43 def test_load_state_dict(self):44 wrapped_module, module = self._get_module()45 wrapped_module.load_state_dict(module.state_dict())46 input = torch.rand(4, 5)47 torch.testing.assert_allclose(wrapped_module(input), module(input))48 def test_forward(self):49 wrapped_module, module = self._get_module()50 input = torch.rand(4, 5)51 torch.testing.assert_allclose(wrapped_module(input), module(input))52if __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 pyresttest 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