Beispiel #1
0
 def test_that_if_scene_file_is_missing_in_archived_files_verification_mismatch_is_raised(
         self):
     with mock.patch("verifier.utils.get_files_list_from_archive",
                     side_effect=["", "result.png"]):
         with pytest.raises(VerificationMismatch) as exception_wrapper:
             validate_downloaded_archives(self.subtask_id,
                                          self.archives_list,
                                          self.scene_file)
         assert_that(exception_wrapper.value.subtask_id).is_equal_to(
             self.subtask_id)
Beispiel #2
0
 def test_that_if_archive_is_not_a_zip_file_verification_mismatch_is_raised(
         self):
     with mock.patch("verifier.utils.get_files_list_from_archive",
                     side_effect=BadZipFile):
         with pytest.raises(VerificationMismatch) as exception_wrapper:
             validate_downloaded_archives(self.subtask_id,
                                          self.archives_list,
                                          self.scene_file)
         assert_that(exception_wrapper.value.subtask_id).is_equal_to(
             self.subtask_id)
Beispiel #3
0
 def test_that_if_one_of_the_files_to_be_unpacked_already_exists_verification_error_is_raised(
         self):
     with mock.patch("verifier.utils.get_files_list_from_archive",
                     side_effect=["kitten.blend", "result.png"]):
         with mock.patch("verifier.utils.os.listdir",
                         return_value="result.png"):
             with pytest.raises(VerificationError) as exception_wrapper:
                 validate_downloaded_archives(self.subtask_id,
                                              self.archives_list,
                                              self.scene_file)
             assert_that(exception_wrapper.value.subtask_id).is_equal_to(
                 self.subtask_id)
             assert_that(exception_wrapper.value.error_code).\
                 is_equal_to(ErrorCode.VERIFIER_UNPACKING_ARCHIVE_FAILED)
Beispiel #4
0
def blender_verification_order(
    subtask_id: str,
    source_package_path: str,
    source_size: int,
    source_package_hash: str,
    result_package_path: str,
    result_size: int,
    result_package_hash: str,
    output_format: str,
    scene_file: str,
    verification_deadline: Union[int, float],
    frames: List[int],
    blender_crop_script_parameters: Dict[str, Union[int, List[float], bool]],
) -> None:
    log(logger,
        f'Blender_verification_order_starts. SUBTASK_ID: {subtask_id}.',
        f'Source_package_path: {source_package_path}.',
        f'Source_size: {source_size}.',
        f'Source_package_hash: {source_package_hash}.',
        f'Result_package_path: {result_package_path}.',
        f'Result_size: {result_size}.',
        f'Result_package_hash: {result_package_hash}.',
        f'Output_format: {output_format}.', f'Scene_file: {scene_file}.',
        f'Frames: {frames}.')

    assert output_format in BlenderSubtaskDefinition.OutputFormat.__members__.keys(
    )
    assert source_package_path != result_package_path
    assert source_package_hash != result_package_hash
    assert (source_size and source_package_hash
            and source_package_path) and (result_size and result_package_hash
                                          and result_package_path)
    assert isinstance(subtask_id, str)
    assert isinstance(verification_deadline, (int, float))
    assert blender_crop_script_parameters is not None

    # Generate a FileTransferToken valid for a download of any file listed in the order.
    file_transfer_token = create_file_transfer_token_for_concent(
        subtask_id=subtask_id,
        source_package_path=source_package_path,
        source_size=source_size,
        source_package_hash=source_package_hash,
        result_package_path=result_package_path,
        result_size=result_size,
        result_package_hash=result_package_hash,
        operation=message.concents.FileTransferToken.Operation.download,
    )

    package_paths_to_downloaded_archive_names = {
        source_package_path: f'source_{os.path.basename(source_package_path)}',
        result_package_path: f'result_{os.path.basename(result_package_path)}',
    }

    download_archives_from_storage(file_transfer_token, subtask_id,
                                   package_paths_to_downloaded_archive_names)

    validate_downloaded_archives(
        subtask_id, package_paths_to_downloaded_archive_names.values(),
        scene_file)

    unpack_archives(package_paths_to_downloaded_archive_names.values(),
                    subtask_id)

    result_files_list = get_files_list_from_archive(
        generate_verifier_storage_file_path(
            package_paths_to_downloaded_archive_names[result_package_path]))

    ensure_enough_result_files_provided(
        frames=frames,
        result_files_list=result_files_list,
        subtask_id=subtask_id,
    )

    parsed_files_to_compare = parse_result_files_with_frames(
        frames=frames,
        result_files_list=result_files_list,
        output_format=output_format,
    )

    ensure_frames_have_related_files_to_compare(
        frames=frames,
        parsed_files_to_compare=parsed_files_to_compare,
        subtask_id=subtask_id,
    )

    (blender_output_file_name_list,
     parsed_files_to_compare) = render_images_by_frames(
         parsed_files_to_compare=parsed_files_to_compare,
         frames=frames,
         output_format=output_format,
         scene_file=scene_file,
         subtask_id=subtask_id,
         verification_deadline=verification_deadline,
         blender_crop_script_parameters=blender_crop_script_parameters,
     )

    delete_source_files(
        package_paths_to_downloaded_archive_names[source_package_path],
        subtask_id)

    upload_blender_output_file(
        frames=frames,
        blender_output_file_name_list=blender_output_file_name_list,
        output_format=output_format,
        subtask_id=subtask_id,
    )

    ssim_list = compare_all_rendered_images_with_user_results_files(
        parsed_files_to_compare=parsed_files_to_compare,
        subtask_id=subtask_id,
    )

    compare_minimum_ssim_with_results(ssim_list, subtask_id)
