How to use set_trivial_attr method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...129 pb_job: a new instance of the job class provided in the130 protocol buffer.131 tag: used to set pb_job.tag and pb_job.afe_job_id.132 """133 self.set_trivial_attr(tko_job, pb_job, self.job_type_dict)134 self.set_afe_job_id_and_tag(pb_job, tag)135 for test in tko_job.tests:136 newtest = pb_job.tests.add()137 self.set_pb_test(test, newtest)138 for key, val in tko_job.keyval_dict.iteritems():139 newkeyval = pb_job.keyval_dict.add()140 = key141 newkeyval.value = str(val)142 def get_tko_test(self, test):143 """Creates a tko test from pb_test.144 Extracts data from pb_test by calling helper methods and145 creates a tko test using the models.test constructor.146 :param:147 test: a pb_test where fields will be extracted from.148 :return: a new instance of models.test149 """150 fields_dict = self.get_trivial_attr(test, self.test_type_dict)151 fields_dict['kernel'] = self.get_tko_kernel(test.kernel)152 fields_dict['iterations'] = [self.get_tko_iteration(iteration)153 for iteration in test.iterations]154 fields_dict['attributes'] = dict((, keyval.value)155 for keyval in test.attributes)156 fields_dict['labels'] = list(test.labels)157 return models.test(fields_dict['subdir'],158 fields_dict['testname'],159 fields_dict['status'],160 fields_dict['reason'],161 fields_dict['kernel'],162 fields_dict['machine'],163 fields_dict['started_time'],164 fields_dict['finished_time'],165 fields_dict['iterations'],166 fields_dict['attributes'],167 fields_dict['labels'])168 def set_pb_test(self, tko_test, pb_test):169 """Sets the various fields of test object of the tko protocol.170 Method takes a tko test and a new test of the protocol buffer and171 transfers the values in the tko test to the new test.172 :param173 tko_test: a tko test instance.174 pb_test: an empty protocol buffer test instance.175 """176 self.set_trivial_attr(tko_test, pb_test, self.test_type_dict)177 self.set_pb_kernel(tko_test.kernel, pb_test.kernel)178 for current_iteration in tko_test.iterations:179 pb_iteration = pb_test.iterations.add()180 self.set_pb_iteration(current_iteration, pb_iteration)181 for key, val in tko_test.attributes.iteritems():182 newkeyval = pb_test.attributes.add()183 = key184 newkeyval.value = str(val)185 for current_label in tko_test.labels:186 pb_test.labels.append(current_label)187 def get_tko_kernel(self, kernel):188 """Constructs a new tko kernel object from a pb kernel object.189 Uses all the getter methods on the pb kernel object to extract190 the attributes and constructs a new tko kernel object using191 the model.kernel constructor.192 :param193 kernel: a pb kernel object where data will be extracted.194 :return: a new tko kernel object.195 """196 fields_dict = self.get_trivial_attr(kernel, self.kernel_type_dict)197 return models.kernel(fields_dict['base'], [], fields_dict['kernel_hash'])198 def set_pb_kernel(self, tko_kernel, pb_kernel):199 """Set a specific kernel of a test.200 Takes the same form of all the other setting methods. It201 separates the string variables from the int variables and set202 them safely.203 :param204 tko_kernel: a tko kernel.205 pb_kernel: an empty protocol buffer kernel.206 """207 self.set_trivial_attr(tko_kernel, pb_kernel, self.kernel_type_dict)208 def get_tko_iteration(self, iteration):209 """Creates a new tko iteration with the data in the provided210 pb iteration.211 Uses the data in the pb iteration and the models.iteration212 constructor to create a new tko iterations213 :param214 iteration: a pb iteration instance215 :return: a tko iteration instance with the same data.216 """217 fields_dict = self.get_trivial_attr(iteration,218 self.iteration_type_dict)219 fields_dict['attr_keyval'] = dict((, keyval.value)220 for keyval in iteration.attr_keyval)221 fields_dict['perf_keyval'] = dict((, keyval.value)222 for keyval in iteration.perf_keyval)223 return models.iteration(fields_dict['index'],224 fields_dict['attr_keyval'],225 fields_dict['perf_keyval'])226 def set_pb_iteration(self, tko_iteration, pb_iteration):227 """Sets all fields for a particular iteration.228 Takes same form as all the other setting methods. Sets int,229 str and datetime variables safely.230 :param231 tko_iteration: a tko test iteration.232 pb_iteration: an empty pb test iteration.233 """234 self.set_trivial_attr(tko_iteration, pb_iteration,235 self.iteration_type_dict)236 for key, val in tko_iteration.attr_keyval.iteritems():237 newkeyval = pb_iteration.attr_keyval.add()238 = key239 newkeyval.value = str(val)240 for key, val in tko_iteration.perf_keyval.iteritems():241 newkeyval = pb_iteration.perf_keyval.add()242 = key243 newkeyval.value = str(val)244 def get_trivial_attr(self, obj, objdict):245 """Get all trivial attributes from the object.246 This function is used to extract attributes from a pb job. The247 dictionary specifies the types of each attribute in each tko248 class.249 :param250 obj: the pb object that is being extracted.251 objdict: the dict that specifies the type.252 :return: a dict of each attr name and it's corresponding value.253 """254 resultdict = {}255 for field, field_type in objdict.items():256 value = getattr(obj, field)257 if field_type in (str, int, long):258 resultdict[field] = field_type(value)259 elif field_type == datetime:260 resultdict[field] = (261 datetime.fromtimestamp(value / 1000.0))262 return resultdict263 def set_trivial_attr(self, tko_obj, pb_obj, objdict):264 """Sets all the easy attributes appropriately according to the265 type.266 This function is used to set all the trivial attributes267 provided by objdict, the dictionary that specifies the types268 of each attribute in each tko class.269 :param270 tko_obj: the original object that has the data being copied.271 pb_obj: the new pb object that is being copied into.272 objdict: specifies the type of each attribute in the class we273 are working with.274 """275 for attr, attr_type in objdict.iteritems():276 if attr_type == datetime:277 t = getattr(tko_obj, attr)...

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:


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?