How to use test_keyval_dict method in autotest

Best Python code snippet using autotest_python

job_serializer_unittest.py

Source:job_serializer_unittest.py Github

copy

Full Screen

...97 self.pb_job.aborted_by)98 def test_aborted_on(self):99 self.check_time(self.tko_job.aborted_on,100 self.pb_job.aborted_on)101 def test_keyval_dict(self):102 """Check if the contents of the dictionary are the same.103 """104 self.assertEqual(len(self.tko_job.keyval_dict),105 len(self.pb_job.keyval_dict))106 self.check_dict(self.tko_job.keyval_dict,107 self.convert_keyval_to_dict(self.pb_job,108 'keyval_dict'))109 def test_tests(self):110 """Check if all the test are the same.111 """112 for test, newtest in zip(self.tko_job.tests,113 self.pb_job.tests):114 self.assertEqual(test.subdir, newtest.subdir)115 self.assertEqual(test.testname, newtest.testname)116 self.assertEqual(test.status, newtest.status)117 self.assertEqual(test.reason, newtest.reason)118 self.assertEqual(test.machine, newtest.machine)119 self.assertEqual(test.labels, newtest.labels)120 self.check_time(test.started_time, newtest.started_time)121 self.check_time(test.finished_time, newtest.finished_time)122 self.check_iteration(test.iterations, newtest.iterations)123 self.check_dict(test.attributes,124 self.convert_keyval_to_dict(newtest,125 'attributes'))126 self.check_kernel(test.kernel, newtest.kernel)127 def check_time(self, dTime, stime):128 """Check if the datetime object contains the same time value129 in microseconds.130 """131 t = mktime(dTime.timetuple()) + 1e-6 * dTime.microsecond132 self.assertEqual(long(t), stime/1000)133 def check_iteration(self, tko_iterations, pb_iterations):134 """Check if the iteration objects are the same.135 """136 for tko_iteration, pb_iteration in zip(tko_iterations,137 pb_iterations):138 self.assertEqual(tko_iteration.index, pb_iteration.index)139 self.check_dict(tko_iteration.attr_keyval,140 self.convert_keyval_to_dict(pb_iteration,141 'attr_keyval'))142 self.check_dict(tko_iteration.perf_keyval,143 self.convert_keyval_to_dict(pb_iteration,144 'perf_keyval'))145 def convert_keyval_to_dict(self, var, attr):146 """Convert a protocol buffer repeated keyval object into a147 python dict.148 """149 return dict((keyval.name, keyval.value) for keyval in150 getattr(var,attr))151 def check_dict(self, dictionary, keyval):152 """Check if the contents of the dictionary are the same as a153 repeated keyval pair.154 """155 for key, value in dictionary.iteritems():156 self.assertTrue(key in keyval);157 self.assertEqual(str(value), keyval[key])158 def check_kernel(self, kernel, newkernel):159 """Check if the kernels are the same.160 """161 self.assertEqual(kernel.base, newkernel.base)162 self.assertEqual(kernel.kernel_hash, newkernel.kernel_hash)163class ReadBackTest(JobSerializerUnittest):164 """Check if convert between models.job and pb job is correct even165 after being written to binary and read by manually166 """167 def setUp(self):168 super(ReadBackTest, self).setUp()169 out_binary = NamedTemporaryFile(mode='wb')170 try:171 out_binary.write(self.pb_job.SerializeToString())172 out_binary.flush()173 binary = open(out_binary.name, 'rb')174 try:175 self.pb_job = tko_pb2.Job()176 self.pb_job.ParseFromString(binary.read())177 finally:178 binary.close()179 finally:180 out_binary.close()181class ReadBackGetterTest(JobSerializerUnittest):182 """Check if convert between models.job and pb job is correct after183 using the getter methods in JobSerializer to read back the184 data.185 """186 def setUp(self):187 super(ReadBackGetterTest, self).setUp()188 temp_binary = NamedTemporaryFile(mode='wb')189 try:190 temp_binary.write(self.pb_job.SerializeToString())191 temp_binary.flush()192 js = job_serializer.JobSerializer()193 self.from_pb_job = js.deserialize_from_binary(temp_binary.name)194 finally:195 temp_binary.close()196 def test_keyval_dict(self):197 """Check if the contents of the dictionary are the same. """198 self.assertEqual(len(self.tko_job.keyval_dict),199 len(self.from_pb_job.keyval_dict))200 self.check_dict(self.tko_job.keyval_dict,201 self.from_pb_job.keyval_dict)202 def test_tests(self):203 """Check if all the test are the same.204 """205 for test, newtest in zip(self.tko_job.tests,206 self.from_pb_job.tests):207 self.assertEqual(test.subdir, newtest.subdir)208 self.assertEqual(test.testname, newtest.testname)209 self.assertEqual(test.status, newtest.status)210 self.assertEqual(test.reason, newtest.reason)...

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