How to use test_hypothesis method in pytest-asyncio

Best Python code snippet using pytest-asyncio_python

tests.py

Source:tests.py Github

copy

Full Screen

1"""This file contains tests for the hypotheses application.2These tests include model tests for Hypothesis objects.3"""4import datetime5from django.test import TestCase6from django.test.client import Client7from django.contrib.auth.models import User8from experimentdb.hypotheses.models import Hypothesis, Manipulation, Effect, Process, Context, Evidence9from experimentdb.proteins.models import Protein10from experimentdb.reagents.models import Chemical11MODELS = [Hypothesis, Manipulation, Effect, Process, Context, Evidence]12class HypothesisModelTests(TestCase):13 """Tests the model attributes of Hypothesis objects contained in the hypotheses app."""14 fixtures = ['test_manipulation','test_protein', 'test_process', 'test_entity', 'test_context', 'test_evidence', 'test_hypothesis']15 16 def setUp(self):17 """Instantiate the test client. Creates a test user."""18 self.client = Client()19 self.test_user = User.objects.create_user('blah', 'blah@blah.com', 'blah')20 self.test_user.is_superuser = True21 self.test_user.save()22 self.client.login(username='blah', password='blah')23 def tearDown(self):24 """Depopulate created model instances from test database."""25 for model in MODELS:26 for obj in model.objects.all():27 obj.delete()28 def test_create_hypothesis_minimal(self):29 """This is a test for creating a new Hypothesis object, with only the minimum fields being entered. It also tests the unicode representation."""30 test_hypothesis = Hypothesis(31 manipulation = Manipulation.objects.get(pk=1), 32 effect = Effect.objects.get(pk=1),33 process = Process.objects.get(pk=1)34 )35 test_hypothesis.save()36 self.assertEquals(test_hypothesis.__unicode__(), "Fixture Protein Overexpression positively regulates glucose import")37 38 def test_create_hypothesis_all_fields_process(self):39 """This is a test for creating a new Hypothesis object, with all fields being entered. There is one test for process and one for entity (since both cannot be entered simultaneously). It also tests the unicode representation."""40 test_hypothesis = Hypothesis(41 manipulation = Manipulation.objects.get(pk=1), 42 effect = Effect.objects.get(pk=1),43 process = Process.objects.get(pk=1),44 context = Context.objects.get(pk=1),45 )46 test_hypothesis.save()47 test_evidence = Evidence.objects.get(pk=1)48 test_hypothesis.evidence.add(test_evidence) # tests the addition of evidence as a m2m field49 test_hypothesis.identical_hypotheses.add(test_hypothesis) # tests the addition of a symmetrical hypothesis as a m2m field50 self.assertEquals(test_hypothesis.__unicode__(), 'Fixture Protein Overexpression positively regulates glucose import in Fixture Context')51def test_create_hypothesis_all_fields_entity(self): 52 """This is a test for creating a new Hypothesis object, with all fields being entered. There is one test for process and one for entity (since both cannot be entered simultaneously). It also tests the unicode representation."""53 54 test_hypothesis = Hypothesis(55 manipulation = Manipulation.objects.get(pk=1), 56 effect = Effect.objects.get(pk=1),57 process = Process.objects.get(pk=1),58 context = Context.objects.get(pk=1),59 evidence = Evidence.objects.get(pk=1),60 )61 test_hypothesis.save()62 test_evidence = Evidence.objects.get(pk=1)63 test_hypothesis.evidence.add(test_evidence) # tests the addition of evidence as a m2m field64 test_hypothesis.identical_hypotheses.add(test_hypothesis) # tests the addition of a symmetrical hypothesis as a m2m field 65 self.assertEquals(test_hypothesis.__unicode__(), 'Fixture Protein Overexpression positively regulates glucose import in Fixture Context') 66 67def test_create_hypothesis_create_date(self):68 """This is a test for checking that the create and modified date are being set correctly."""69 test_hypothesis = Hypothesis(70 manipulation = Manipulation.objects.get(pk=1), 71 effect = Effect.objects.get(pk=1),72 process = Process.objects.get(pk=1)73 )74 test_hypothesis.save()75 self.assertEquals(test_hypothesis.__unicode__(), "Fixture Protein Overexpression positively regulates glucose import")76 self.assertEquals(test_hypothesis.create_date, datetime.date.today()) 77 self.assertEquals(test_hypothesis.modified_date, datetime.date.today()) 78 79 80class ManipulationModelTests(TestCase):81 """Tests the model attributes of Manipulation objects contained in the hypotheses app."""82 fixtures = ['test_protein','test_chemical']83 84 def setUp(self):85 """Instantiate the test client. Creates a test user."""86 self.client = Client()87 self.test_user = User.objects.create_user('blah', 'blah@blah.com', 'blah')88 self.test_user.is_superuser = True89 self.test_user.save()90 self.client.login(username='blah', password='blah')91 def tearDown(self):92 """Depopulate created model instances from test database."""93 for model in MODELS:94 for obj in model.objects.all():95 obj.delete()96 def test_create_manipulation_minimal_treatment_protein_added(self):97 """This is a test for creating a new Manipulation object, with only the minimum fields being entered. It also tests the unicode representation. This tests for adding a protein."""98 test_manipulation = Manipulation(99 type = "Treatment",100 protein_added = Protein.objects.get(pk=1)101 )102 test_manipulation.save()103 self.assertEquals(test_manipulation.__unicode__(), "Fixture Protein Treatment")104 def test_create_manipulation_minimal_treatment_chemical(self):105 """This is a test for creating a new Manipulation object, with only the minimum fields being entered. It also tests the unicode representation. This tests for chemcial treatment."""106 test_manipulation = Manipulation(107 type = "Treatment",108 chemical = Chemical.objects.get(pk=1)109 )110 test_manipulation.save()111 self.assertEquals(test_manipulation.__unicode__(), "Test Chemical Treatment")112 def test_create_manipulation_minimal_overexpression(self):113 """This is a test for creating a new Manipulation object, with only the minimum fields being entered. It also tests the unicode representation. This tests for protein overexpression."""114 test_manipulation = Manipulation(115 type = "Overexpression",116 protein = Protein.objects.get(pk=1)117 )118 test_manipulation.save()119 self.assertEquals(test_manipulation.__unicode__(), "Fixture Protein Overexpression")120 def test_create_manipulation_minimal_knockdown(self):121 """This is a test for creating a new Manipulation object, with only the minimum fields being entered. It also tests the unicode representation. This tests for protein knockdown."""122 test_manipulation = Manipulation(123 type = "Knockdown",124 protein = Protein.objects.get(pk=1)125 )126 test_manipulation.save()127 self.assertEquals(test_manipulation.__unicode__(), "Fixture Protein Knockdown") 128 def test_create_manipulation_minimal_knockout(self):129 """This is a test for creating a new Manipulation object, with only the minimum fields being entered. It also tests the unicode representation. This tests for knockout."""130 test_manipulation = Manipulation(131 type = "Knockout",132 protein = Protein.objects.get(pk=1)133 )134 test_manipulation.save()...

