How to use verify_step method in grail

Best Python code snippet using grail_python

sign_up.py

Source:sign_up.py Github

copy

Full Screen

...23 error_id = set_error_message(message=message)24 return redirect(url_for("auth.error", error=error_id))25@bp.get("/step1")26@login_block27@verify_step(1)28def step1():29 email = session['social.kakao.email']30 code_id = session['social.kakao.code_id']31 code: Code = Code.query.filter_by(32 id=code_id,33 email=email34 ).first()35 if code is None:36 return to(message="만료된 이메일 인증 요청입니다. 다시 시도해주세요.")37 if code.is_expired() or code.is_used():38 return to(message="만료된 이메일 인증 요청입니다. 다시 시도해주세요.")39 return render_template(40 "kakao/sign-up/step1.html",41 error=get_error_message(),42 email=environ['SMTP_USER']43 )44@bp.post("/step1")45@verify_step(1)46def step1_post():47 email = session['social.kakao.email']48 code_id = session['social.kakao.code_id']49 code: Code = Code.query.filter_by(50 id=code_id,51 email=email52 ).first()53 if code is None:54 return to(message="만료된 이메일 인증 요청입니다. 다시 시도해주세요.")55 if code.is_expired() or code.is_used():56 return to(message="만료된 이메일 인증 요청입니다. 다시 시도해주세요.")57 if code.code == request.form.get("code", "undefined"):58 session['social.kakao.step'] = 259 # used in step160 del session['social.kakao.code_id']61 return redirect(url_for("social.kakao.sign_up.step2"))62 error_id = set_error_message(message="인증 코드가 올바르지 않습니다.")63 return redirect(url_for("social.kakao.sign_up.step1", error=error_id))64@bp.get("/step2")65@login_block66@verify_step(2)67def step2():68 try:69 email = session['social.kakao.email']70 except KeyError:71 return to(message="올바른 요청이 아닙니다")72 tos = TermsOfService.query.order_by(73 TermsOfService.id.desc()74 ).with_entities(75 TermsOfService.id76 ).first()77 privacy = PrivacyPolicy.query.order_by(78 PrivacyPolicy.id.desc()79 ).with_entities(80 PrivacyPolicy.id81 ).first()82 if tos is None or privacy is None:83 return "서비스 이용약관과 개인정보 처리방침이 등록되지 않아 회원가입을 진행 할 수 없습니다."84 session['social.kakao.version'] = {85 "tos": tos.id,86 "privacy": privacy.id87 }88 return render_template(89 "kakao/sign-up/step2.html",90 error=get_error_message()91 )92@bp.post("/step2")93@login_block94@verify_step(2)95def step2_post():96 def _to(message: str):97 error_id = set_error_message(message=message)98 return redirect(url_for("social.kakao.sign_up.step2", error=error_id))99 tos_agree = request.form.get("tos_agree", None) == "on"100 privacy_agree = request.form.get("privacy_agree", None) == "on"101 if tos_agree is False:102 return _to(message="서비스 이용약관에 동의해야 서비스를 이용 할 수 있습니다.")103 if privacy_agree is False:104 return _to(message="개인정보 처리방침에 동의해야 서비스를 이용 할 수 있습니다.")105 try:106 id = session['social.kakao.id']107 email = session['social.kakao.email']108 version = session['social.kakao.version']...

Full Screen

Full Screen

test_nn.py

Source:test_nn.py Github

copy

Full Screen

