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))
Example #2
0
def test__assert_only_one_output_cell_exists():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test__assert_only_one_output_cell_exists
    """
    jupyter_helper.update_ipynb_test_source_code(source_code='print(1)')
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code()
    jupyter_helper._assert_only_one_output_cell_exists()
Example #3
0
def test_get_test_code_text_output():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_get_test_code_text_output
    """
    jupyter_helper.update_ipynb_test_source_code(source_code='print(100)')
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code()
    text_output = jupyter_helper.get_test_code_text_output()
    assert_equal(text_output, '100')
Example #4
0
def test_empty_test_ipynb_code_cell():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_empty_test_ipynb_code_cell
    """
    jupyter_helper.update_ipynb_test_source_code(source_code='print(1)')
    jupyter_helper.empty_test_ipynb_code_cell()
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code()
    assert_false(jupyter_helper.output_text_cell_exists())
Example #5
0
def test_update_ipynb_test_source_code():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_update_ipynb_test_source_code
    """
    jupyter_helper.update_ipynb_test_source_code(
        source_code='print(100)\nprint(200)')
    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper.run_test_code()
    text_output = jupyter_helper.get_test_code_text_output()
    is_in = '100' in text_output
    assert_true(is_in)
    is_in = '200' in text_output
    assert_true(is_in)
Example #6
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()
Example #7
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)