def test_run_spark_command_exception_while_storing():
    run_cell_method = MagicMock()
    exception = LivyUnexpectedStatusException('WOW')
    run_cell_method.side_effect = [(True, ""), exception]
    spark_controller.run_command = run_cell_method

    command = "-s"
    name = "sessions_name"
    context = "-c"
    context_name = "spark"
    meth = "-m"
    method_name = "sample"
    output = "-o"
    output_var = "var_name"
    line = " ".join([
        command, name, context, context_name, meth, method_name, output,
        output_var
    ])
    cell = "cell code"

    result = magic.spark(line, cell)

    run_cell_method.assert_any_call(Command(cell), name)
    run_cell_method.assert_any_call(
        SparkStoreCommand(output_var, samplemethod=method_name), name)
    ipython_display.write.assert_called_once_with("")
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(exception))
Esempio n. 2
0
 def wrapped(self, *args, **kwargs):
     try:
         out = f(self, *args, **kwargs)
     except exceptions_to_handle as err:
         # Do not log! as some messages may contain private client information
         self.ipython_display.send_error(EXPECTED_ERROR_MSG.format(err))
         return None
     else:
         return out
def test_delete_sessions_command_exception():
    mock_method = MagicMock(
        side_effect=LivyUnexpectedStatusException('FEEEEEELINGS'))
    spark_controller.delete_session_by_name = mock_method
    command = "delete -s name"
    magic.spark(command)
    mock_method.assert_called_once_with("name")
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(mock_method.side_effect))
Esempio n. 4
0
 def wrapped(self, *args, **kwargs):
     try:
         out = f(self, *args, **kwargs)
     except exceptions_to_handle as err:
         # Do not log! as some messages may contain private client information
         self.ipython_display.send_error(EXPECTED_ERROR_MSG.format(err))
         return None
     else:
         return out
def test_cleanup_command_exception():
    mock_method = MagicMock(
        side_effect=SessionManagementException('Livy did something VERY BAD'))
    spark_controller.cleanup = mock_method
    line = "cleanup"

    magic.spark(line)
    mock_method.assert_called_once_with()
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(mock_method.side_effect))
def test_info_command_exception():
    print_info_mock = MagicMock(
        side_effect=LivyClientTimeoutException('OHHHHHOHOHOHO'))
    magic._print_local_info = print_info_mock
    command = "info"

    magic.spark(command)

    print_info_mock.assert_called_once_with()
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(print_info_mock.side_effect))
def test_run_cell_command_exception():
    run_cell_method = MagicMock()
    run_cell_method.side_effect = HttpClientException('meh')
    spark_controller.run_command = run_cell_method

    command = "-s"
    name = "sessions_name"
    line = " ".join([command, name])
    cell = "cell code"

    result = magic.spark(line, cell)

    run_cell_method.assert_called_once_with(Command(cell), name)
    assert result is None
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(run_cell_method.side_effect))
Esempio n. 8
0
def test_run_cell_command_writes_to_err():
    run_cell_method = MagicMock()
    result_value = ""
    run_cell_method.return_value = (False, result_value, MIMETYPE_TEXT_PLAIN)
    spark_controller.run_command = run_cell_method

    command = "-s"
    name = "sessions_name"
    line = " ".join([command, name])
    cell = "cell code"

    result = magic.spark(line, cell)

    run_cell_method.assert_called_once_with(Command(cell), name)
    assert result is None
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(result_value))
def test_add_sessions_command_exception():
    # Do not skip and python
    add_sessions_mock = MagicMock(side_effect=BadUserDataException('hehe'))
    spark_controller.add_session = add_sessions_mock
    command = "add"
    name = "-s name"
    language = "-l python"
    connection_string = "-u http://url.com -a sdf -p w"
    line = " ".join([command, name, language, connection_string])

    magic.spark(line)

    add_sessions_mock.assert_called_once_with(
        "name", Endpoint("http://url.com", "sdf", "w"), False,
        {"kind": "pyspark"})
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(add_sessions_mock.side_effect))
def test_logs_exception():
    get_logs_method = MagicMock(
        side_effect=LivyUnexpectedStatusException('How did this happen?'))
    result_value = ""
    get_logs_method.return_value = result_value
    spark_controller.get_logs = get_logs_method

    command = "logs -s"
    name = "sessions_name"
    line = " ".join([command, name])
    cell = "cell code"

    result = magic.spark(line, cell)

    get_logs_method.assert_called_once_with(name)
    assert result is None
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(get_logs_method.side_effect))
def test_add_sessions_command_exception():
    # Do not skip and python
    add_sessions_mock = MagicMock(side_effect=BadUserDataException('hehe'))
    spark_controller.add_session = add_sessions_mock
    command = "add"
    name = "-s name"
    language = "-l python"
    connection_string = "-u http://url.com -t {} -a sdf -p w".format(
        AUTH_BASIC)
    line = " ".join([command, name, language, connection_string])

    magic.spark(line)
    args = parse_argstring_or_throw(RemoteSparkMagics.spark, line)
    add_sessions_mock.assert_called_once_with(
        "name", Endpoint("http://url.com", initialize_auth(args)), False,
        {"kind": "pyspark"})
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(add_sessions_mock.side_effect))
def test_run_sql_command_exception():
    run_cell_method = MagicMock()
    run_cell_method.side_effect = LivyUnexpectedStatusException('WOW')
    spark_controller.run_sqlquery = run_cell_method

    command = "-s"
    name = "sessions_name"
    context = "-c"
    context_name = "sql"
    meth = "-m"
    method_name = "sample"
    line = " ".join([command, name, context, context_name, meth, method_name])
    cell = "cell code"

    result = magic.spark(line, cell)

    run_cell_method.assert_called_once_with(
        SQLQuery(cell, samplemethod=method_name), name)
    ipython_display.send_error.assert_called_once_with(
        EXPECTED_ERROR_MSG.format(run_cell_method.side_effect))