...18 out = self.conv(x)19 return out20 shape = [1, 1, 28, 28]21 x = torch.randn(*shape)22 verify_step(Model(), [x])23def test_linear():24 class Model(nn.Module):25 def __init__(self):26 super().__init__()27 self.linear = nn.Linear(120, 84)28 def forward(self, x):29 out = self.linear(x)30 return out31 shape = [32, 120]32 x = torch.randn(*shape)33 verify_step(Model(), [x])34def test_sum():35 class Model(nn.Module):36 def __init__(self):37 super().__init__()38 def forward(self, x):39 out = torch.sum(x)40 return out41 shape = [32, 120]42 x = torch.randn(*shape)43 verify_step(Model(), [x], jit_script=False, tol=5e-4)44def test_pad():45 class Model(nn.Module):46 def __init__(self):47 super().__init__()48 def forward(self, x):49 pad = (1, 2, 3, 4, 5, 6)50 out = torch.nn.functional.pad(x, pad, "constant", 2)51 return out52 shape = [32, 120, 20]53 x = torch.randn(*shape)54 verify_step(Model(), [x], jit_script=False)55def test_gelu():56 """GeLU supports approximation since https://github.com/pytorch/pytorch/pull/72826"""57 class Model(nn.Module):58 def __init__(self):59 super().__init__()60 self.gelu = torch.nn.GELU("none")61 def forward(self, x):62 return self.gelu(x)63 shape = [5, 5]64 t_x_cpu = torch.randn(shape, requires_grad=True)65 verify_step(Model(), [t_x_cpu], jit_script=False)66 verify_step(Model(), [t_x_cpu], jit_script=False, with_backward=True)67@pytest.mark.parametrize("dtype", [torch.float32, torch.float16])68@pytest.mark.parametrize("norm_type", [1, 2])69def test_embedding(dtype, norm_type):70 class Model(nn.Module):71 def __init__(self):72 super().__init__()73 self.embedding = nn.Embedding(10, 3, norm_type=norm_type, dtype=dtype)74 def forward(self, x_input):75 return self.embedding(x_input)76 x = torch.randint(10, (3, 3))77 verify_step(Model(), [x], jit_script=False)78def test_softmax():79 class Model(nn.Module):80 def __init__(self):81 super().__init__()82 self.softmax = nn.Softmax()83 def forward(self, x_input):84 return self.softmax(x_input)85 shape = (3, 3)86 t_x_cpu = torch.randn(shape, requires_grad=True)87 verify_step(Model(), [t_x_cpu], jit_script=False)88 verify_step(Model(), [t_x_cpu], jit_script=False, with_backward=True)89@pytest.mark.parametrize("dtype", [torch.float32])90@pytest.mark.parametrize("p", [0.2, 0.6])91def test_dropout(p, dtype):92 class Model(nn.Module):93 def __init__(self):94 super().__init__()95 self.dropout = nn.Dropout(p=p)96 def forward(self, x_input):97 return self.dropout(x_input)98 def check_dropout(x, y, dx=None, dy=None):99 x, y = x.cpu().detach().numpy(), y.cpu().detach().numpy()100 mask = y != 0101 expected = mask * x / (1 - p)102 check(expected, y)...

Full Screen

Full Screen

MapMetricStepTests.py

Source:MapMetricStepTests.py Github

copy

Full Screen

1import unittest2from dto.CacheMetricsDTO import CacheMetricsDTO3from etl.Pipeline import Pipeline4from etl.PipelineStep import PipelineStep5from steps.MapMetricStep import MapMetricStep6class MockPipelineSetupStep(PipelineStep):7 def __init__(self):8 super().__init__(self.__class__.__name__)9 def run_step(self, pipeline_context):10 mock_payload = {}11 mock_payload['mock_key'] = 'mock_value'12 mock_dto = CacheMetricsDTO(mock_payload)13 metrics = [mock_dto]14 pipeline_context.add_var('metrics_list', metrics)15class MockVerifyPipelineStep(PipelineStep):16 def __init__(self, verify_key):17 super().__init__(self.__class__.__name__)18 self.__verify_key = verify_key19 self.__assert_flag = False20 def run_step(self, pipeline_context):21 self.__assert_flag = (pipeline_context.get_var('metrics_list')[0].get_metric_var(self.__verify_key) == 'mock_value')22 def get_assert_flag(self):23 return self.__assert_flag24class MapMetricsStepTests(unittest.TestCase):25 def test_step_maps_direct(self):26 pipeline = Pipeline()27 pipeline.add_step(MockPipelineSetupStep())28 pipeline.add_step(MapMetricStep('mock_key', 'mock_key'))29 verify_step = MockVerifyPipelineStep('mock_key')30 pipeline.add_step(verify_step)31 pipeline.run()32 self.assertEqual(verify_step.get_assert_flag(), True)33 def test_step_maps_rename(self):34 pipeline = Pipeline()35 pipeline.add_step(MockPipelineSetupStep())36 pipeline.add_step(MapMetricStep('mock_key', 'mock_key2'))37 verify_step = MockVerifyPipelineStep('mock_key2')38 pipeline.add_step(verify_step)39 pipeline.run()40 self.assertEqual(verify_step.get_assert_flag(), True)41if __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 grail 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