Run the image test. First, result images are generated (unless compare_only is True). Second, result images are compared against reference images. Third, writes a JSON report to the result_dir containing details on the test run. Returns a tuple containing the
(self, run_only: bool, compare_only: bool, ref_dir: Path, result_dir: Path, mogwai_exe: Path, image_compare_exe: Path, temp_dir: Path)
| 315 | return result, messages, image_reports |
| 316 | |
| 317 | def run(self, run_only: bool, compare_only: bool, ref_dir: Path, result_dir: Path, mogwai_exe: Path, image_compare_exe: Path, temp_dir: Path): |
| 318 | ''' |
| 319 | Run the image test. |
| 320 | First, result images are generated (unless compare_only is True). |
| 321 | Second, result images are compared against reference images. |
| 322 | Third, writes a JSON report to the result_dir containing details on the test run. |
| 323 | Returns a tuple containing the result code and a list of messages. |
| 324 | ''' |
| 325 | # Setup report. |
| 326 | report = { |
| 327 | 'name': self.name, |
| 328 | 'ref_dir': str(ref_dir / self.test_dir), |
| 329 | 'images': [] |
| 330 | } |
| 331 | |
| 332 | start_time = time.time() |
| 333 | result = Test.Result.PASSED |
| 334 | messages = [] |
| 335 | rerun_env = {} |
| 336 | |
| 337 | # Generate results images. |
| 338 | if not compare_only: |
| 339 | result, messages, rerun_env = self.generate_images(result_dir, mogwai_exe, run_only, temp_dir) |
| 340 | |
| 341 | # Compare to references. |
| 342 | if not run_only and result == Test.Result.PASSED: |
| 343 | result, messages, report['images'] = self.compare_images(ref_dir, result_dir, image_compare_exe) |
| 344 | |
| 345 | # Finish report. |
| 346 | report['result'] = Test.RESULT_STRING[result] |
| 347 | report['messages'] = messages |
| 348 | report['duration'] = time.time() - start_time |
| 349 | report['rerun_env'] = rerun_env |
| 350 | |
| 351 | # Write JSON report. |
| 352 | report_dir = result_dir / self.test_dir |
| 353 | report_dir.mkdir(parents=True, exist_ok=True) |
| 354 | report_file = report_dir / 'report.json' |
| 355 | with open(report_file, 'w') as f: |
| 356 | json.dump(report, f, indent=4) |
| 357 | |
| 358 | return result, messages |
| 359 | |
| 360 | def generate_ref(env: Environment, test: Test, ref_dir: Path, process_controller): |
| 361 | if process_controller.is_interrupted(): |
no test coverage detected