Best Python code snippet using pytest-bdd_python
tasklet_fusion_test.py
Source:tasklet_fusion_test.py
...101 assert (num_tasklet_fusions == 1)102 A = np.ones((5, 5), dtype=np_datatype)103 result = sdfg(A=A)104 assert np.allclose(result, 2 * (A + 1))105def test_same_name():106 @dace.program107 def test_same_name(A: datatype[5, 5]):108 B = A + 1109 C = A * 3110 return B + C111 sdfg = test_same_name.to_sdfg(simplify=True)112 num_map_fusions = sdfg.apply_transformations_repeated(MapFusion)113 assert (num_map_fusions == 2)114 num_tasklet_fusions = sdfg.apply_transformations_repeated(TaskletFusion)115 assert (num_tasklet_fusions == 2)116 A = np.ones((5, 5), dtype=np_datatype)117 result = sdfg(A=A)118 assert np.allclose(result, (A + 1) + (A * 3))119def test_same_name_different_memlet():120 @dace.program121 def test_same_name_different_memlet(A: datatype[5, 5], B: datatype[5, 5]):122 C = B * 3123 D = A + 1124 return D + C125 sdfg = test_same_name_different_memlet.to_sdfg(simplify=True)126 num_map_fusions = sdfg.apply_transformations_repeated(MapFusion)127 assert (num_map_fusions == 2)128 num_tasklet_fusions = sdfg.apply_transformations_repeated(TaskletFusion)129 assert (num_tasklet_fusions == 2)130 A = np.ones((5, 5), dtype=np_datatype)131 B = np.ones((5, 5), dtype=np_datatype) * 2132 result = sdfg(A=A, B=B)133 assert np.allclose(result, (A + 1) + (B * 3))134def test_tasklet_fusion_multiline():135 @dace.program136 def test_tasklet_fusion_multiline(A: datatype):137 B = A + 1138 C = dace.define_local([1], datatype)139 D = dace.define_local([1], datatype)140 with dace.tasklet:141 b << B[0]142 c >> C[0]143 d >> D[0]144 d = b * 3145 c = b + 3146 return C + D147 sdfg = test_tasklet_fusion_multiline.to_sdfg(simplify=True)148 num_tasklet_fusions = sdfg.apply_transformations(TaskletFusion)149 assert (num_tasklet_fusions == 1)150 result = sdfg(A=1)151 assert (result[0] == 11)152@pytest.mark.parametrize('with_data', [pytest.param(True), pytest.param(False)])153@pytest.mark.parametrize('language', [pytest.param('CPP'), pytest.param('Python')])154def test_map_with_tasklets(language: str, with_data: bool):155 sdfg = _make_sdfg(language, with_data)156 sdfg.compile()157 sdfg.simplify()158 num = sdfg.apply_transformations_repeated(TaskletFusion)159 assert num == 3160 func = sdfg.compile()161 A = np.arange(1, N + 1, dtype=np_datatype)162 B = np.arange(1, M + 1, dtype=np_datatype)163 C = np.zeros((M, ), dtype=np_datatype)164 func(A=A, B=B, C=C)165 ref = map_with_tasklets.f(A, B)166 assert (np.allclose(C, ref))167if __name__ == '__main__':168 test_basic()169 test_same_name()170 test_same_name_different_memlet()171 test_tasklet_fusion_multiline()172 test_map_with_tasklets(language='Python', with_data=False)173 test_map_with_tasklets(language='Python', with_data=True)174 test_map_with_tasklets(language='CPP', with_data=False)...
test_tasklet_fusion.py
Source:test_tasklet_fusion.py
...18 assert sdfg.apply_transformations(TaskletFusion) == 119 result = np.empty((5, 5), dtype=np.float32)20 sdfg(A=np.ones_like(result), __return=result)21 assert np.allclose(result, 2 * (np.ones_like(result) + 1))22def test_same_name():23 @dace.program24 def test_same_name(A: dace.float32[5, 5]):25 B = A + 126 C = A * 327 return B + C28 sdfg: dace.SDFG = test_same_name.to_sdfg()29 assert sdfg.apply_transformations_repeated(MapFusion) == 230 assert sdfg.apply_transformations_repeated(TaskletFusion) == 231 result = np.empty((5, 5), dtype=np.float32)32 A = np.ones_like(result)33 sdfg(A=A, __return=result)34 assert np.allclose(result, A + 1 + A * 3)35def test_same_name_diff_memlet():36 @dace.program37 def test_same_name_diff_memlet(A: dace.float32[5, 5], B: dace.float32[5,38 5]):...
test_authentication.py
Source:test_authentication.py
1from django.contrib.auth.models import User2from django.urls import reverse3from rest_framework import status4from rest_framework.test import APITestCase5from rest_framework.authtoken.models import Token6class RegTestCase(APITestCase):7 def setUp(self):8 self.user = User.objects.create_user(9 username="test_same_name", password="Password@123")10 def test_registration_regular_registration(self):11 data = {12 "username": "testcase1",13 "email": "test1@example.com",14 "password": "Password@123",15 "password2": "Password@123"16 }17 get_response = self.client.post(reverse('register'), data)18 self.assertEqual(get_response.status_code, status.HTTP_201_CREATED)19 def test_registration_short_password(self):20 data_password_check = {21 "username": "testcase2",22 "email": "test2@example.com",23 "password": "Pas",24 "password2": "Pas"25 }26 get_response = self.client.post(27 reverse('register'), data_password_check)28 self.assertEqual(get_response.status_code, status.HTTP_400_BAD_REQUEST)29 def test_registration_password_mismatch(self):30 data_password_check = {31 "username": "testcase2",32 "email": "test2@example.com",33 "password": "Pass1",34 "password2": "Pass"35 }36 get_response = self.client.post(37 reverse('register'), data_password_check)38 self.assertEqual(get_response.status_code, status.HTTP_400_BAD_REQUEST)39 def test_registration_same_name(self):40 data_same_name_check = {41 "username": "test_same_name",42 "email": "test3@example.com",43 "password": "Password@123",44 "password2": "Password@123"45 }46 get_response = self.client.post(47 reverse('register'), data_same_name_check)48 self.assertEqual(get_response.status_code, status.HTTP_400_BAD_REQUEST)49 def test_registration_wrong_email(self):50 data_email_check = {51 "username": "testcase4",52 "email": "test4@",53 "password": "Password@123",54 "password2": "Password@123"55 }56 get_response = self.client.post(reverse('register'), data_email_check)57 self.assertEqual(get_response.status_code, status.HTTP_400_BAD_REQUEST)58class LoginTestCase(APITestCase):59 def setUp(self):60 self.user = User.objects.create_user(61 username="example", password="Password@123")62 def test_login(self):63 data = {64 "username": "example",65 "password": "Password@123"66 }67 get_response = self.client.post(reverse('login'), data)68 self.assertEqual(get_response.status_code, status.HTTP_200_OK)69class LogoutTestCase(APITestCase):70 def setUp(self):71 self.user = User.objects.create_user(72 username="example", password="Password@123")73 def test_logout(self):74 self.token = Token.objects.get(user__username="example")75 self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)76 get_response = self.client.get(reverse('logout'))...
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!!