# Path: datarobot_batch_scoring/api_response_handlers/pred_api_v10.py
# def row_id_field(result_sorted, batch):
# def prediction_values_fields(result_sorted, pred_name):
# def keep_original_fields(batch, keep_cols, fast_mode, input_delimiter):
#     def rows_generator():
# def prediction_explanation_fields(
#     result_sorted,
#     prediction_explanations_key,
#     num_prediction_explanations,
# ):
#     def rows_generator():
# def pred_threshold_field(result_sorted, pred_threshold_name):
# def pred_decision_field(result_sorted, pred_decision):
# def format_data(result, batch, **opts):
#     def _find_prediction_explanations_key():
# def unpack_data(request):
# 
# Path: datarobot_batch_scoring/api_response_handlers/api_v1.py
# def format_data(result, batch, **opts):
# def unpack_data(request):
# 
# Path: datarobot_batch_scoring/consts.py
# SENTINEL = Batch(-1, 0, None, '', -1)
# ERROR_SENTINEL = Batch(-1, 1, None, '', -1)
# REPORT_INTERVAL = 5
# DEPRECATION_WARNING = (
#     '{yellow}{bold}Deprecation Warning!{reset} '
#     'The Batch Scoring script is deprecated. It will continue functioning '
#     'indefinitely, but it will not receive any new bug fixes and new '
#     'functionality. Please, use the Batch Prediction command-line tools '
#     'instead: '
#     '({underline}https://app.datarobot.com/docs/predictions'
#     '/batch/cli-scripts.html{reset}).'
#     .format(
#         yellow='\033[93m',
#         bold='\033[1m',
#         reset='\033[0m',
#         underline='\033[4m'
#     )
#    )
#     CTX_WARNING = 'CTX_WARNING'
#     CTX_ERROR = 'CTX_ERROR'
#     RESPONSE = 'RESPONSE'
#     SENTINEL = 'SENTINEL'
#     SHOVEL_DONE = 'SHOVEL_DONE'
#     SHOVEL_ERROR = 'SHOVEL_ERROR'
#     SHOVEL_CSV_ERROR = 'SHOVEL_CSV_ERROR'
#     SHOVEL_PROGRESS = 'SHOVEL_PROGRESS'
#     NETWORK_DONE = 'NETWORK_DONE'
#     NETWORK_ERROR = 'NETWORK_ERROR'
#     NETWORK_PROGRESS = 'NETWORK_PROGRESS'
#     WRITER_DONE = 'WRITER_DONE'
#     WRITER_ERROR = 'WRITER_ERROR'
#     WRITER_PROGRESS = 'WRITER_PROGRESS'
#     REGRESSION = 'Regression'
#     BINARY = 'Binary'
# class WriterQueueMsg(object):
# class ProgressQueueMsg(object):
# class TargetType(object):
# 
# Path: datarobot_batch_scoring/exceptions.py
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


import pytest
from datarobot_batch_scoring.api_response_handlers import pred_api_v10, api_v1
from datarobot_batch_scoring.consts import Batch
from datarobot_batch_scoring.exceptions import UnexpectedKeptColumnCount, \
    NoPredictionThresholdInResult
          'fast_mode': False,
          'delimiter': ','},
         ['row_id', 'readmitted', 'threshold', 'label'],
         [[0, 1, 0.5, 1], [1, 1, 0.5, 1]]),
    ))
    def test_format_data(self, parsed_pred_api_v10_predictions, batch,
                         opts, expected_fields, expected_values):
        fields, values = pred_api_v10.format_data(
            parsed_pred_api_v10_predictions, batch, **opts)
        assert fields == expected_fields
        assert values == expected_values

    @pytest.mark.parametrize('opts', [
        {'pred_name': None,
         'pred_threshold_name': 'threshold',
         'keep_cols': None,
         'skip_row_id': False,
         'fast_mode': False,
         'delimiter': ','},
    ])
    def test_fail_threshold_on_non_binary_classification(
            self, parsed_pred_api_v10_predictions_regression,
            batch, opts):
        with pytest.raises(NoPredictionThresholdInResult):
            pred_api_v10.format_data(
                parsed_pred_api_v10_predictions_regression, batch, **opts)


class TestApiV1Handlers(object):
    def test_unpack_data(self):

