Example #1
0
def test_keep_cols(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv',
                 '--keep_cols', 'a, b, c']

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/api/v1/',
            base_headers={},
            user=mock.ANY,
            pwd=None,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            n_retry=3,
            concurrent=4,
            resume=False,
            n_samples=1000,
            out_file='out.csv',
            keep_cols=['a', 'b', 'c'],
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            timeout=30,
            ui=mock.ANY
        )
Example #2
0
def test_no_required_params(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '--n_samples', '10',
        '--n_concurrent', '1', '--no'
    ]
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
    assert not mock_method.called
Example #3
0
def test_no_required_params(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '--n_samples',
                 '10',
                 '--n_concurrent', '1', '--no']
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
    assert not mock_method.called
Example #4
0
def test_lower_case_for_user(monkeypatch):
    main_args = [
        '--host', 'http://*****:*****@datarobot.com', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--n_samples', '10', '--n_concurrent', '1'
    ]

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/predApi/v1.0/',
            base_headers={},
            user='******',
            pwd=mock.ANY,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            deployment_id=None,
            import_id=None,
            n_retry=3,
            concurrent=1,
            resume=None,
            n_samples=10,
            out_file='out.csv',
            keep_cols=None,
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            pred_threshold_name=None,
            pred_decision_name=None,
            timeout=None,
            ui=mock.ANY,
            auto_sample=False,
            fast_mode=False,
            dry_run=False,
            encoding='',
            skip_dialect=False,
            skip_row_id=False,
            output_delimiter=None,
            compression=False,
            field_size_limit=None,
            verify_ssl=True,
            max_prediction_explanations=0,
        )
Example #5
0
def test_without_passed_user_and_passwd(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv',
                 '--n_samples',
                 '10',
                 '--n_concurrent', '1', '--no']

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/predApi/v1.0/',
            base_headers={},
            user=mock.ANY,
            pwd=mock.ANY,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            import_id=None,
            n_retry=3,
            concurrent=1,
            resume=None,
            n_samples=10,
            out_file='out.csv',
            keep_cols=None,
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            timeout=None,
            ui=mock.ANY,
            auto_sample=False,
            fast_mode=False,
            dry_run=False,
            encoding='',
            skip_dialect=False,
            skip_row_id=False,
            output_delimiter=None,
            compression=False,
            field_size_limit=None,
            verify_ssl=True
        )
