예제 #1
0
 def wrapped(self, *args, **kwargs):
     try:
         out = f(self, *args, **kwargs)
     except exceptions_to_handle as err:
         self.ipython_display.send_error(EXPECTED_ERROR_MSG.format(err))
         return None
     else:
         return out
예제 #2
0
 def wrapped(self, *args, **kwargs):
     try:
         out = f(self, *args, **kwargs)
     except exceptions_to_handle as err:
         self.ipython_display.send_error(EXPECTED_ERROR_MSG.format(err))
         return None
     else:
         return out
예제 #3
0
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))
예제 #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
예제 #5
0
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))
예제 #6
0
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))
예제 #7
0
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))
예제 #8
0
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))
예제 #9
0
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))
예제 #10
0
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))