How to use _setup_simple_test method in avocado

Best Python code snippet using avocado_python

test_output_check.py

Source:test_output_check.py Github

copy

Full Screen

...127 (expected_rc, result))128 output_file = "%s.data/output.expected" % self.output_script129 with open(output_file, 'rb') as fd_output:130 self.assertEqual(fd_output.read(), STDOUT + STDERR)131 def _setup_simple_test(self, simple_test_content):132 variants_file = os.path.join(self.tmpdir.name, 'variants.json')133 with open(variants_file, 'w') as file_obj:134 file_obj.write(JSON_VARIANTS)135 simple_test = os.path.join(self.tmpdir.name, 'simpletest.py')136 with open(simple_test, 'w') as file_obj:137 file_obj.write(simple_test_content)138 return (simple_test, variants_file)139 def test_output_record_none(self):140 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '141 '--output-check-record none'142 % (AVOCADO, self.tmpdir.name, self.output_script.path))143 result = process.run(cmd_line, ignore_status=True)144 expected_rc = exit_codes.AVOCADO_ALL_OK145 self.assertEqual(result.exit_status, expected_rc,146 "Avocado did not return rc %d:\n%s" %147 (expected_rc, result))148 self.assertIsNotFile("%s.data/stdout.expected" % self.output_script)149 self.assertIsNotFile("%s.data/stderr.expected" % self.output_script)150 def test_output_record_stdout(self):151 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '152 '--output-check-record stdout'153 % (AVOCADO, self.tmpdir.name, self.output_script.path))154 result = process.run(cmd_line, ignore_status=True)155 expected_rc = exit_codes.AVOCADO_ALL_OK156 self.assertEqual(result.exit_status, expected_rc,157 "Avocado did not return rc %d:\n%s" %158 (expected_rc, result))159 stdout_file = "%s.data/stdout.expected" % self.output_script160 stderr_file = "%s.data/stderr.expected" % self.output_script161 with open(stdout_file, 'rb') as fd_stdout:162 self.assertEqual(fd_stdout.read(), STDOUT)163 self.assertIsNotFile(stderr_file)164 def test_output_record_and_check(self):165 self._check_output_record_all()166 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s'167 % (AVOCADO, self.tmpdir.name, self.output_script.path))168 result = process.run(cmd_line, ignore_status=True)169 expected_rc = exit_codes.AVOCADO_ALL_OK170 self.assertEqual(result.exit_status, expected_rc,171 "Avocado did not return rc %d:\n%s" %172 (expected_rc, result))173 def test_output_record_and_check_combined(self):174 self._check_output_record_combined()175 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s'176 % (AVOCADO, self.tmpdir.name, self.output_script.path))177 result = process.run(cmd_line, ignore_status=True)178 expected_rc = exit_codes.AVOCADO_ALL_OK179 self.assertEqual(result.exit_status, expected_rc,180 "Avocado did not return rc %d:\n%s" %181 (expected_rc, result))182 def test_output_tamper_stdout(self):183 self._check_output_record_all()184 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"185 stdout_file = "%s.data/stdout.expected" % self.output_script.path186 with open(stdout_file, 'wb') as stdout_file_obj:187 stdout_file_obj.write(tampered_msg)188 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s --xunit -'189 % (AVOCADO, self.tmpdir.name, self.output_script.path))190 result = process.run(cmd_line, ignore_status=True)191 expected_rc = exit_codes.AVOCADO_TESTS_FAIL192 self.assertEqual(result.exit_status, expected_rc,193 "Avocado did not return rc %d:\n%s" %194 (expected_rc, result))195 self.assertIn(tampered_msg, result.stdout)196 def test_output_tamper_combined(self):197 self._check_output_record_combined()198 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"199 output_file = "%s.data/output.expected" % self.output_script.path200 with open(output_file, 'wb') as output_file_obj:201 output_file_obj.write(tampered_msg)202 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s --xunit -'203 % (AVOCADO, self.tmpdir.name, self.output_script.path))204 result = process.run(cmd_line, ignore_status=True)205 expected_rc = exit_codes.AVOCADO_TESTS_FAIL206 self.assertEqual(result.exit_status, expected_rc,207 "Avocado did not return rc %d:\n%s" %208 (expected_rc, result))209 self.assertIn(tampered_msg, result.stdout)210 def test_output_diff(self):211 self._check_output_record_all()212 tampered_msg_stdout = b"I PITY THE FOOL THAT STANDS ON STDOUT!"213 tampered_msg_stderr = b"I PITY THE FOOL THAT STANDS ON STDERR!"214 stdout_file = "%s.data/stdout.expected" % self.output_script.path215 with open(stdout_file, 'wb') as stdout_file_obj:216 stdout_file_obj.write(tampered_msg_stdout)217 stderr_file = "%s.data/stderr.expected" % self.output_script.path218 with open(stderr_file, 'wb') as stderr_file_obj:219 stderr_file_obj.write(tampered_msg_stderr)220 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s --json -'221 % (AVOCADO, self.tmpdir.name, self.output_script.path))222 result = process.run(cmd_line, ignore_status=True)223 expected_rc = exit_codes.AVOCADO_TESTS_FAIL224 self.assertEqual(result.exit_status, expected_rc,225 "Avocado did not return rc %d:\n%s" %226 (expected_rc, result))227 json_result = json.loads(result.stdout_text)228 job_log = json_result['debuglog']229 stdout_diff = os.path.join(json_result['tests'][0]['logdir'],230 'stdout.diff')231 stderr_diff = os.path.join(json_result['tests'][0]['logdir'],232 'stderr.diff')233 with open(stdout_diff, 'rb') as stdout_diff_obj:234 stdout_diff_content = stdout_diff_obj.read()235 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDOUT!',236 stdout_diff_content)237 self.assertIn(b'+' + STDOUT, stdout_diff_content)238 with open(stderr_diff, 'rb') as stderr_diff_obj:239 stderr_diff_content = stderr_diff_obj.read()240 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDERR!',241 stderr_diff_content)242 self.assertIn(b'+Hello, stderr!', stderr_diff_content)243 with open(job_log, 'rb') as job_log_obj:244 job_log_content = job_log_obj.read()245 self.assertIn(b'Stdout Diff:', job_log_content)246 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDOUT!', job_log_content)247 self.assertIn(b'+' + STDOUT, job_log_content)248 self.assertIn(b'Stdout Diff:', job_log_content)249 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDERR!', job_log_content)250 self.assertIn(b'+' + STDERR, job_log_content)251 def test_disable_output_check(self):252 self._check_output_record_all()253 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"254 stdout_file = "%s.data/stdout.expected" % self.output_script.path255 with open(stdout_file, 'wb') as stdout_file_obj:256 stdout_file_obj.write(tampered_msg)257 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '258 '--disable-output-check --xunit -'259 % (AVOCADO, self.tmpdir.name, self.output_script.path))260 result = process.run(cmd_line, ignore_status=True)261 expected_rc = exit_codes.AVOCADO_ALL_OK262 self.assertEqual(result.exit_status, expected_rc,263 "Avocado did not return rc %d:\n%s" %264 (expected_rc, result))265 self.assertNotIn(tampered_msg, result.stdout)266 def test_merge_records_same_output(self):267 variants_file = os.path.join(self.tmpdir.name, 'variants.json')268 with open(variants_file, 'w') as file_obj:269 file_obj.write(JSON_VARIANTS)270 simple_test = os.path.join(self.tmpdir.name, 'simpletest.py')271 with open(simple_test, 'w') as file_obj:272 file_obj.write(TEST_WITH_SAME_EXPECTED_OUTPUT)273 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '274 '--output-check-record both --json-variants-load %s' %275 (AVOCADO, self.tmpdir.name, simple_test, variants_file))276 process.run(cmd_line, ignore_status=True)277 self.assertIsFile("%s.data/stdout.expected" % simple_test)278 self.assertIsFile("%s.data/stderr.expected" % simple_test)279 def test_merge_records_different_output(self):280 simple_test, variants_file = self._setup_simple_test(281 TEST_WITH_DIFFERENT_EXPECTED_OUTPUT)282 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '283 '--output-check-record both --json-variants-load %s' %284 (AVOCADO, self.tmpdir.name, simple_test, variants_file))285 process.run(cmd_line, ignore_status=True)286 self.assertIsNotFile("%s.data/stdout.expected" % simple_test)287 self.assertIsNotFile("%s.data/stderr.expected" % simple_test)288 self.assertIsFile("%s.data/PassTest.test_1/stdout.expected" % simple_test)289 self.assertIsFile("%s.data/PassTest.test_1/stderr.expected" % simple_test)290 self.assertIsFile("%s.data/PassTest.test_2/stdout.expected" % simple_test)291 self.assertIsFile("%s.data/PassTest.test_2/stderr.expected" % simple_test)292 def test_merge_records_different_output_variants(self):293 simple_test, variants_file = self._setup_simple_test(294 TEST_WITH_DIFFERENT_EXPECTED_OUTPUT_VARIANTS)295 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '296 '--output-check-record both --json-variants-load %s' %297 (AVOCADO, self.tmpdir.name, simple_test, variants_file))298 process.run(cmd_line, ignore_status=True)299 self.assertIsNotFile("%s.data/stdout.expected" % simple_test)300 self.assertIsNotFile("%s.data/stderr.expected" % simple_test)301 self.assertIsNotFile("%s.data/PassTest.test_1/stdout.expected" % simple_test)302 self.assertIsNotFile("%s.data/PassTest.test_1/stderr.expected" % simple_test)303 self.assertIsNotFile("%s.data/PassTest.test_2/stdout.expected" % simple_test)304 self.assertIsNotFile("%s.data/PassTest.test_2/stderr.expected" % simple_test)305 self.assertIsFile("%s.data/PassTest.test_2/bar/stderr.expected" % simple_test)306 self.assertIsFile("%s.data/PassTest.test_2/foo/stderr.expected" % simple_test)307 def test_merge_records_different_and_same_output(self):308 simple_test, variants_file = self._setup_simple_test(309 TEST_WITH_DIFFERENT_AND_SAME_EXPECTED_OUTPUT)310 cmd_line = ('%s run --job-results-dir %s --disable-sysinfo %s '311 '--output-check-record both --json-variants-load %s' %312 (AVOCADO, self.tmpdir.name, simple_test, variants_file))313 process.run(cmd_line, ignore_status=True)314 self.assertIsFile("%s.data/stdout.expected" % simple_test)315 self.assertIsFile("%s.data/stderr.expected" % simple_test)316 self.assertIsFile("%s.data/PassTest.test_1/stdout.expected" % simple_test)317 self.assertIsFile("%s.data/PassTest.test_1/stderr.expected" % simple_test)318 self.assertIsNotFile("%s.data/PassTest.test_2/stdout.expected" % simple_test)319 self.assertIsNotFile("%s.data/PassTest.test_2/stderr.expected" % simple_test)320 def tearDown(self):321 super(RunnerSimpleTest, self).tearDown()322 self.output_script.remove()...

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