Best Python code snippet using localstack_python
load_model.py
Source:load_model.py
...50 help='Number of Instances to create',51 type=int,52 default=225053 )54 def get_model_template(self, template_name):55 result = []56 subconfig = self.model_config.get(template_name, [])57 for otype_dict in subconfig:58 modname = otype_dict.keys()[0]59 for obj_id, obj_attrs in otype_dict.values()[0].iteritems():60 obj_attrs['id'] = obj_id61 result.append((modname, dict(obj_attrs)))62 return result63 def talesEvalAttrs(self, obj_attrs, **kwargs):64 for attr in obj_attrs:65 if isinstance(obj_attrs[attr], list):66 obj_attrs[attr] = [talesEvalStr(x, self, extra=kwargs) for x in obj_attrs[attr]]67 else:68 obj_attrs[attr] = talesEvalStr(obj_attrs[attr], self, extra=kwargs)69 def run(self):70 with open('model.yaml', 'r') as f:71 self.model_config = yaml.load(f)72 self.connect()73 objmaps = []74 for modname, obj_attrs in self.get_model_template("Global"):75 objmaps.append(ObjectMap(modname=modname, data=obj_attrs))76 for controller_num in range(1, self.options.controllers + 1):77 for modname, obj_attrs in self.get_model_template("Controller"):78 self.talesEvalAttrs(79 obj_attrs,80 num=controller_num,81 device_name=self.options.device82 )83 objmaps.append(ObjectMap(modname=modname, data=obj_attrs))84 for compute_num in range(1, self.options.computes + 1):85 for modname, obj_attrs in self.get_model_template("Compute"):86 self.talesEvalAttrs(87 obj_attrs,88 num=compute_num,89 device_name=self.options.device90 )91 objmaps.append(ObjectMap(modname=modname, data=obj_attrs))92 for tenant_num in range(3, self.options.tenants + 3):93 for modname, obj_attrs in self.get_model_template("Tenant"):94 self.talesEvalAttrs(95 obj_attrs,96 num=tenant_num,97 device_name=self.options.device98 )99 objmaps.append(ObjectMap(modname=modname, data=obj_attrs))100 compute_nums = range(1, self.options.computes + 1)101 tenant_nums = range(3, self.options.tenants + 3)102 for instance_num in range(1, self.options.instances + 1):103 for modname, obj_attrs in self.get_model_template("Instance"):104 tenant_num = tenant_nums[instance_num % self.options.tenants]105 compute_num = compute_nums[instance_num % self.options.computes]106 self.talesEvalAttrs(107 obj_attrs,108 num=instance_num,109 device_name=self.options.device,110 tenant_num=tenant_num,111 compute_num=compute_num112 )113 objmaps.append(ObjectMap(modname=modname, data=obj_attrs))114 device = self.dmd.Devices.OpenStack.Infrastructure.findDevice(self.options.device)115 if not device:116 print "Creating OpenStackInfrastructure device %s" % self.options.device117 device = self.dmd.Devices.OpenStack.Infrastructure.createInstance(self.options.device)...
csharp_sca.py
Source:csharp_sca.py
...21 if not isExist:22 os.makedirs(path)23 for table in self.__tables:24 file = open(f"{path}/{table['name']}.cs", "w")25 file.write(get_model_template(table, self.__models_namespace))26 file.close()27 def create_interfaces(self):28 path = f"{self.__output_path}/Repositories"29 isExist = os.path.exists(path)30 if not isExist:31 os.makedirs(path)32 for table in self.__tables:33 file = open(f"{path}/I{table['name']}Repository.cs", "w")34 file.write(get_irepository_template(table, self.__models_namespace, self.__repositories_namespace))35 file.close()36 def create_sqlserver_repository(self, connection_string):37 path = f"{self.__output_path}/Repositories"38 isExist = os.path.exists(path)39 if not isExist:...
test_byom.py
Source:test_byom.py
...5from functools import lru_cache6import nbox7from nbox import utils8@lru_cache()9def get_model_template(spec: str):10 if spec == "I-I":11 # this is an image image model, we hard code to 3 inputs12 class NHeadModel(torch.nn.Module):13 def __init__(self):14 super().__init__()15 # input_size = (10, 10, 3)16 self.a = torch.nn.Linear(300, 3)17 # input_size = (5, 5, 3)18 self.b = torch.nn.Linear(75, 3)19 def forward(self, a, b):20 return self.a(a.reshape(a.shape[0], -1)) + self.b(b.reshape(b.shape[0], -1))21 # load the model22 model = nbox.Model(NHeadModel(), category={"a": "image", "b": "image"})23 return model, {"a": [1, 3, 10, 10], "b": [1, 3, 5, 5]}24 elif spec == "I-T":25 raise NotImplementedError("TODO")26class PytorchModelLoader(unittest.TestCase):27 def test_image_image_model(self):28 model, templates = get_model_template("I-I")29 # define parser30 parser = nbox.ImageParser(31 post_proc_fn=None,32 templates=templates,33 )34 image = os.path.join(utils.folder(__file__), "assets/cat.jpg")35 # simple fp list -> should fail36 with self.assertRaises(Exception):37 out = parser([image, image])38 # simple dict with 1 input39 out = parser({"a": image, "b": image})40 self.assertEqual(41 {k: v.shape for k, v in out.items()},42 {...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!