Exemplo n.º 1
0
def test_df_execution_quiet_with_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    cell = SQLQuery("")
    session = MagicMock()
    output_var = "var_name"

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_sqlquery = MagicMock(return_value=df)

    res = magic.execute_sqlquery("", None, None, None, session, output_var, True)

    magic.spark_controller.run_sqlquery.assert_called_once_with(cell, session)
    assert res is None
    assert shell.user_ns[output_var] == df
Exemplo n.º 2
0
def test_df_execution_quiet_with_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    cell = SQLQuery("")
    session = MagicMock()
    output_var = "var_name"

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(return_value=df)

    res = magic.execute_sqlquery(cell, session, output_var, True)

    magic.spark_controller.run_cell_sql.assert_called_once_with(cell, session)
    assert res is None
    assert shell.user_ns[output_var] == df
Exemplo n.º 3
0
def test_df_execution_without_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    query = SQLQuery("")
    session = MagicMock()
    output_var = None

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_sqlquery = MagicMock(return_value=df)

    res = magic.execute_sqlquery("", None, None, None, session, output_var, False)

    magic.spark_controller.run_sqlquery.assert_called_once_with(query, session)
    assert res == df
    assert_equals(list(shell.user_ns.keys()), [])
Exemplo n.º 4
0
def test_df_execution_without_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    query = SQLQuery("")
    session = MagicMock()
    output_var = None

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(return_value=df)

    res = magic.execute_sqlquery(query, session, output_var, False)

    magic.spark_controller.run_cell_sql.assert_called_once_with(query, session)
    assert res == df
    assert_equals(list(shell.user_ns.keys()), [])
Exemplo n.º 5
0
def test_df_execution_quiet_without_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    cell = SQLQuery("")
    session = MagicMock()
    output_var = None

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(return_value=df)

    res = magic.execute_sqlquery(cell, session, output_var, True)

    magic.spark_controller.run_cell_sql.assert_called_once_with(cell, session)
    assert res is None
    assert_equals(list(shell.user_ns.keys()), [])
Exemplo n.º 6
0
def test_df_execution_with_output_var():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell

    df = 0
    query = SQLQuery("")
    session = MagicMock()
    output_var = "var_name"

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(return_value=df)

    res = magic.execute_sqlquery(query, session, output_var, False)

    magic.spark_controller.run_cell_sql.assert_called_once_with(query, session)
    assert res == df
    assert shell.user_ns[output_var] == df
Exemplo n.º 7
0
def test_df_execution_throws():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell
    error = "error"

    query = SQLQuery("")
    session = MagicMock()
    output_var = "var_name"

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(side_effect=DataFrameParseException(error))

    res = magic.execute_sqlquery(query, session, output_var, False)

    magic.spark_controller.run_cell_sql.assert_called_once_with(query, session)
    assert res is None
    assert_equals(list(shell.user_ns.keys()), [])
Exemplo n.º 8
0
def test_df_execution_throws():
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell
    error = "error"

    query = SQLQuery("")
    session = MagicMock()
    output_var = "var_name"

    magic.spark_controller = MagicMock()
    magic.spark_controller.run_cell_sql = MagicMock(
        side_effect=DataFrameParseException(error))

    res = magic.execute_sqlquery(query, session, output_var, False)

    magic.spark_controller.run_cell_sql.assert_called_once_with(query, session)
    assert res is None
    assert_equals(list(shell.user_ns.keys()), [])