Best Python code snippet using tempest_python
build_model.py
Source:build_model.py
...150network_dict = {}151available_network = []152153154def create_network(name, num_layer, dim, layer_name, types, **kwargs):155 available_network.append(f"{name}")156 for i in range(8):157 network_dict.update({f"{name}_b{i}": lambda i=i: BuildModel(num_layer, dim, layer_name, types, i, **kwargs)})158159160create_network("efficientnet", [], 0, "DepthwiseConv1D", "resnet", efficientv1=True)161create_network("ej_efficientnet", [], 0, "DepthwiseConv1D", "resnet", efficientv1=True, ej=True)162163create_network("dense_efficientnet", [], 0, "DepthwiseConv1D", "densenet", efficientv1=True)164create_network("ej_dense_efficientnet", [], 0, "DepthwiseConv1D", "densenet", efficientv1=True, ej=True)165166create_network("lambda_efficientnet", [], 0, "lambdalayer", "resnet", efficientv1=True)167create_network("ej_lambda_efficientnet", [], 0, "lambdalayer", "resnet", efficientv1=True, ej=True)168169create_network("efficientnetv2", [], 0, "DepthwiseConv1D", "resnet", efficientv2=True)170create_network("ej_efficientnetv2", [], 0, "DepthwiseConv1D", "resnet", efficientv2=True, ej=True)171172create_network("resnet", [], 48, "Conv1D", "resnet")173create_network("ej_resnet", [], 48, "Conv1D", "resnet", ej=True)174create_network("se_resnet", [], 48, "Conv1D", "resnet", se=True)175create_network("ej_se_resnet", [], 48, "Conv1D", "resnet", se=True, ej=True)176177create_network("densenet", [], 48, "Conv1D", "densenet")178create_network("ej_densenet", [], 48, "Conv1D", "densenet", ej=True)179create_network("se_densenet", [], 48, "Conv1D", "densenet", se=True)180create_network("ej_se_densenet", [], 48, "Conv1D", "densenet", se=True, ej=True)181182create_network("lambda_resnet", [], 48, "LambdaLayer", "resnet")183create_network("ej_lambda_resnet", [], 48, "LambdaLayer", "resnet", ej=True)184create_network("se_lambda_resnet", [], 48, "LambdaLayer", "resnet", se=True)185create_network("ej_se_lambda_resnet", [], 48, "LambdaLayer", "resnet", se=True, ej=True)186187create_network("convnext", [], 48, "DepthwiseConv1D", "resnet", convnext=True)188create_network("ej_convnext", [], 48, "DepthwiseConv1D", "resnet", convnext=True, ej=True)189create_network("se_convnext", [], 48, "DepthwiseConv1D", "resnet", convnext=True, se=True)190create_network("ej_se_convnext", [], 48, "DepthwiseConv1D", "resnet", convnext=True, se=True, ej=True)191192create_network("lambda_convnext", [], 48, "LambdaLayer", "resnet", convnext=True)193create_network("ej_lambda_convnext", [], 48, "LambdaLayer", "resnet", convnext=True, ej=True)194create_network("se_lambda_convnext", [], 48, "LambdaLayer", "resnet", convnext=True, se=True)195create_network("ej_se_lambda_convnext", [], 48, "LambdaLayer", "resnet", convnext=True, se=True, ej=True)196197198def build_model(model_name: str, input_shape: tuple, output_size: int, output_activation=None, agent=None) -> Model:199 model = network_dict[model_name]()200 model = model.build_model(input_shape, output_size, output_activation, agent)201202 return model203204205available_network = np.array(available_network).reshape((-1,))206
...
network_test.py
Source:network_test.py
...4from .. import helpers5from ..base import requires_api_version6@requires_api_version('1.21')7class TestNetworks(helpers.BaseTestCase):8 def create_network(self, *args, **kwargs):9 net_name = u'dockerpy{}'.format(random.getrandbits(24))[:14]10 net_id = self.client.create_network(net_name, *args, **kwargs)['Id']11 self.tmp_networks.append(net_id)12 return (net_name, net_id)13 def test_list_networks(self):14 networks = self.client.networks()15 initial_size = len(networks)16 net_name, net_id = self.create_network()17 networks = self.client.networks()18 self.assertEqual(len(networks), initial_size + 1)19 self.assertTrue(net_id in [n['Id'] for n in networks])20 networks_by_name = self.client.networks(names=[net_name])21 self.assertEqual([n['Id'] for n in networks_by_name], [net_id])22 networks_by_partial_id = self.client.networks(ids=[net_id[:8]])23 self.assertEqual([n['Id'] for n in networks_by_partial_id], [net_id])24 def test_inspect_network(self):25 net_name, net_id = self.create_network()26 net = self.client.inspect_network(net_id)27 self.assertEqual(net, {28 u'Name': net_name,29 u'Id': net_id,30 u'Driver': 'bridge',31 u'Containers': {},32 u'IPAM': {u'Config': [{}], u'Driver': 'default'},33 u'Options': {},34 u'Scope': 'local'35 })36 def test_create_network_with_host_driver_fails(self):37 net_name = 'dockerpy{}'.format(random.getrandbits(24))[:14]38 with pytest.raises(docker.errors.APIError):39 self.client.create_network(net_name, driver='host')40 def test_remove_network(self):41 initial_size = len(self.client.networks())42 net_name, net_id = self.create_network()43 self.assertEqual(len(self.client.networks()), initial_size + 1)44 self.client.remove_network(net_id)45 self.assertEqual(len(self.client.networks()), initial_size)46 def test_connect_and_disconnect_container(self):47 net_name, net_id = self.create_network()48 container = self.client.create_container('busybox', 'top')49 self.tmp_containers.append(container)50 self.client.start(container)51 network_data = self.client.inspect_network(net_id)52 self.assertFalse(network_data.get('Containers'))53 self.client.connect_container_to_network(container, net_id)54 network_data = self.client.inspect_network(net_id)55 self.assertEqual(56 list(network_data['Containers'].keys()),57 [container['Id']])58 self.client.disconnect_container_from_network(container, net_id)59 network_data = self.client.inspect_network(net_id)60 self.assertFalse(network_data.get('Containers'))61 def test_connect_on_container_create(self):62 net_name, net_id = self.create_network()63 container = self.client.create_container(64 image='busybox',65 command='top',66 host_config=self.client.create_host_config(network_mode=net_name),67 )68 self.tmp_containers.append(container)69 self.client.start(container)70 network_data = self.client.inspect_network(net_id)71 self.assertEqual(72 list(network_data['Containers'].keys()),73 [container['Id']])74 self.client.disconnect_container_from_network(container, net_id)75 network_data = self.client.inspect_network(net_id)76 self.assertFalse(network_data.get('Containers'))
main.py
Source:main.py
...10 def __init__(self, message):11 self._message = message12 def __str__(self):13 return f'{type(self)}: {self._message}'14def create_network(node):15 if node['type'] == 'term':16 return InputGate()17 elif node['type'] == 'not':18 return NotGate(create_network(node['input']))19 elif node['type'] == 'and':20 return AndGate(create_network(n) for n in node['inputs'])21 elif node['type'] == 'or':22 return OrGate(create_network(n) for n in node['inputs'])23 else:24 raise ConfigError(f"Invalid node type \"{node['type']}\"")25parser = argparse.ArgumentParser(description='Evaluate a Boolean function.')26parser.add_argument('--config', '-c',27 dest='config',28 default='config.yaml',29 help='Path of YAML file describing the function.')30args = parser.parse_args()31with open(args.config) as config_file:32 network = create_network(yaml.safe_load(config_file))33print(network)34template = network.template()35for row in csv.reader(stdin):36 try:37 value = network.value(bool(int(value.strip())) for value in row)38 print(template.format(*[int(s) for s in row]) + ' = ' + str(int(value)))39 except IndexError:...
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!!