How to use get_field_dict method in autotest

Best Python code snippet using autotest_python

test_behaviors.py

Source:test_behaviors.py Github

copy

Full Screen

...55 seo_title = 'name'56 class SharedModel2(SEO):57 class SEO:58 seo_title = 'asdf'59 get_field_dict(SharedModel1)['name']60 get_field_dict(SharedModel2)['asdf']61class TestMultiInheritMRO(unittest.TestCase):62 def test_improper_mro_multi_inheritance(self):63 class UpperBase(models.Model):64 pass65 with self.assertRaises(ImproperlyConfigured):66 class MultiInherited(UpperBase, Behavior):67 pass68 def test_proper_mro_multi_inheritance(self):69 class UpperBase(models.Model):70 pass71 class MultiInherited(Behavior, UpperBase):72 pass73def get_field_dict(model):74 """75 Make a dictionary of field name -> field class76 """77 return dict((field.name, field) for field in model._meta.fields)78class TestTimestampable(unittest.TestCase):79 def test_bare(self):80 class TestModel(Timestampable):81 pass82 x = TestModel()83 fields = get_field_dict(x)84 self.assertTrue(isinstance(fields['created_at'], models.DateTimeField))85 self.assertTrue(isinstance(fields['updated_at'], models.DateTimeField))86 #@unittest.expectedFailure87 #def test_same_name(self):88 # # This is actually a problem with django, it won't let you have two89 # # model classes with the same name in the same app90 # class TestModel(Timestampable):91 # class Timestampable:92 # created_at = 'asdf'93 #94 # x = TestModel()95 #96 # fields = get_field_dict(x)97 #98 # self.assertTrue(isinstance(fields['asdf'], models.DateTimeField))99 # self.assertTrue(isinstance(fields['updated_at'], models.DateTimeField))100 def test_custom(self):101 # This tests fails if the models share a name. see test_same_name102 class Test2Model(Timestampable):103 class Timestampable:104 created_at = 'asdf'105 x = Test2Model()106 fields = get_field_dict(x)107 self.assertTrue(isinstance(fields['asdf'], models.DateTimeField))108 self.assertTrue(isinstance(fields['updated_at'], models.DateTimeField))109 def test_proxy(self):110 class TestProxyParentModel(Timestampable):111 pass112 class TestProxyProxyModel(TestProxyParentModel):113 class Meta:114 proxy = True115 field_names = [i.attname for i in TestProxyProxyModel._meta.fields]116 # without careful treatment, proxy models117 # could have fields added twice. verify that118 # there are no duplicate field names.119 self.assertTrue(len(set(field_names)) == len(field_names))120class TestValidation(unittest.TestCase):121 def test_bare(self):122 class ValidationTestModel(Validation):123 foo = models.CharField(max_length=1)124 def validate(self):125 raise ValidationError('Generic Error')126 def validate_foo(self):127 raise ValidationError('Foo Error')128 x = ValidationTestModel()129 self.assertFalse(x.is_valid())130 self.assertIsInstance(x.validation_errors(), dict)131 expected_errors = {132 NON_FIELD_ERRORS: [u'Generic Error'],133 'foo': [u'This field cannot be blank.', u'Foo Error']134 }135 self.assertEqual(x.validation_errors(), expected_errors)136 try:137 x.save()138 self.assertTrue(False)139 except ValidationError:140 pass141class TestMergedQuerySet(unittest.TestCase):142 def test_bare(self):143 from django.db.models.query import QuerySet144 class QuerySetTestModel_A(models.Model):145 class QuerySet(QuerySet):146 def foo(self):147 pass148 class QuerySetTestModel_B(models.Model):149 class QuerySet(QuerySet):150 def bar(self):151 pass152 class QuerySetTestModel_C(ManagedQuerySet, QuerySetTestModel_A, QuerySetTestModel_B):153 class QuerySet(QuerySet):154 def baz(self):155 pass156 x = QuerySetTestModel_C()157 self.assertTrue(hasattr(x.QuerySet, 'foo'))158 self.assertTrue(hasattr(x.QuerySet, 'bar'))159 self.assertTrue(hasattr(x.QuerySet, 'baz'))160class TestSEO(unittest.TestCase):161 def test_bare(self):162 class Test3Model(SEO):163 pass164 x = Test3Model()165 fields = get_field_dict(x)166 self.assertTrue(isinstance(fields['seo_title'], models.CharField))167 self.assertTrue(isinstance(fields['seo_description'], models.TextField))168 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))169 def test_overridden_field(self):170 class Test14Model(SEO):171 seo_title = models.IntegerField()172 x = Test14Model()173 fields = get_field_dict(x)174 self.assertTrue(isinstance(fields['seo_title'], models.IntegerField))175 self.assertTrue(isinstance(fields['seo_description'], models.TextField))176 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))177 def test_nonsense_config(self):178 class Test13Model(SEO):179 blahblah = 'foo'180 asdf = models.CharField(max_length=255)181 x = Test13Model()182 fields = get_field_dict(x)183 self.assertTrue(isinstance(fields['seo_title'], models.CharField))184 self.assertTrue(isinstance(fields['seo_description'], models.TextField))185 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))186 def test_override(self):187 class Test4Model(SEO):188 class SEO:189 seo_title = 'foo'190 x = Test4Model()191 fields = get_field_dict(x)192 self.assertTrue(isinstance(fields['foo'], models.CharField))193 self.assertTrue(isinstance(fields['seo_description'], models.TextField))194 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))195 def test_deep_inheritance(self):196 class ParentModel(SEO):197 class SEO:198 seo_title = 'foo'199 class Test7Model(ParentModel):200 class SEO:201 seo_keywords = 'asdfasdf'202 x = Test7Model()203 fields = get_field_dict(x)204 self.assertTrue(isinstance(fields['foo'], models.CharField))205 self.assertTrue(isinstance(fields['seo_description'], models.TextField))206 self.assertTrue(isinstance(fields['asdfasdf'], models.TextField))207 def test_deep_inheritance_abstract(self):208 class ParentModelAbstract(SEO):209 class SEO:210 seo_title = 'foo'211 class Meta:212 abstract = True213 class Test8Model(ParentModelAbstract):214 class SEO:215 seo_keywords = 'asdfasdf'216 x = Test8Model()217 fields = get_field_dict(x)218 self.assertTrue(isinstance(fields['foo'], models.CharField))219 self.assertTrue(isinstance(fields['seo_description'], models.TextField))220 self.assertTrue(isinstance(fields['asdfasdf'], models.TextField))221 def test_deep_inheritance_settings(self):222 class ParentModelNoSettings(SEO):223 class Meta:224 abstract = True225 class Test9Model(ParentModelNoSettings):226 class SEO:227 seo_keywords = 'asdfasdf'228 x = Test9Model()229 fields = get_field_dict(x)230 self.assertTrue(isinstance(fields['seo_title'], models.CharField))231 self.assertTrue(isinstance(fields['seo_description'], models.TextField))232 self.assertTrue(isinstance(fields['asdfasdf'], models.TextField))233class TestTwoBehaviors(unittest.TestCase):234 def test_bare(self):235 class Test5Model(SEO, Timestampable):236 pass237 x = Test5Model()238 fields = get_field_dict(x)239 self.assertTrue(isinstance(fields['seo_title'], models.CharField))240 self.assertTrue(isinstance(fields['seo_description'], models.TextField))241 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))242 self.assertTrue(isinstance(fields['created_at'], models.DateTimeField))243 self.assertTrue(isinstance(fields['updated_at'], models.DateTimeField))244 def test_override(self):245 class Test6Model(SEO, Timestampable):246 class SEO:247 seo_title = 'asdf'248 class Timestampable:249 updated_at = 'foo'250 pass251 x = Test6Model()252 fields = get_field_dict(x)253 self.assertTrue(isinstance(fields['asdf'], models.CharField))254 self.assertTrue(isinstance(fields['seo_description'], models.TextField))255 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))256 self.assertTrue(isinstance(fields['created_at'], models.DateTimeField))257 self.assertTrue(isinstance(fields['foo'], models.DateTimeField))258 def test_new_behavior(self):259 class SeoAndTime(SEO, Timestampable):260 class SEO:261 seo_title = 'seo_and_time_title'262 pass263 class Test10Model(SeoAndTime):264 class Timestampable:265 updated_at = 'asdf'266 class SEO:267 seo_description = 'foo'268 x = Test10Model()269 fields = get_field_dict(x)270 self.assertTrue(isinstance(fields['seo_and_time_title'], models.CharField))271 self.assertTrue(isinstance(fields['foo'], models.TextField))272 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))273 self.assertTrue(isinstance(fields['created_at'], models.DateTimeField))274 self.assertTrue(isinstance(fields['asdf'], models.DateTimeField))275 def test_namespacings(self):276 class SeoAndTime2(SEO, Timestampable):277 class SEO:278 seo_title = 'seo_and_time_title'279 pass280 class Test11Model(SeoAndTime2):281 class Timestampable:282 seo_description = 'asdf'283 x = Test11Model()284 fields = get_field_dict(x)285 self.assertTrue(isinstance(fields['seo_and_time_title'], models.CharField))286 self.assertTrue(isinstance(fields['seo_description'], models.TextField))287 self.assertTrue(isinstance(fields['seo_keywords'], models.TextField))288 self.assertTrue(isinstance(fields['created_at'], models.DateTimeField))...

