How to use _check_output_record_all method in avocado

Best Python code snippet using avocado_python

test_output_check.py

Source:test_output_check.py Github

copy

Full Screen

...20 content,21 'avocado_output_check_functional',22 open_mode='wb')23 self.output_script.save()24 def _check_output_record_all(self):25 os.chdir(BASEDIR)26 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s '27 '--output-check-record all'28 % (AVOCADO, self.tmpdir, self.output_script.path))29 result = process.run(cmd_line, ignore_status=True)30 expected_rc = exit_codes.AVOCADO_ALL_OK31 self.assertEqual(result.exit_status, expected_rc,32 "Avocado did not return rc %d:\n%s" %33 (expected_rc, result))34 stdout_file = os.path.join("%s.data/stdout.expected" % self.output_script)35 stderr_file = os.path.join("%s.data/stderr.expected" % self.output_script)36 with open(stdout_file, 'rb') as fd_stdout:37 self.assertEqual(fd_stdout.read(), STDOUT)38 with open(stderr_file, 'rb') as fd_stderr:39 self.assertEqual(fd_stderr.read(), STDERR)40 def _check_output_record_combined(self):41 os.chdir(BASEDIR)42 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s '43 '--output-check-record combined'44 % (AVOCADO, self.tmpdir, self.output_script.path))45 result = process.run(cmd_line, ignore_status=True)46 expected_rc = exit_codes.AVOCADO_ALL_OK47 self.assertEqual(result.exit_status, expected_rc,48 "Avocado did not return rc %d:\n%s" %49 (expected_rc, result))50 output_file = os.path.join("%s.data/output.expected" % self.output_script)51 with open(output_file, 'rb') as fd_output:52 self.assertEqual(fd_output.read(), STDOUT + STDERR)53 def test_output_record_none(self):54 os.chdir(BASEDIR)55 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s '56 '--output-check-record none'57 % (AVOCADO, self.tmpdir, self.output_script.path))58 result = process.run(cmd_line, ignore_status=True)59 expected_rc = exit_codes.AVOCADO_ALL_OK60 self.assertEqual(result.exit_status, expected_rc,61 "Avocado did not return rc %d:\n%s" %62 (expected_rc, result))63 stdout_file = os.path.join("%s.data/stdout.expected" % self.output_script)64 stderr_file = os.path.join("%s.data/stderr.expected" % self.output_script)65 self.assertFalse(os.path.isfile(stdout_file))66 self.assertFalse(os.path.isfile(stderr_file))67 def test_output_record_stdout(self):68 os.chdir(BASEDIR)69 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s '70 '--output-check-record stdout'71 % (AVOCADO, self.tmpdir, self.output_script.path))72 result = process.run(cmd_line, ignore_status=True)73 expected_rc = exit_codes.AVOCADO_ALL_OK74 self.assertEqual(result.exit_status, expected_rc,75 "Avocado did not return rc %d:\n%s" %76 (expected_rc, result))77 stdout_file = os.path.join("%s.data/stdout.expected" % self.output_script)78 stderr_file = os.path.join("%s.data/stderr.expected" % self.output_script)79 with open(stdout_file, 'rb') as fd_stdout:80 self.assertEqual(fd_stdout.read(), STDOUT)81 self.assertFalse(os.path.isfile(stderr_file))82 def test_output_record_and_check(self):83 self._check_output_record_all()84 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s'85 % (AVOCADO, self.tmpdir, self.output_script.path))86 result = process.run(cmd_line, ignore_status=True)87 expected_rc = exit_codes.AVOCADO_ALL_OK88 self.assertEqual(result.exit_status, expected_rc,89 "Avocado did not return rc %d:\n%s" %90 (expected_rc, result))91 def test_output_record_and_check_combined(self):92 self._check_output_record_combined()93 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s'94 % (AVOCADO, self.tmpdir, self.output_script.path))95 result = process.run(cmd_line, ignore_status=True)96 expected_rc = exit_codes.AVOCADO_ALL_OK97 self.assertEqual(result.exit_status, expected_rc,98 "Avocado did not return rc %d:\n%s" %99 (expected_rc, result))100 def test_output_tamper_stdout(self):101 self._check_output_record_all()102 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"103 stdout_file = os.path.join("%s.data/stdout.expected" % self.output_script.path)104 with open(stdout_file, 'wb') as stdout_file_obj:105 stdout_file_obj.write(tampered_msg)106 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s --xunit -'107 % (AVOCADO, self.tmpdir, self.output_script.path))108 result = process.run(cmd_line, ignore_status=True)109 expected_rc = exit_codes.AVOCADO_TESTS_FAIL110 self.assertEqual(result.exit_status, expected_rc,111 "Avocado did not return rc %d:\n%s" %112 (expected_rc, result))113 self.assertIn(tampered_msg, result.stdout)114 def test_output_tamper_combined(self):115 self._check_output_record_combined()116 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"117 output_file = os.path.join("%s.data/output.expected" % self.output_script.path)118 with open(output_file, 'wb') as output_file_obj:119 output_file_obj.write(tampered_msg)120 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s --xunit -'121 % (AVOCADO, self.tmpdir, self.output_script.path))122 result = process.run(cmd_line, ignore_status=True)123 expected_rc = exit_codes.AVOCADO_TESTS_FAIL124 self.assertEqual(result.exit_status, expected_rc,125 "Avocado did not return rc %d:\n%s" %126 (expected_rc, result))127 self.assertIn(tampered_msg, result.stdout)128 def test_output_diff(self):129 self._check_output_record_all()130 tampered_msg_stdout = b"I PITY THE FOOL THAT STANDS ON STDOUT!"131 tampered_msg_stderr = b"I PITY THE FOOL THAT STANDS ON STDERR!"132 stdout_file = "%s.data/stdout.expected" % self.output_script.path133 with open(stdout_file, 'wb') as stdout_file_obj:134 stdout_file_obj.write(tampered_msg_stdout)135 stderr_file = "%s.data/stderr.expected" % self.output_script.path136 with open(stderr_file, 'wb') as stderr_file_obj:137 stderr_file_obj.write(tampered_msg_stderr)138 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s --json -'139 % (AVOCADO, self.tmpdir, self.output_script.path))140 result = process.run(cmd_line, ignore_status=True)141 expected_rc = exit_codes.AVOCADO_TESTS_FAIL142 self.assertEqual(result.exit_status, expected_rc,143 "Avocado did not return rc %d:\n%s" %144 (expected_rc, result))145 json_result = json.loads(result.stdout_text)146 job_log = json_result['debuglog']147 stdout_diff = os.path.join(json_result['tests'][0]['logdir'],148 'stdout.diff')149 stderr_diff = os.path.join(json_result['tests'][0]['logdir'],150 'stderr.diff')151 with open(stdout_diff, 'rb') as stdout_diff_obj:152 stdout_diff_content = stdout_diff_obj.read()153 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDOUT!',154 stdout_diff_content)155 self.assertIn(b'+' + STDOUT, stdout_diff_content)156 with open(stderr_diff, 'rb') as stderr_diff_obj:157 stderr_diff_content = stderr_diff_obj.read()158 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDERR!',159 stderr_diff_content)160 self.assertIn(b'+Hello, stderr!', stderr_diff_content)161 with open(job_log, 'rb') as job_log_obj:162 job_log_content = job_log_obj.read()163 self.assertIn(b'Stdout Diff:', job_log_content)164 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDOUT!', job_log_content)165 self.assertIn(b'+' + STDOUT, job_log_content)166 self.assertIn(b'Stdout Diff:', job_log_content)167 self.assertIn(b'-I PITY THE FOOL THAT STANDS ON STDERR!', job_log_content)168 self.assertIn(b'+' + STDERR, job_log_content)169 def test_disable_output_check(self):170 self._check_output_record_all()171 tampered_msg = b"I PITY THE FOOL THAT STANDS ON MY WAY!"172 stdout_file = os.path.join("%s.data/stdout.expected" % self.output_script.path)173 with open(stdout_file, 'wb') as stdout_file_obj:174 stdout_file_obj.write(tampered_msg)175 cmd_line = ('%s run --job-results-dir %s --sysinfo=off %s '176 '--output-check=off --xunit -'177 % (AVOCADO, self.tmpdir, self.output_script.path))178 result = process.run(cmd_line, ignore_status=True)179 expected_rc = exit_codes.AVOCADO_ALL_OK180 self.assertEqual(result.exit_status, expected_rc,181 "Avocado did not return rc %d:\n%s" %182 (expected_rc, result))183 self.assertNotIn(tampered_msg, result.stdout)184 def tearDown(self):...

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