Best Python code snippet using molecule_python
test_models.py
Source: test_models.py
...35 )36 view = ViewFactory(song=self.song, user=UserFactory())37 self.song.artists.add(artist)38 39 def test_created(self):40 self.assertEqual(self.song.name, "nf")41 self.assertEqual(self.song.download_url, "t.com")42 self.assertEqual(self.song.duration, 1.55)43 artist = self.song.artists.all()[0]44 self.assertEqual(artist.name, "nf")45 self.assertEqual(self.song.album.name, "the search")46 self.assertEqual(self.song.genre.name, "rap")47 self.assertEqual(self.song.total_views, 1)48 self.assertTrue(self.song.image)49 self.assertEqual(str(self.song), "nf")50class SubtitleTest(TestCase):51 def setUp(self):52 # mocking open function in save method of Subtitle class53 mock_open = mock.mock_open() 54 with mock.patch("builtins.open", mock_open):55 with open("test.srt") as mock_f:56 mock_f.read.return_value = "subtitle text" # value returned to fill in Subtitle.text57 song = SongFactory(name="nf", duration=1.55)58 self.subtitle = Subtitle(59 song = song,60 file = "test.srt",61 language = "P",62 )63 self.subtitle.save()64 65 def test_created(self):66 self.assertEqual(self.subtitle.song.name, "nf")67 self.assertEqual(self.subtitle.language, "P")68 self.assertEqual(self.subtitle.text, "subtitle text")69 self.assertFalse(self.subtitle.file) # file deleted after reading in save method70class AlbumTest(TestCase):71 def setUp(self):72 artist = ArtistFactory(name="nf")73 genre = GenreFactory(name="rap")74 self.album = Album(75 name = "the search",76 artist = artist,77 genre = genre,78 )79 self.album.save()80 self.song = SongFactory(name="the search", album=self.album, duration=1.55)81 82 def test_created(self):83 self.assertEqual(self.album.name, "the search")84 self.assertEqual(self.album.artist.name, "nf")85 self.assertEqual(self.album.genre.name, "rap")86 self.assertEqual(self.album.total_songs, 1)87 self.assertTrue(self.song in self.album.get_songs())88class ViewTest(TestCase):89 def setUp(self):90 self.user = UserFactory(username="test")91 self.song = SongFactory(name="the search", duration=1.55)92 self.view = View.objects.create(user=self.user, song=self.song)93 94 def test_created(self):95 self.assertEqual(self.view.user.username, "test")96 self.assertEqual(self.view.song.name, "the search")97 self.assertEqual(str(self.view), "test-the search view")98 with self.assertRaises(IntegrityError):99 View.objects.create(user=self.user, song=self.song)100class LikeTest(TestCase):101 def setUp(self):102 self.user = UserFactory(username="test")103 self.song = SongFactory(name="the search", duration=1.55)104 self.like = Like.objects.create(user=self.user, song=self.song)105 106 def test_created(self):107 self.assertEqual(self.like.user.username, "test")108 self.assertEqual(self.like.song.name, "the search")109 self.assertEqual(str(self.like), "test-the search like")110 with self.assertRaises(IntegrityError):111 Like.objects.create(user=self.user, song=self.song)112 113class PlayListTest(TestCase):114 def setUp(self):115 user = UserFactory(username="test")116 self.song = SongFactory(name="the search", duration=1.55)117 self.playlist = PlayList.objects.create(name="my-play-list", user=user)118 self.playlist.songs.add(self.song)119 120 def test_created(self):121 self.assertEqual(self.playlist.name, "my-play-list")122 self.assertEqual(self.playlist.image.name, "playlist/default.png")123 self.assertEqual(self.playlist.user.username, "test")124 self.assertTrue(self.song in self.playlist.songs.all())...
Assingment_5.py
Source: Assingment_5.py
1import json2import numpy as np3import matplotlib.pyplot as plt4import math5from sklearn import linear_model6from sklearn.metrics import mean_absolute_error, mean_squared_error7from pylab import polyfit, poly1d8from scipy.stats.stats import pearsonr9traindata = 'training.json'10testdata = 'testing.json'11 12def getData():13 global training_data14 global testing_data15 with open(traindata) as json_data_1:16 training_data = json.load(json_data_1, encoding = 'ISO-8859-1')17 with open(testdata) as json_data_2:18 testing_data = json.load(json_data_2, encoding = 'ISO-8859-1')19def formatData():20 global train_karma21 global train_created22 global test_karma23 global test_created24 global TRAIN_CREATED25 global TEST_CREATED26 27 train_karma = []28 train_created = []29 test_karma = []30 test_created = []31 TRAIN_CREATED = []32 TEST_CREATED = []33 34 for i in training_data:35 if not i.has_key('karma') or not i.has_key('created'):36 i["karma"] = 0;37 i["created"] = 1509813038 38 train_karma.append(i["karma"])39 train_created.append(i["created"])40 for j in testing_data:41 if not j.has_key('karma') or not j.has_key('created'):42 j["karma"] = 0;43 j["created"] = 150981303844 test_karma.append(j["karma"])45 test_created.append(j["created"])46 47 TRAIN_CREATED = np.array([train_created])48 TRAIN_CREATED = TRAIN_CREATED.T49 TEST_CREATED = np.array([test_created])50 TEST_CREATED = TEST_CREATED.T51def trainAndPlot():52 global model53 54 X,y = TRAIN_CREATED, train_karma55 x = train_created56 57 model = linear_model.LinearRegression()58 model.fit(X, y)59 60 fit = np.polyfit(x, y, deg=1)61 fit_fn = np.poly1d(fit)62 plt.plot(X, y, 'ro', X, fit_fn(X), 'b')63 plt.show()64 #plt.savefig('HackerNewsPlot.png')65 print("a: ", model.coef_)66 print("b: ", model.intercept_)67def calcMAE():68 train_karma_pred = model.predict(TRAIN_CREATED)69 test_karma_pred = model.predict(TEST_CREATED)70 71 train_MAE = mean_absolute_error(train_karma, train_karma_pred)72 test_MAE = mean_absolute_error(test_karma, test_karma_pred)73 74 print('Train MAE: ', train_MAE)75 print('Test MAE: ', test_MAE)76def calcMSE():77 train_karma_pred = model.predict(TRAIN_CREATED)78 test_karma_pred = model.predict(TEST_CREATED)79 train_MSE = mean_squared_error(train_karma, train_karma_pred)80 test_MSE = mean_squared_error(test_karma, test_karma_pred)81 train_MSE = math.sqrt(train_MSE)82 test_MSE = math.sqrt(test_MSE)83 84 print('Train MSE: ', train_MSE)85 print('Test MSE: ', test_MSE)86def calcPR():87 train_PR = pearsonr(train_created, train_karma)88 test_PR = pearsonr(test_created, test_karma)89 print('Train PR: ', train_PR)90 print('Test PR: ', test_PR)91def run():92 getData()93 formatData()94 trainAndPlot()95 calcMAE()96 calcMSE()97 calcPR()98 print 'Score: ', model.score(, test_karma)99 print('done')...
ursl.py
Source: ursl.py
1"""proj URL Configuration2The `urlpatterns` list routes URLs to views. For more information please see:3 https://docs.djangoproject.com/en/3.0/topics/http/urls/4Examples:5Function views6 1. Add an import: from my_app import views7 2. Add a URL to urlpatterns: path('', views.home, name='home')8Class-based views9 1. Add an import: from other_app.views import Home10 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')11Including another URLconf12 1. Import the include() function: from django.urls import include, path13 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))14"""15from django.contrib import admin16from django.urls import path17from test_hello_word.views import test_form,test_pk,test_created,test,Test_B_V,Genre_Create,Genre_Update,Genre_List,Genre_Delete18# from phones import 19urlpatterns = [20 path('admin/', admin.site.urls),21 path('', test),22 path('test_created/', test_created),23 path('test_form/', test_form),24 path('test_form/<int:pk>', test_form),25 path('test_pk/<int:pk>', test_pk),26 path('test_b_v/', Test_B_V.as_view()),27 path('create/', Genre_Create.as_view()),28 path('update/<int:pk>', Genre_Update.as_view()),29 path('list/', Genre_List.as_view()),30 path('delete/<int:pk>', Genre_Delete.as_view())...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Most test automation tools just do test execution automation. Without test design involved in the whole test automation process, the test cases remain ad hoc and detect only simple bugs. This solution is just automation without real testing. In addition, test execution automation is very inefficient.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
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!!