Example #6
0
def test_unicode_decode_error_message_fast(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--encoding=ascii', '--fast', '--dry_run'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        mock_method.side_effect = UnicodeDecodeError('test', b'', 1, 1, 'test')
        assert main(argv=main_args) == 1

    ui.error.assert_has_calls([
        mock.call("'test' codec can't decode bytes in position 1-0: test"),
        mock.call("You are using --fast option, which uses a small sample "
                  "of data to figuring out the encoding of your file. You "
                  "can try to specify the encoding directly for this file "
                  "by using the encoding flag (e.g. --encoding utf-8). "
                  "You could also try to remove the --fast mode to auto-"
                  "detect the encoding with a larger sample size")
    ])
Example #7
0
def test_unicode_decode_error_message_fast(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv',
                 '--encoding=ascii', '--fast', '--dry_run']

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        mock_method.side_effect = UnicodeDecodeError('test',
                                                     b'', 1, 1, 'test')
        assert main(argv=main_args) == 1

    ui.error.assert_has_calls([
        mock.call("'test' codec can't decode bytes in position 1-0: test"),
        mock.call("You are using --fast option, which uses a small sample "
                  "of data to figuring out the encoding of your file. You "
                  "can try to specify the encoding directly for this file "
                  "by using the encoding flag (e.g. --encoding utf-8). "
                  "You could also try to remove the --fast mode to auto-"
                  "detect the encoding with a larger sample size")
    ])
Example #8
0
def test_input_dataset_doesnt_exist(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'file-not-exists.csv'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with('file file-not-exists.csv does not exist.')
Example #9
0
def test_skip_row_id(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv',
                 '--skip_row_id',
                 '--encoding=utf-8', '--skip_dialect']

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/api/v1/',
            base_headers={},
            user=mock.ANY,
            pwd=None,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            n_retry=3,
            concurrent=4,
            resume=False,
            n_samples=False,
            out_file='out.csv',
            keep_cols=None,
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            timeout=30,
            ui=mock.ANY,
            fast_mode=False,
            auto_sample=True,
            dry_run=False,
            encoding='utf-8',
            skip_dialect=True,
            skip_row_id=True,
            output_delimiter=None
        )
Example #10
0
def test_bad_objectid(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93caa',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)
    monkeypatch.setattr('datarobot_batch_scoring.main.verify_objectid',
                        mock.Mock(side_effect=ValueError('bad objectid')))

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with('bad objectid')
Example #11
0
def test_invalid_delimiter(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '--delimiter', 'INVALID',
        '56dd9570018e213242dfa93c', '56dd9570018e213242dfa93d',
        'tests/fixtures/temperatura_predict.csv'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with(
        'Delimiter "INVALID" is not a valid delimiter.')
Example #12
0
def test_output_delimiter(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--output_delimiter=tab', '--encoding=utf-8', '--skip_dialect'
    ]

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/predApi/v1.0/',
            base_headers={},
            user=mock.ANY,
            pwd=mock.ANY,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            import_id=None,
            n_retry=3,
            concurrent=4,
            resume=None,
            n_samples=False,
            out_file='out.csv',
            keep_cols=None,
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            timeout=None,
            ui=mock.ANY,
            fast_mode=False,
            auto_sample=True,
            dry_run=False,
            encoding='utf-8',
            skip_dialect=True,
            skip_row_id=False,
            output_delimiter='\t',
            compression=False,
            field_size_limit=None,
            verify_ssl=True)
Example #13
0
def test_input_dataset_doesnt_exist(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'file-not-exists.csv']

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with('file file-not-exists.csv does not exist.')
Example #14
0
def test_reason_codes_not_compatible_wit_old_api(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--api_version', 'api/v1', '--max_prediction_explanations', '3'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
    assert not mock_method.called
    ui.fatal.assert_called_with('Prediction explanation is not available for '
                                'api_version `api/v1` please use the '
                                '`predApi/v1.0` or deployments endpoint')
Example #15
0
def test_without_passed_user_and_passwd(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--n_samples', '10', '--n_concurrent', '1', '--no'
    ]

    monkeypatch.setattr('datarobot_batch_scoring.main.UI', mock.Mock(spec=UI))

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        main(argv=main_args)
        mock_method.assert_called_once_with(
            base_url='http://localhost:53646/api/v1/',
            base_headers={},
            user=mock.ANY,
            pwd=mock.ANY,
            api_token=None,
            create_api_token=False,
            pid='56dd9570018e213242dfa93c',
            lid='56dd9570018e213242dfa93d',
            import_id=None,
            n_retry=3,
            concurrent=1,
            resume=False,
            n_samples=10,
            out_file='out.csv',
            keep_cols=None,
            delimiter=None,
            dataset='tests/fixtures/temperatura_predict.csv',
            pred_name=None,
            timeout=30,
            ui=mock.ANY,
            auto_sample=False,
            fast_mode=False,
            dry_run=False,
            encoding='',
            skip_dialect=False,
            skip_row_id=False,
            output_delimiter=None,
            compression=False)
Example #16
0
def test_bad_objectid(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93caa',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv']

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)
    monkeypatch.setattr('datarobot_batch_scoring.main.verify_objectid',
                        mock.Mock(side_effect=ValueError('bad objectid')))

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with('bad objectid')
Example #17
0
def test_invalid_delimiter(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 '--delimiter', 'INVALID',
                 'tests/fixtures/temperatura_predict.csv']

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    ui.fatal.side_effect = SystemExit
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        with pytest.raises(SystemExit):
            main(argv=main_args)
        assert not mock_method.called
    ui.fatal.assert_called_with(
        'Delimiter "INVALID" is not a valid delimiter.')
Example #18
0
def test_unicode_decode_error_message_slow(monkeypatch):
    main_args = [
        '--host', 'http://localhost:53646/api', '56dd9570018e213242dfa93c',
        '56dd9570018e213242dfa93d', 'tests/fixtures/temperatura_predict.csv',
        '--dry_run'
    ]

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch('datarobot_batch_scoring.main'
                    '.run_batch_predictions') as mock_method:
        mock_method.side_effect = UnicodeDecodeError('test', b'', 1, 1, 'test')
        assert main(argv=main_args) == 1

    # Without fast flag, we don't show the verbose error message
    ui.error.assert_called_with(
        "'test' codec can't decode bytes in position 1-0: test")
Example #19
0
def test_unicode_decode_error_message_slow(monkeypatch):
    main_args = ['--host',
                 'http://localhost:53646/api',
                 '56dd9570018e213242dfa93c',
                 '56dd9570018e213242dfa93d',
                 'tests/fixtures/temperatura_predict.csv',
                 '--dry_run']

    ui_class = mock.Mock(spec=UI)
    ui = ui_class.return_value
    monkeypatch.setattr('datarobot_batch_scoring.main.UI', ui_class)

    with mock.patch(
            'datarobot_batch_scoring.main'
            '.run_batch_predictions') as mock_method:
        mock_method.side_effect = UnicodeDecodeError('test',
                                                     b'', 1, 1, 'test')
        assert main(argv=main_args) == 1

    # Without fast flag, we don't show the verbose error message
    ui.error.assert_called_with(
        "'test' codec can't decode bytes in position 1-0: test"
    )
Example #20
0
from datarobot_batch_scoring import main
# This exists as a simple entrypoint for PyInstaller

main.main()
Example #21
0
import sys

from datarobot_batch_scoring import main
# This exists as a simple entrypoint for PyInstaller

sys.exit(main.main())