Best Python code snippet using localstack_python
test_ssm.py
Source: test_ssm.py
...16 assert "Parameters" in response17 assert isinstance(response["Parameters"], list)18 def test_put_parameters(self, ssm_client, create_parameter):19 param_name = f"param-{short_uid()}"20 create_parameter(21 Name=param_name,22 Description="test",23 Value="123",24 Type="String",25 )26 _assert(param_name, param_name, ssm_client)27 _assert(f"/{param_name}", param_name, ssm_client) # TODO: not valid28 # TODO botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetParameter operation: Parameter name: can't be prefixed with "ssm" (case-insensitive). If formed as a path, it can consist of sub-paths divided by slash symbol; each sub-path can be formed as a mix of letters, numbers and the following 3 symbols .-_29 def test_hierarchical_parameter(self, ssm_client, create_parameter):30 param_a = f"{short_uid()}"31 create_parameter(32 Name=f"/{param_a}/b/c",33 Value="123",34 Type="String",35 )36 _assert(f"/{param_a}/b/c", f"/{param_a}/b/c", ssm_client)37 _assert(f"/{param_a}//b//c", f"/{param_a}/b/c", ssm_client)38 _assert(f"{param_a}/b//c", f"/{param_a}/b/c", ssm_client)39 # TODO botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetParameter operation: WithDecryption flag must be True for retrieving a Secret Manager secret.40 def test_get_secret_parameter(self, ssm_client, secretsmanager_client, create_secret):41 secret_name = f"test_secret-{short_uid()}"42 create_secret(43 Name=secret_name,44 SecretString="my_secret",45 Description="testing creation of secrets",46 )47 result = ssm_client.get_parameter(Name=f"/aws/reference/secretsmanager/{secret_name}")48 assert f"/aws/reference/secretsmanager/{secret_name}" == result.get("Parameter").get("Name")49 assert "my_secret" == result.get("Parameter").get("Value")50 source_result = result.get("Parameter").get("SourceResult")51 assert source_result is not None, "SourceResult should be present"52 assert type(source_result) is str, "SourceResult should be a string"53 # TODO: botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetParameter operation: WithDecryption flag must be True for retrieving a Secret Manager secret.54 def test_get_inexistent_secret(self, ssm_client):55 with pytest.raises(ssm_client.exceptions.ParameterNotFound):56 ssm_client.get_parameter(Name="/aws/reference/secretsmanager/inexistent")57 # TODO: AssertionError: assert '/aws/reference/secretsmanager/9763a545_test_secret_params' in ['inexistent_param', '/aws/reference/secretsmanager/inexistent_secret']58 def test_get_parameters_and_secrets(59 self, ssm_client, secretsmanager_client, create_parameter, create_secret60 ):61 param_name = f"param-{short_uid()}"62 secret_path = "/aws/reference/secretsmanager/"63 secret_name = f"{short_uid()}_test_secret_params"64 complete_secret = secret_path + secret_name65 create_parameter(66 Name=param_name,67 Description="test",68 Value="123",69 Type="String",70 )71 create_secret(72 Name=secret_name,73 SecretString="my_secret",74 Description="testing creation of secrets",75 )76 response = ssm_client.get_parameters(77 Names=[78 param_name,79 complete_secret,80 "inexistent_param",81 secret_path + "inexistent_secret",82 ]83 )84 found = response.get("Parameters")85 not_found = response.get("InvalidParameters")86 for param in found:87 assert param["Name"] in [param_name, complete_secret]88 for param in not_found:89 # TODO: AssertionError: assert '/aws/reference/secretsmanager/9763a545_test_secret_params' in ['inexistent_param', '/aws/reference/secretsmanager/inexistent_secret']90 assert param in ["inexistent_param", secret_path + "inexistent_secret"]91 def test_get_parameters_by_path_and_filter_by_labels(self, ssm_client, create_parameter):92 prefix = f"/prefix-{short_uid()}"93 path = f"{prefix}/path"94 value = "value"95 param = create_parameter(Name=path, Value=value, Type="String")96 ssm_client.label_parameter_version(97 Name=path, ParameterVersion=param["Version"], Labels=["latest"]98 )99 list_of_params = ssm_client.get_parameters_by_path(100 Path=prefix, ParameterFilters=[{"Key": "Label", "Values": ["latest"]}]101 )102 assert len(list_of_params["Parameters"]) == 1103 found_param = list_of_params["Parameters"][0]104 assert path == found_param["Name"]105 assert found_param["ARN"]106 assert found_param["Type"] == "String"...
fpn.py
Source: fpn.py
...4243 for m in self.sublayers():44 if isinstance(m, nn.Conv2D):45 n = m._kernel_size[0] * m._kernel_size[1] * m._out_channels46 m.weight = paddle.create_parameter(47 shape=m.weight.shape,48 dtype='float32',49 default_initializer=paddle.nn.initializer.Normal(50 0, math.sqrt(2. / n)))51 elif isinstance(m, nn.BatchNorm2D):52 m.weight = paddle.create_parameter(53 shape=m.weight.shape,54 dtype='float32',55 default_initializer=paddle.nn.initializer.Constant(1.0))56 m.bias = paddle.create_parameter(57 shape=m.bias.shape,58 dtype='float32',59 default_initializer=paddle.nn.initializer.Constant(0.0))6061 def forward(self, x):62 return self.relu(self.bn(self.conv(x)))636465class FPN(nn.Layer):66 def __init__(self, in_channels, out_channels):67 super(FPN, self).__init__()6869 # Top layer70 self.toplayer_ = Conv_BN_ReLU(71 in_channels[3], out_channels, kernel_size=1, stride=1, padding=0)72 # Lateral layers73 self.latlayer1_ = Conv_BN_ReLU(74 in_channels[2], out_channels, kernel_size=1, stride=1, padding=0)7576 self.latlayer2_ = Conv_BN_ReLU(77 in_channels[1], out_channels, kernel_size=1, stride=1, padding=0)7879 self.latlayer3_ = Conv_BN_ReLU(80 in_channels[0], out_channels, kernel_size=1, stride=1, padding=0)8182 # Smooth layers83 self.smooth1_ = Conv_BN_ReLU(84 out_channels, out_channels, kernel_size=3, stride=1, padding=1)8586 self.smooth2_ = Conv_BN_ReLU(87 out_channels, out_channels, kernel_size=3, stride=1, padding=1)8889 self.smooth3_ = Conv_BN_ReLU(90 out_channels, out_channels, kernel_size=3, stride=1, padding=1)9192 self.out_channels = out_channels * 493 for m in self.sublayers():94 if isinstance(m, nn.Conv2D):95 n = m._kernel_size[0] * m._kernel_size[1] * m._out_channels96 m.weight = paddle.create_parameter(97 shape=m.weight.shape,98 dtype='float32',99 default_initializer=paddle.nn.initializer.Normal(100 0, math.sqrt(2. / n)))101 elif isinstance(m, nn.BatchNorm2D):102 m.weight = paddle.create_parameter(103 shape=m.weight.shape,104 dtype='float32',105 default_initializer=paddle.nn.initializer.Constant(1.0))106 m.bias = paddle.create_parameter(107 shape=m.bias.shape,108 dtype='float32',109 default_initializer=paddle.nn.initializer.Constant(0.0))110111 def _upsample(self, x, scale=1):112 return F.upsample(x, scale_factor=scale, mode='bilinear')113114 def _upsample_add(self, x, y, scale=1):115 return F.upsample(x, scale_factor=scale, mode='bilinear') + y116117 def forward(self, x):118 f2, f3, f4, f5 = x119 p5 = self.toplayer_(f5)120
...
lstm.py
Source: lstm.py
...5 super(LSTM, self).__init__()6 self.input_size = input_size7 self.hidden_size = hidden_size8 self.output_size = output_size9 self.W_hi = LSTM.create_parameter(hidden_size, hidden_size)10 self.W_hf = LSTM.create_parameter(hidden_size, hidden_size)11 self.W_ho = LSTM.create_parameter(hidden_size, hidden_size)12 self.W_hh = LSTM.create_parameter(hidden_size, hidden_size)13 self.W_xi = LSTM.create_parameter(hidden_size, input_size)14 self.W_xf = LSTM.create_parameter(hidden_size, input_size)15 self.W_xo = LSTM.create_parameter(hidden_size, input_size)16 self.W_xh = LSTM.create_parameter(hidden_size, input_size)17 self.b_i = LSTM.create_parameter(hidden_size, 1)18 self.b_f = LSTM.create_parameter(hidden_size, 1)19 self.b_o = LSTM.create_parameter(hidden_size, 1)20 self.b_h = LSTM.create_parameter(hidden_size, 1)21 self.W_hy = LSTM.create_parameter(output_size, hidden_size)22 self.b_y = LSTM.create_parameter(output_size, 1)23 def get_gradient_norm(self, norm=2):24 return [p.grad.data.norm(norm).item() for p in self.parameters()]25 def get_parameter_names(self):26 return [name for name, _ in self.named_parameters()]27 @staticmethod28 def create_parameter(*size):29 parameter = nn.Parameter(torch.FloatTensor(*size))30 parameter.requires_grad = True31 nn.init.xavier_uniform_(parameter)32 return parameter33 def forward(self, input, hidden, memory):34 i = torch.sigmoid(self.W_hi @ hidden.T + self.W_xi @ input.view(-1, 1) + self.b_i).T35 f = torch.sigmoid(self.W_hf @ hidden.T + self.W_xf @ input.view(-1, 1) + self.b_f).T36 o = torch.sigmoid(self.W_ho @ hidden.T + self.W_xo @ input.view(-1, 1) + self.b_o).T37 memory_ = torch.tanh(self.W_hh @ hidden.T + self.W_xh @ input.view(-1, 1) + self.b_h).T38 memory = f * memory + i * memory_39 hidden = o * torch.tanh(memory)40 output = (self.W_hy @ hidden.T + self.b_y).T41 return output, hidden, memory42 def init_hidden(self):...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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!!