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))
Exemple #2
0
def test_open_test_jupyter_note_book():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_open_test_jupyter_note_book
    """
    jupyter_helper.open_test_jupyter_note_book()
    assert_equal(
        selenium_helper.driver.title, jupyter_helper.TEST_JUPYTER_NOTE_NAME,
        'could not open the Jupyter notebook for testing. Please check that the notebook is properly placed in the target path.'
    )
    selenium_helper.exit_webdriver()
Exemple #3
0
def test__assert_current_page_is_test_notebook():
    """
    Test Command
    ------------
    $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test__assert_current_page_is_test_notebook
    """
    selenium_helper.exit_webdriver()
    assert_raises(Exception,
                  jupyter_helper._assert_current_page_is_test_notebook)

    driver = selenium_helper.start_webdriver()
    driver.get('https://www.google.com/')
    assert_raises(Exception,
                  jupyter_helper._assert_current_page_is_test_notebook)

    jupyter_helper.open_test_jupyter_note_book()
    jupyter_helper._assert_current_page_is_test_notebook()
Exemple #4
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()
Exemple #5
0
def teardown():
    selenium_helper.exit_webdriver()
    jupyter_helper.empty_test_ipynb_code_cell()
def test_exit_webdriver():
    driver = selenium_helper.start_webdriver()
    assert_not_equal(driver, None)
    selenium_helper.exit_webdriver()
    assert_equal(selenium_helper.driver, None)