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))
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()
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')
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())
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()
def test_hide_input_cell(): """ Test Command ------------ $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_hide_input_cell """ jupyter_helper.open_test_jupyter_note_book() jupyter_helper.hide_input_cell() driver = jupyter_helper.selenium_helper.driver script = 'return $(".{input_selector_class_str}").css("display");'.format( input_selector_class_str=jupyter_helper.INPUT_SELECTOR_CLASS_STR) display_style_str = driver.execute_script(script) assert_equal(display_style_str, 'none')
def test_display_cell_menu(): """ Test Command ------------ $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test_display_cell_menu """ jupyter_helper.open_test_jupyter_note_book() jupyter_helper.display_cell_menu() driver = jupyter_helper.selenium_helper.driver script = 'return $("#{cell_menu_selector_id_str}").css("display");'.format( cell_menu_selector_id_str=jupyter_helper.CELL_MENU_SELECTOR_ID_STR) display_style = driver.execute_script(script) assert_equal(display_style, 'block')
def test__get_test_code_cell_elem(): """ Test Command ------------ $ python run_tests.py --module_name plot_playground.tests.test_jupyter_helper:test__get_test_code_cell_elem """ driver = selenium_helper.start_webdriver() driver.get('https://www.google.com/') assert_raises(Exception, jupyter_helper._get_test_code_cell_elem) jupyter_helper.open_test_jupyter_note_book() code_cell_elem = jupyter_helper._get_test_code_cell_elem() assert_true(isinstance(code_cell_elem, WebElement))
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)
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()
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()
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)
def setup(): driver = selenium_helper.start_webdriver() jupyter_helper.open_test_jupyter_note_book()