Beispiel #5
0
def blender_verification_order(
    subtask_id: str,
    source_package_path: str,
    source_size: int,
    source_package_hash: str,
    result_package_path: str,
    result_size: int,
    result_package_hash: str,
    output_format: str,
    scene_file: str,
    verification_deadline: int,
    frames: List[int],
    blender_crop_script: Optional[str],
):
    log_string_message(
        logger,
        f'Blender_verification_order_starts. SUBTASK_ID: {subtask_id}.',
        f'Source_package_path: {source_package_path}.',
        f'Source_size: {source_size}.',
        f'Source_package_hash: {source_package_hash}.',
        f'Result_package_path: {result_package_path}.',
        f'Result_size: {result_size}.',
        f'Result_package_hash: {result_package_hash}.',
        f'Output_format: {output_format}.', f'Scene_file: {scene_file}.',
        f'Frames: {frames}.')

    assert output_format in BlenderSubtaskDefinition.OutputFormat.__members__.keys(
    )
    assert source_package_path != result_package_path
    assert source_package_hash != result_package_hash
    assert (source_size and source_package_hash
            and source_package_path) and (result_size and result_package_hash
                                          and result_package_path)
    assert isinstance(subtask_id, str)
    assert isinstance(verification_deadline, int)

    # this is a temporary hack - dummy verification which's result depends on subtask_id only

    if settings.MOCK_VERIFICATION_ENABLED:
        result = VerificationResult.MATCH.name if subtask_id[
            -1] == 'm' else VerificationResult.MISMATCH.name
        if subtask_id[-1] == 'm':
            verification_result.delay(
                subtask_id,
                result,
            )
        log_string_message(
            logger,
            f'Temporary hack, verification result depends on subtask_id only - SUBTASK_ID: {subtask_id}. Result: {result}'
        )
        return

    # Generate a FileTransferToken valid for a download of any file listed in the order.
    file_transfer_token = create_file_transfer_token_for_concent(
        subtask_id=subtask_id,
        source_package_path=source_package_path,
        source_size=source_size,
        source_package_hash=source_package_hash,
        result_package_path=result_package_path,
        result_size=result_size,
        result_package_hash=result_package_hash,
        operation=message.FileTransferToken.Operation.download,
    )

    package_paths_to_downloaded_archive_names = {
        source_package_path: f'source_{os.path.basename(source_package_path)}',
        result_package_path: f'result_{os.path.basename(result_package_path)}',
    }

    download_archives_from_storage(file_transfer_token, subtask_id,
                                   package_paths_to_downloaded_archive_names)

    validate_downloaded_archives(
        subtask_id, package_paths_to_downloaded_archive_names.values(),
        scene_file)

    unpack_archives(package_paths_to_downloaded_archive_names.values(),
                    subtask_id)

    result_files_list = get_files_list_from_archive(
        generate_verifier_storage_file_path(
            package_paths_to_downloaded_archive_names[result_package_path]))

    ensure_enough_result_files_provided(
        frames=frames,
        result_files_list=result_files_list,
        subtask_id=subtask_id,
    )

    parsed_files_to_compare = parse_result_files_with_frames(
        frames=frames,
        result_files_list=result_files_list,
        output_format=output_format,
    )

    ensure_frames_have_related_files_to_compare(
        frames=frames,
        parsed_files_to_compare=parsed_files_to_compare,
        subtask_id=subtask_id,
    )

    (blender_output_file_name_list,
     parsed_files_to_compare) = render_images_by_frames(
         parsed_files_to_compare=parsed_files_to_compare,
         frames=frames,
         output_format=output_format,
         scene_file=scene_file,
         subtask_id=subtask_id,
         verification_deadline=verification_deadline,
         blender_crop_script=blender_crop_script,
     )

    delete_source_files(
        package_paths_to_downloaded_archive_names[source_package_path])

    upload_blender_output_file(
        frames=frames,
        blender_output_file_name_list=blender_output_file_name_list,
        output_format=output_format,
        subtask_id=subtask_id,
    )

    ssim_list = compare_all_rendered_images_with_user_results_files(
        parsed_files_to_compare=parsed_files_to_compare,
        subtask_id=subtask_id,
    )

    compare_minimum_ssim_with_results(ssim_list, subtask_id)