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))
예제 #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()
예제 #3
0
def test_exec_d3_js_script_on_jupyter():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_d3_helper:test_exec_d3_js_script_on_jupyter
    """
    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.selenium_helper.driver.refresh()
    time.sleep(3)

    jupyter_helper.run_test_code(sleep_seconds=3)
    driver = selenium_helper.driver
    svg_elem = driver.find_element_by_id(settings.TEST_SVG_ELEM_ID)
    selenium_helper.save_target_elem_screenshot(target_elem=svg_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)