def test_display_plot():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_storytelling_slope_plot:test_display_plot
    """
    source_code = """
from plot_playground.tests.test_storytelling_slope_plot import display_test_plot
display_test_plot()
    """
    jupyter_helper.update_ipynb_test_source_code(source_code=source_code)
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code(sleep_seconds=10)
    jupyter_helper.hide_header()
    jupyter_helper.hide_input_cell()
    svg_elem = selenium_helper.driver.find_element_by_id(
        settings.TEST_SVG_ELEM_ID)
    selenium_helper.save_target_elem_screenshot(target_elem=svg_elem)
    selenium_helper.exit_webdriver()
    expected_img_path = img_helper.get_test_expected_img_path(
        file_name='slope_plot_display_plot')
    similarity = img_helper.compare_img_hist(
        img_path_1=selenium_helper.DEFAULT_TEST_IMG_PATH,
        img_path_2=expected_img_path)
    assert_greater_equal(similarity, 0.99)

    plot_meta = display_test_plot()
    assert_true(isinstance(plot_meta, d3_helper.PlotMeta))
Esempio n. 2
0
def test_display_plot():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_linux_stats_plot:test_display_plot
    """
    source_code = """
from plot_playground.tests.test_linux_stats_plot import display_test_plot
display_test_plot()
    """
    jupyter_helper.update_ipynb_test_source_code(source_code=source_code)
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code(sleep_seconds=10)
    jupyter_helper.hide_header()
    jupyter_helper.hide_input_cell()
    selenium_helper.driver.set_window_size(width=1400, height=1300)
    count = 0
    while True:
        try:
            svg_elem = selenium_helper.driver.find_element_by_id(
                settings.TEST_SVG_ELEM_ID)
            break
        except Exception:
            count += 1
            if count > 5:
                break
            time.sleep(3)
            continue
    selenium_helper.save_target_elem_screenshot(target_elem=svg_elem)
    expected_img_path = img_helper.get_test_expected_img_path(
        file_name='stats_linux_stats_plot_display_plot')
    similarity = img_helper.compare_img_hist(
        img_path_1=selenium_helper.DEFAULT_TEST_IMG_PATH,
        img_path_2=expected_img_path)
    assert_greater(similarity, 0.8)
    selenium_helper.exit_webdriver()

    plot_meta = display_test_plot()
    assert_true(isinstance(plot_meta, d3_helper.PlotMeta))

    jupyter_helper.empty_test_ipynb_code_cell()
Esempio n. 3
0
def test_hide_header():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_hide_header
    """
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.hide_header()
    time.sleep(5)
    driver = jupyter_helper.selenium_helper.driver

    script = 'return $("#{header_container_id}").css("display");'.format(
        header_container_id=jupyter_helper.HEADER_CONTAINER_SELECTOR_ID_STR)
    display_style_str = driver.execute_script(script)
    assert_equal(display_style_str, 'none')

    script = 'return $("#{menu_bar_container_id}").css("display");'.format(
        menu_bar_container_id=jupyter_helper.\
            MENU_BAR_CONTAINER_SELECTOR_ID_STR
    )
    display_style_str = driver.execute_script(script)
    assert_equal(display_style_str, 'none')
def test_save_target_elem_screenshot():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_selenium_helper:test_save_target_elem_screenshot
    """

    script_str = read_jupyter_test_python_script(
        script_file_name='exec_d3_js_script_on_jupyter')
    jupyter_helper.update_ipynb_test_source_code(source_code=script_str)
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code(sleep_seconds=5)
    driver = selenium_helper.driver
    jupyter_helper.hide_input_cell()
    jupyter_helper.hide_header()
    target_elem = driver.find_element_by_id(settings.TEST_SVG_ELEM_ID)
    selenium_helper.save_target_elem_screenshot(target_elem=target_elem)
    expected_img_path = img_helper.get_test_expected_img_path(
        file_name='exec_d3_js_script_on_jupyter')
    similarity = img_helper.compare_img_hist(
        img_path_1=selenium_helper.DEFAULT_TEST_IMG_PATH,
        img_path_2=expected_img_path)
    assert_equal(similarity, 1.0)