Best Python code snippet using autotest_python
test_combine_features.py
Source: test_combine_features.py
...35@pytest.fixture36def set_up_models_optimizers_loss():37 """Set up 2 identical models, optimizers and a loss function. Base net,38 dropout and batch_size can be pass as parameters."""39 def _set_up(base_net=nn.Linear(32 * 32, 128), dropout=0.0, batch_size=1):40 # Setting device41 device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')42 # Set seed43 cuda = {'deterministic': True, 'benchmark': False}44 set_seed_and_random_states(1234, None, cuda)45 # Define data46 # 1 view input47 dtype = torch.float3248 set_up = {}49 set_up['x_1view'] = [torch.randn((batch_size, 1, 32, 32), dtype=dtype, device=device)]50 # Flatten the input for now51 set_up['x_1view'] = [view.view(batch_size, -1) for view in set_up['x_1view']]52 set_up['mask_1view'] = torch.ones((batch_size, 1), dtype=dtype, device=device)53 # 3 views input...
urls.py
Source: urls.py
1from django.conf.urls.defaults import patterns, url2from myproject.lesson.views import *3urlpatterns = patterns('myproject.lesson.views',4 # Examples:5 url(r'^wel/$', 'wel'),6 #*********set up topic******************7 url(r'^set_up/$', 'settopic'),8 url(r'^set_up/topic=&?/$', 'settopic'),9 url(r'^set_up/gettopajax/$', 'topajax'),10 url(r'^set_up/delete/(\d+)/$', 'deletetopiccode'),11 12 #*********set up content******************13 url(r'^setup_sub/$', 'setsub'),14 url(r'^setup_sub/subtopicajaxxxxxx/$', 'filsubtop'),15 url(r'^setup_sub/entercont/$', 'entercont'),16 url(r'^setup_sub/entercontent/(\d+)/$', 'cont'),17 url(r'^setup_sub/delete/(\d+)/$', 'deletecon'),18 #*********set up objectives****************** 19 url(r'^set_up/obj/$', 'setobj'),20 url(r'^set_up/obj/subobjajax/$', 'filobj'),21 url(r'^set_up/obj/objajax/$','obj'),22 url(r'^set_up/obj/objajax/(\d+)/$', 'enterobj'),23 url(r'^set_up/obj/delete/(\d+)/$', 'deleteobj'),24#*********set up instructional resources*****************25 url(r'^set_up/resources/$', 'setresource'),26 url(r'^set_up/resources/resajax/$', 'resajax'),27 url(r'^set_up/resources/enterir/$','enterir'),28 url(r'^set_up/resources/enterir/(\d+)/$','irajax'),29 url(r'^set_up/resources/delete/(\d+)/$','deleteir'),30 #*********set up teacher activities***************** 31 url(r'^set_up/teacher_activities/$', 'tactivities'),32 url(r'^set_up/teacher_activities/tajax/$', 'tajax'),33 url(r'^set_up/teacher_activities/enajax/$', 'entajax'),34 url(r'^set_up/teacher_activities/enajax/(\d+)/$', 'saveta'),35 url(r'^set_up/teacher_activities/delete/(\d+)/$', 'deleteta'),36#*********set up students activities*****************37 url(r'^set_up/students_activities/$', 'sactivities'),38 url(r'^set_up/students_activities/sajax/$', 'sajax'),39 url(r'^set_up/students_activities/ensajax/$', 'ensajax'),40 url(r'^set_up/students_activities/ensajax/(\d+)/$', 'savesa'),41 url(r'^set_up/students_activities/delete/(\d+)/$', 'deletesa'),42#*********EVALUATION*****************43 url(r'^set_up/evaluation/$', 'seteva'),44 url(r'^set_up/evajax/$', 'fileva'),45 url(r'^set_up/eva/evajax/$','eva'),46 url(r'^set_up/eva/evajjax/(\d+)/$', 'entereva'),47 url(r'^set_up/evaluation/delete/(\d+)/$', 'deleteva'),48 #*********lesson count*****************49 url(r'^set_up/lesson_count/$','lesscount'),50 url(r'^set_up/lesson_count/getwa/$','wajax'),51 url(r'^set_up/lesson_count/entwa/$', 'enterwa'),52 url(r'^set_up/lesson_count/entwa/(\d+)/$', 'editwa'),53 #********Lesson Note***********************54 url(r'^note/$', 'setupmynote'),55 url(r'^note/getnote/$','notajax'),56 url(r'^note/upload/(\d+)/$','uploadnote'),57 url(r'^note/view/(\d+)/$','viewnote'),58 url(r'^note/edit/(\d+)/$','reviewnote'),59 #********Questions Bank ***********************60 url(r'^ExamQuest/$','examquests'),61 url(r'^ExamQuest/getquest/$', 'getexamquest'),62 url(r'^ExamQuest/view/(\d+)/$','downquest'),63 url(r'^ExamQuest/upload/(\d+)/$','upquest'),64 url(r'^ExamQuest/newupload/(w+)/(w+)/(w+)/(w+)/$','upquestnew'),65#**************Lesson Plan***************66 url(r'^plan/$', 'setupmyplan'),67#**************Admin***************68 # url(r'^admin/$', 'admins'),...
test_requests.py
Source: test_requests.py
1import requests2import json3from tests.data.create_user import CreateUser4from tests.data.create_user_response import CreateUserResponse5from utils.file_reader import read_file6from tests.base_test import set_up7def test_get_users(set_up):8 response = requests.get(set_up['base_uri'] + 'users?page=2', headers=set_up['headers'])9 assert response.status_code == 20010 data = json.loads(response.text)11 assert data['page'] == 212def test_get_user_not_found(set_up):13 response = requests.get(set_up['base_uri'] + 'users/100', headers=set_up['headers'])14 assert response.status_code == 40415def test_delete_request(set_up):16 response = requests.delete(set_up['base_uri'] + 'users/2', headers=set_up['headers'])17 assert response.status_code == 20418def test_post_request(set_up):19 body = read_file('data.json')20 response = requests.post(set_up['base_uri'] + 'users', json=body['user_data'][0], headers=set_up['headers'])21 assert response.status_code == 20122 data = json.loads(response.text)23 assert data['name'] == body['user_data'][0]['name']24 assert data['job'] == body['user_data'][0]['job']25def test_put_request(set_up):26 body = read_file('data.json')27 response = requests.put(set_up['base_uri'] + 'users/2', json=body['user_data'][1], headers=set_up['headers'])28 assert response.status_code == 20029 data = json.loads(response.text)30 assert data['name'] == body['user_data'][1]['name']31 assert data['job'] == body['user_data'][1]['job']32def test_patch_request(set_up):33 body = read_file('data.json')34 response = requests.patch(set_up['base_uri'] + 'users/2', json=body['user_data'][2], headers=set_up['headers'])35 assert response.status_code == 20036 data = json.loads(response.text)37 assert data['job'] == body['user_data'][2]['job']38def test_post_login_successful(set_up):39 body = read_file('data.json')40 print(body['login_data'][0])41 response = requests.post(set_up['base_uri'] + 'login', json=body['login_data'][0], headers=set_up['headers'])42 assert response.status_code == 20043 data = json.loads(response.text)44 assert data['token'] == 'QpwL5tke4Pnpja7X4'45def test_post_login_unsuccessful(set_up):46 body = read_file('data.json')47 response = requests.post(set_up['base_uri'] + 'login', json=body['login_data'][1], headers=set_up['headers'])48 assert response.status_code == 40049 data = json.loads(response.text)50 assert data['error'] == "Missing password"51def test_post_register_successful(set_up):52 user = CreateUser()53 user.set_email('eve.holt@reqres.in')54 user.set_password('pistol')55 # converts the object to json56 user_json = json.dumps(user.__dict__)57 # json.loads converts the json to a dictionary58 response = requests.post(set_up['base_uri'] + 'register', json=json.loads(user_json), headers=set_up['headers'])59 assert response.status_code == 20060 # get the response body as a dictionary61 data = json.loads(response.text)62 # create a new object from the dictionary63 user_response = CreateUserResponse(**data)64 assert user_response.get_id() == 4...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!