예제 #1
0
def test_link():
    url = u"https://microsoft.com"
    magic = SparkMagicBase(None)
    assert_equals(magic._link(u'Link', url), u"""<a target="_blank" href="https://microsoft.com">Link</a>""")

    url = None
    assert_equals(magic._link(u'Link', url), u"")
예제 #2
0
def _setup():
    global magic, session, shell, ipython_display
    shell = MagicMock()
    shell.user_ns = {}
    magic = SparkMagicBase(None)
    magic.shell = shell
    session = MagicMock()
    magic.spark_controller = MagicMock()
    magic.ipython_display = MagicMock()
예제 #3
0
def test_link():
    url = u"https://microsoft.com"
    magic = SparkMagicBase(None)
    assert_equals(
        magic._link(u'Link', url),
        u"""<a target="_blank" href="https://microsoft.com">Link</a>""")

    url = None
    assert_equals(magic._link(u'Link', url), u"")
예제 #4
0
def test_print_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = 1
    session1 = MagicMock()
    session1.id = 1
    session1.get_row_html.return_value = u"""<tr><td>row1</td></tr>"""
    session2 = MagicMock()
    session2.id = 3
    session2.get_row_html.return_value = u"""<tr><td>row2</td></tr>"""
    magic._print_endpoint_info([session2, session1], current_session_id)
    magic.ipython_display.html.assert_called_once_with(u"""<table>
<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>Current session?</th></tr>\
<tr><td>row1</td></tr><tr><td>row2</td></tr>\
</table>""")
def test_print_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = 1
    session1 = MagicMock()
    session1.id = 1
    session1.get_row_html.return_value = u"""<tr><td>row1</td></tr>"""
    session2 = MagicMock()
    session2.id = 3
    session2.get_row_html.return_value = u"""<tr><td>row2</td></tr>"""
    magic._print_endpoint_info([session2, session1], current_session_id)
    magic.ipython_display.html.assert_called_once_with(
        u"""<table>
<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>Current session?</th></tr>\
<tr><td>row1</td></tr><tr><td>row2</td></tr>\
</table>"""
    )
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
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()), [])
예제 #8
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
예제 #9
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()), [])
예제 #10
0
def test_print_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = 1
    session1 = MagicMock()
    session1.id = 1
    session1.get_app_id.return_value = 'app1234'
    session1.kind = SESSION_KIND_PYSPARK
    session1.status = IDLE_SESSION_STATUS
    session1.get_spark_ui_url.return_value = 'https://microsoft.com/sparkui'
    session1.get_driver_log_url.return_value = 'https://microsoft.com/driverlog'
    session2 = MagicMock()
    session2.id = 3
    session2.get_app_id.return_value = 'app5069'
    session2.kind = SESSION_KIND_SPARK
    session2.status = BUSY_SESSION_STATUS
    session2.get_spark_ui_url.return_value = None
    session2.get_driver_log_url.return_value = None
    magic._print_endpoint_info([session2, session1], current_session_id)
    magic.ipython_display.html.assert_called_once_with(u"""<table>
<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>Current session?</th></tr>\
<tr><td>1</td><td>app1234</td><td>pyspark</td><td>idle</td><td><a target="_blank" href="https://microsoft.com/sparkui">Link</a></td><td><a target="_blank" href="https://microsoft.com/driverlog">Link</a></td><td>\u2714</td></tr>\
<tr><td>3</td><td>app5069</td><td>spark</td><td>busy</td><td></td><td></td><td></td></tr>\
</table>""")
예제 #11
0
def test_print_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = 1
    session1 = MagicMock()
    session1.id = 1
    session1.get_app_id.return_value = 'app1234'
    session1.kind = SESSION_KIND_PYSPARK
    session1.status = IDLE_SESSION_STATUS
    session1.get_spark_ui_url.return_value = 'https://microsoft.com/sparkui'
    session1.get_driver_log_url.return_value = 'https://microsoft.com/driverlog'
    session2 = MagicMock()
    session2.id = 3
    session2.get_app_id.return_value = 'app5069'
    session2.kind = SESSION_KIND_SPARK
    session2.status = BUSY_SESSION_STATUS
    session2.get_spark_ui_url.return_value = None
    session2.get_driver_log_url.return_value = None
    magic._print_endpoint_info([session2, session1], current_session_id)
    magic.ipython_display.html.assert_called_once_with(u"""<table>
<tr><th>ID</th><th>YARN Application ID</th><th>Kind</th><th>State</th><th>Spark UI</th><th>Driver log</th><th>Current session?</th></tr>\
<tr><td>1</td><td>app1234</td><td>pyspark</td><td>idle</td><td><a target="_blank" href="https://microsoft.com/sparkui">Link</a></td><td><a target="_blank" href="https://microsoft.com/driverlog">Link</a></td><td>\u2714</td></tr>\
<tr><td>3</td><td>app5069</td><td>spark</td><td>busy</td><td></td><td></td><td></td></tr>\
</table>""")
예제 #12
0
def test_load_emits_event():
    spark_events = MagicMock()
    SparkMagicBase(None, spark_events=spark_events)
    spark_events.emit_library_loaded_event.assert_called_once_with()
def test_print_empty_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = None
    magic._print_endpoint_info([], current_session_id)
    magic.ipython_display.html.assert_called_once_with(u"No active sessions.")
예제 #14
0
def test_print_empty_endpoint_info():
    magic = SparkMagicBase(None)
    magic.ipython_display = MagicMock()
    current_session_id = None
    magic._print_endpoint_info([], current_session_id)
    magic.ipython_display.html.assert_called_once_with(u'No active sessions.')