Best Python code snippet using localstack_python
network_test.py
Source:network_test.py
...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)...
bnn_test.py
Source:bnn_test.py
...9 bnn = BinaryNeuralNetwork(in_dim=in_dim, out_dim=out_dim)10 x = np.random.randn(n_imgs, *in_dim)11 y = np.random.randint(out_dim, size=n_imgs)12 bnn.fit(x, y, x, y)13 vals = bnn.inspect_network(x, y)14 param_file = bnn.param_file15 bnn = BinaryNeuralNetwork(in_dim=in_dim, out_dim=out_dim,16 param_file=param_file)17 vals1 = bnn.inspect_network(x, y)18 assert np.array_equal(vals['score'], vals1['score'])19def test_tnn():20 """Test a ternary neural network."""21 network_params = {22 'conv': [32],23 'max_pool': [True, False],24 'filter_size': 3,25 'fc': [10],26 'bin_weights': [True] * 1,27 'bin_acts': [True] * 1,28 'levels': 3,29 'threshold': 0.2,30 }31 in_dim = (28, 28, 1)32 out_dim = 1033 n_imgs = 10034 bnn = BinaryNeuralNetwork(in_dim=in_dim, out_dim=out_dim,35 network_params=network_params)36 x = np.random.randn(n_imgs, *in_dim)37 y = np.random.randint(out_dim, size=n_imgs)38 bnn.fit(x, y, x, y)39 vals = bnn.inspect_network(x, y)40 param_file = bnn.param_file41 bnn = BinaryNeuralNetwork(in_dim=in_dim, out_dim=out_dim,42 param_file=param_file,43 network_params=network_params)44 vals1 = bnn.inspect_network(x, y)45 assert np.array_equal(vals['score'], vals1['score'])46if __name__ == '__main__':47 test_bnn()...
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!!