Skip to content

Commit

Permalink
Implement outline of Jupyter testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 2, 2017
1 parent 395eefc commit cc3c3a9
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 0 deletions.
152 changes: 152 additions & 0 deletions test-data/selenium-test-notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Welcome to the interactive Galaxy IPython Notebook."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"You can access your data via the dataset number. For example, ``handle = open(get(42), 'r')``.\n",
"To save data, write your data to a file, and then call ``put('filename.txt')``. The dataset will then be available in your galaxy history.\n",
"Notebooks can be saved to Galaxy by clicking the large green button at the top right of the IPython interface.<br>\n",
"More help and informations can be found on the project [website](https://github.com/bgruening/galaxy-ipython)."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"'/import/1'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get(1)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"chr6_hla_hap2 0 150\r\n"
]
}
],
"source": [
"!grep chr6 /import/1"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"!echo \"Hello World\" > /tmp/cow"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"put(\"/tmp/cow\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1 [2] 1.txt.gg ipython_galaxy_notebook.ipynb\r\n"
]
}
],
"source": [
"!ls /import"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"put(\"/import/ipython_galaxy_notebook.ipynb\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
26 changes: 26 additions & 0 deletions test/galaxy_selenium/navigates_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
DATABASE_OPERATION=WaitType("database_operation", 10),
# Wait time for jobs to complete in default environment.
JOB_COMPLETION=WaitType("job_completion", 30),
# Wait time for a GIE to spawn.
GIE_SPAWN=WaitType("gie_spawn", 30),
)

# Choose a moderate wait type for operations that don't specify a type.
Expand Down Expand Up @@ -806,6 +808,30 @@ def history_panel_multi_operation_action_click(self, action):
action_element = menu_element.find_element_by_link_text(action)
action_element.click()

def history_panel_item_click_visualization_menu(self, hid):
viz_button_selector = "%s %s" % (self.history_panel_item_selector(hid), ".visualizations-dropdown")
self.wait_for_and_click_selector(viz_button_selector)
self.wait_for_selector_visible("%s %s" % (viz_button_selector, ".dropdown-menu"))

def history_panel_item_available_visualizations_elements(self, hid):
# Precondition: viz menu has been opened with history_panel_item_click_visualization_menu
viz_menu_selectors = "%s %s" % (self.history_panel_item_selector(hid), "a.visualization-link")
return self.driver.find_elements_by_css_selector(viz_menu_selectors)

def history_panel_item_available_visualizations(self, hid):
# Precondition: viz menu has been opened with history_panel_item_click_visualization_menu
return [e.text for e in self.history_panel_item_available_visualizations_elements(hid)]

def history_panel_item_click_visualization(self, hid, visualization_name):
# Precondition: viz menu has been opened with history_panel_item_click_visualization_menu
elements = self.history_panel_item_available_visualizations_elements(hid)
for element in elements:
if element.text == visualization_name:
element.click()
return element

assert False, "No visualization [%s] found." % visualization_name

def history_panel_item_selector(self, hid, wait=False):
current_history_id = self.current_history_id()
contents = self.api_get("histories/%s/contents" % current_history_id)
Expand Down
9 changes: 9 additions & 0 deletions test/selenium_tests/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ def assert_initial_history_panel_state_correct(self):
def workflow_populator(self):
return SeleniumSessionWorkflowPopulator(self)

def ensure_visualization_available(self, hid, visualization_name):
"""Skip or fail a test if visualization for file doesn't appear.
Precondition: viz menu has been opened with history_panel_item_click_visualization_menu.
"""
visualization_names = self.history_panel_item_available_visualizations(hid)
if visualization_name not in visualization_names:
raise unittest.SkipTest("Skipping test, visualization [%s] doesn't appear to be configured." % visualization_name)


class SharedStateSeleniumTestCase(SeleniumTestCase):
"""This describes a class Selenium tests that setup class state for all tests.
Expand Down
46 changes: 46 additions & 0 deletions test/selenium_tests/test_jupyter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from .framework import (
managed_history,
selenium_test,
SeleniumTestCase,
)

JUPYTER_VISUALIZATION_NAME = "Jupyter"


class JupyterTestCase(SeleniumTestCase):

ensure_registered = True

@selenium_test
@managed_history
def test_jupyter_session(self):
self.perform_upload(self.get_filename("1.txt"))
self.perform_upload(self.get_filename("selenium-test-notebook.ipynb"))
self.wait_for_history()
self.history_panel_ensure_showing_item_details(2)
self.history_panel_item_click_visualization_menu(2)
self.ensure_visualization_available(2, JUPYTER_VISUALIZATION_NAME)
self.history_panel_item_click_visualization(2, JUPYTER_VISUALIZATION_NAME)
with self.main_panel():
viz_iframe = self.wait_for_selector("body iframe", wait_type=self.wait_types.GIE_SPAWN)
try:
self.driver.switch_to.frame(viz_iframe)
self.wait_for_selector("ul.nav")
lis = self.driver.find_elements_by_css_selector("ul.nav li.dropdown")
cell_li = None
for li in lis:
if li.text == "Cell":
cell_li = li
break
cell_li.click()
self.wait_for_and_click_selector("ul#cell_menu li#run_all_cells")
finally:
self.driver.switch_to.default_content()

# TODO: wait on something in the notebook instead of sleeping so long.
self.sleep_for(wait_type=self.wait_types.JOB_COMPLETION)
self.history_panel_refresh_click()

# Re-running notebook should publish two new things to the history.
self.history_panel_wait_for_hid_ok(3)
self.history_panel_wait_for_hid_ok(4)

0 comments on commit cc3c3a9

Please sign in to comment.