Full Screen

Full Screen

make_tiledb_metadata_file.py

Source:make_tiledb_metadata_file.py Github

copy

Full Screen

...40 outf.write('\t'+task_dict[task][field])41 except:42 print("not found:"+field+'\t'+task_dict[task]['cromwell_id']+'\t'+task)43 outf.write('\tNA')44def get_field_dict(text_field,args_field,task_dict,id_to_task):45 if args_field is None:46 for task in task_dict: 47 task_dict[task][text_field]=None48 else:49 for line in open(args_field,'r').read().strip().split('\n'):50 tokens=line.split('/')51 for token in tokens:52 if token in id_to_task:53 cur_task=id_to_task[token]54 if cur_task not in task_dict:55 task_dict[cur_task]=dict()56 task_dict[cur_task]['cromwell_id']=token 57 task_dict[cur_task][text_field]=line58 break59 return task_dict 60def main():61 args=parse_args()62 #create a dictionary of cromwell hash values to encode id's 63 id_to_task=pd.read_csv(args.id_to_task,header=None,sep='\t',index_col=0).to_dict()[1]64 65 #create a dictionary to keep track of task files66 task_dict=dict()67 #iterate through each of the fields68 task_dict=get_field_dict('fc_bigwig',args.fc_bigwig,task_dict,id_to_task)69 #print(task_dict)70 #print("parsed fc_bigwig") 71 task_dict=get_field_dict('pval_bigwig',args.pval_bigwig,task_dict,id_to_task)72 #print("parsed pval_bigwig")73 task_dict=get_field_dict('count_bigwig_plus_5p',args.count_bigwig_plus_5p,task_dict,id_to_task)74 #print("parsed count_bigwig_plus_5p") 75 task_dict=get_field_dict('count_bigwig_minus_5p',args.count_bigwig_minus_5p,task_dict,id_to_task)76 #print("parsed count_bigwig_minus_5p")77 task_dict=get_field_dict('count_bigwig_unstranded_5p',args.count_bigwig_unstranded_5p,task_dict,id_to_task)78 #print("parsed count_bigwig_unstranded_5p")79 task_dict=get_field_dict('idr_peak',args.idr_peak,task_dict,id_to_task)80 #print("parsed idr_peak") 81 task_dict=get_field_dict('overlap_peak',args.overlap_peak,task_dict,id_to_task)82 #print("parsed overlap_peak") 83 task_dict=get_field_dict('ambig_peak',args.ambig_peak,task_dict,id_to_task)84 #print("parsed ambig_peak")85 #print(task_dict)86 #generate output file(s)87 #pdb.set_trace() 88 if args.split_tasks_to_separate_files is True:89 for task in task_dict:90 write_output_file_per_task(args,task_dict,task)91 else:92 write_output_file_all_tasks(args,task_dict)93 94 95 96if __name__=="__main__":97 main()...