Full Screen

Full Screen

5 Model.py

Source:5 Model.py Github

copy

Full Screen

1from tqdm import tqdm2import numpy as np3from keras.models import Input, Model,Sequential4from keras.layers import Dense,Dropout,Concatenate,Input5import tensorflow as tf67##labels = ["[0,neutral]","[1,entailment]",,"[2,contradiction]"]8embeddings = np.load("Sentence_Embeddings.npy",allow_pickle = True)9encoded_labels = np.load("encoded_labels.npy",allow_pickle = True)10print("Here")1112test_premise = [embeddings[i] for i in range(9843*2) if i%2==0]13test_premise = np.array(test_premise)1415test_hypothesis =[embeddings[i] for i in range(9843*2) if i%2==1]16test_hypothesis = np.array(test_hypothesis)1718test_labels = encoded_labels[:9843]19print("Here")20train_premise = [embeddings[i] for i in range(9843*2,len(embeddings)) if i%2==0]21train_premise = np.array(train_premise)2223train_hypothesis =[embeddings[i] for i in range(9843*2,len(embeddings)) if i%2==1]24train_hypothesis = np.array(train_hypothesis)2526train_labels = encoded_labels[9843:len(embeddings)]27print("Here")2829Premise = Input(shape=(300,))30Hypothesis = Input(shape=(300,))31Merged = Concatenate(axis=1)([Premise,Hypothesis])32x = Dense(300,activation="tanh",use_bias=True)(Merged)33for i in range(2):34 x = Dense(300,activation="tanh",use_bias=True ,kernel_regularizer='l2')(x)35 Dropout(0.3)3637x = Dense(3,activation="softmax",use_bias=True)(x)38model = Model(inputs=[Premise,Hypothesis],outputs=x)39model.compile(optimizer="adam",loss="sparse_categorical_crossentropy",metrics="accuracy")40#model.summary()41model.fit(42 x = [train_premise,train_hypothesis],43 y = train_labels,44 batch_size=64,45 epochs=30,46 validation_data=([test_premise,test_hypothesis],test_labels)47 ) ...

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 pytest-asyncio 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