# Path: datarobot_batch_scoring/api_response_handlers/pred_api_v10.py
# def row_id_field(result_sorted, batch):
# def prediction_values_fields(result_sorted, pred_name):
# def keep_original_fields(batch, keep_cols, fast_mode, input_delimiter):
#     def rows_generator():
# def prediction_explanation_fields(
#     result_sorted,
#     prediction_explanations_key,
#     num_prediction_explanations,
# ):
#     def rows_generator():
# def pred_threshold_field(result_sorted, pred_threshold_name):
# def pred_decision_field(result_sorted, pred_decision):
# def format_data(result, batch, **opts):
#     def _find_prediction_explanations_key():
# def unpack_data(request):
# 
# Path: datarobot_batch_scoring/api_response_handlers/api_v1.py
# def format_data(result, batch, **opts):
# def unpack_data(request):
# 
# Path: datarobot_batch_scoring/consts.py
# SENTINEL = Batch(-1, 0, None, '', -1)
# ERROR_SENTINEL = Batch(-1, 1, None, '', -1)
# REPORT_INTERVAL = 5
# DEPRECATION_WARNING = (
#     '{yellow}{bold}Deprecation Warning!{reset} '
#     'The Batch Scoring script is deprecated. It will continue functioning '
#     'indefinitely, but it will not receive any new bug fixes and new '
#     'functionality. Please, use the Batch Prediction command-line tools '
#     'instead: '
#     '({underline}https://app.datarobot.com/docs/predictions'
#     '/batch/cli-scripts.html{reset}).'
#     .format(
#         yellow='\033[93m',
#         bold='\033[1m',
#         reset='\033[0m',
#         underline='\033[4m'
#     )
#    )
#     CTX_WARNING = 'CTX_WARNING'
#     CTX_ERROR = 'CTX_ERROR'
#     RESPONSE = 'RESPONSE'
#     SENTINEL = 'SENTINEL'
#     SHOVEL_DONE = 'SHOVEL_DONE'
#     SHOVEL_ERROR = 'SHOVEL_ERROR'
#     SHOVEL_CSV_ERROR = 'SHOVEL_CSV_ERROR'
#     SHOVEL_PROGRESS = 'SHOVEL_PROGRESS'
#     NETWORK_DONE = 'NETWORK_DONE'
#     NETWORK_ERROR = 'NETWORK_ERROR'
#     NETWORK_PROGRESS = 'NETWORK_PROGRESS'
#     WRITER_DONE = 'WRITER_DONE'
#     WRITER_ERROR = 'WRITER_ERROR'
#     WRITER_PROGRESS = 'WRITER_PROGRESS'
#     REGRESSION = 'Regression'
#     BINARY = 'Binary'
# class WriterQueueMsg(object):
# class ProgressQueueMsg(object):
# class TargetType(object):
# 
# Path: datarobot_batch_scoring/exceptions.py
# class UnexpectedKeptColumnCount(Exception):
#     pass
# 
# class NoPredictionThresholdInResult(Exception):
#     pass


# Path: tests/test_api_response_handlers.py
import pytest
from datarobot_batch_scoring.api_response_handlers import pred_api_v10, api_v1
from datarobot_batch_scoring.consts import Batch
from datarobot_batch_scoring.exceptions import UnexpectedKeptColumnCount, \
    NoPredictionThresholdInResult

          'fast_mode': False,
          'delimiter': ','},
         ['row_id', 'readmitted', 'threshold', 'label'],
         [[0, 1, 0.5, 1], [1, 1, 0.5, 1]]),
    ))
    def test_format_data(self, parsed_pred_api_v10_predictions, batch,
                         opts, expected_fields, expected_values):
        fields, values = pred_api_v10.format_data(
            parsed_pred_api_v10_predictions, batch, **opts)
        assert fields == expected_fields
        assert values == expected_values

    @pytest.mark.parametrize('opts', [
        {'pred_name': None,
         'pred_threshold_name': 'threshold',
         'keep_cols': None,
         'skip_row_id': False,
         'fast_mode': False,
         'delimiter': ','},
    ])
    def test_fail_threshold_on_non_binary_classification(
            self, parsed_pred_api_v10_predictions_regression,
            batch, opts):
        with pytest.raises(NoPredictionThresholdInResult):
            pred_api_v10.format_data(
                parsed_pred_api_v10_predictions_regression, batch, **opts)


class TestApiV1Handlers(object):
    def test_unpack_data(self):

        result = api_v1.unpack_data({