Full Screen

Full Screen

csv_parse.py

Source:csv_parse.py Github

copy

Full Screen

...20def cmp_total_with_value_dict(table, field_dict):21 for field_name in table.field_name_list:22 if table.__getattribute__(field_name) != field_dict[field_name]:23 msg = "%s.%s does not match at field[%s]. table value[%s], db value[%s]." % (table.db_name, table.table_name, field_name, table.__getattribute__(field_name), field_dict[field_name])24 msg += "\ntable:" + table.get_field_dict().__str__()25 msg += "\ndb:" + field_dict.__str__()26 return False, msg27 return True, ""28def get_primary_key_value_dict(table):29 if len(table.primary_key_value_dict) == 0:30 for field_name in table.primary_key_name_list:31 table.primary_key_value_dict[field_name] = table.__getattribute__(field_name)32 return table.primary_key_value_dict33def get_field_dict(table):34 if len(table.field_dict) == 0:35 for field_name in table.field_name_list:36 table.field_dict[field_name] = table.__getattribute__(field_name)37 return table.field_dict38def parse_one_csv_file(file_path, db_name, table_name, tables, primary_key_name_list):39 tables[table_name] = []40 row = 041 Table = type(table_name, (object,), {})42 for line in open(file_path, "r"):43 line = common_utils.try_gbk2utf8(line)44 line = common_utils.trim_return(line)45 fields = line.split(",")46 if row == 0:47 Table.db_name = db_name...

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 autotest 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