Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JS tests for Jupyter NBs #549

Merged
merged 11 commits into from
Jan 5, 2017
Merged

Add JS tests for Jupyter NBs #549

merged 11 commits into from
Jan 5, 2017

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Aug 18, 2016

Behold: JS tests in Jupyter Notebooks are coming to plotly.py

My strategy was the following:

  1. Have a few ipynb fixture files with plotly.py code cells but no outputs
  2. Execute them using the jupyter execute api
  3. Convert the resulting ipynb JSON to HTML using nbconver api
  4. Add JS test bundle to the resulting HTML file
  5. Run the JS tests in a browser!

Step 5 was a little harder than I thought. There's a ton of test runners that take a JS bundle, shim it into an HTML page and run the tests. But, I couldn't find any test runner that takes an already made
HTML page and runs the test there. A few runners allow you to add HTML to their default test page, but I couldn't get the results I wanted, so I decided to build my little test runner see lib/server.js

TODO:

  • add more test fixtures / cases
  • get this to work on CircleCI
  • make sure this works in all python versions we support

@chriddyp @theengineear @cldougl @mdtusz



class PlotlyJupyterTestCase(TestCase):
def setUp(self):
Copy link
Contributor Author

@etpinard etpinard Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execute fixture NB and convert results to HTML

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 set_up or setup for python 🐍_case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like setUp is what we want here

image

but I'm no python expert.

@mdtusz
Copy link
Contributor

mdtusz commented Aug 18, 2016

This looks great! Will be good to get some more solid tests in for nb's.

@theengineear
Copy link
Contributor

So awesome, @etpinard!! Nice work, man!

@theengineear
Copy link
Contributor

@etpinard I'm assuming this just got back-burnered with other work, but this would be really nice to test. Status update?

@etpinard
Copy link
Contributor Author

etpinard commented Jan 4, 2017

@theengineear I got everything working locally in both python 2.7 and 3.4

Upgrading optonal-requirements.txt didn't go down so well on CircleCI. If you're up for a challenge, I could use some help.

## ipython dependencies ##
ipython[all]==3.0.0
## ipython ##
ipython
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theengineear this didn't go down so smooth on Circle.

@theengineear
Copy link
Contributor

Yup. I just upgraded our test framework to use tox. I'll fiddle around with it tomorrow am and let you know how it goes!

Challenge accepted 😸

etpinard and others added 7 commits January 5, 2017 10:08
- add coverage to optional requirements
- pip install optional requirements and no need for
  nothing else
- make lib/server.js handle arbitrary html index and js test file
  (to test multiple ipynb fixutres)
- use ipykernel to determine which python version nosetest is launched w/
- use domready to make sure that tests are ran after DOM is ready
- one testing offline connected=True
- one testing offline connected=False (the default)
@theengineear
Copy link
Contributor

@etpinard, the tests are failing for me locally because they're looking for a custom.css file? Adding a blank custom.css ends up creating two seemingly OK html files in /fixtures.

Initial error:

image

After adding custom.css:

image

$ nosetests plotly/tests/test_optional/test_jupyter/test_jupyter.py
FF
======================================================================
FAIL: test_js (test_jupyter.PlotlyJupyterConnectedFalseTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ee/PyCharmProjects/python-api/plotly/tests/test_optional/test_jupyter/test_jupyter.py", line 55, in test_js
    self.fail('One or more javascript test failed')
AssertionError: One or more javascript test failed
-------------------- >> begin captured logging << --------------------
root: INFO: Executing notebook with kernel: python2
root: DEBUG: Native kernel (python2) available from /Users/ee/venvs/python-api/lib/python2.7/site-packages/ipykernel/resources
root: DEBUG: Starting kernel: ['/Users/ee/venvs/python-api/bin/python2.7', '-m', 'ipykernel', '-f', u'/var/folders/r8/xjmvqr192r589r78rrx8_ft80000gn/T/tmp7aYXtD.json']
root: DEBUG: Connecting to: tcp://127.0.0.1:63173
root: DEBUG: connecting shell channel to tcp://127.0.0.1:63170
root: DEBUG: Connecting to: tcp://127.0.0.1:63170
root: DEBUG: connecting iopub channel to tcp://127.0.0.1:63171
root: DEBUG: Connecting to: tcp://127.0.0.1:63171
root: DEBUG: connecting stdin channel to tcp://127.0.0.1:63172
root: DEBUG: Connecting to: tcp://127.0.0.1:63172
root: DEBUG: connecting heartbeat channel to tcp://127.0.0.1:63174
root: DEBUG: Executing cell:
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.graph_objs as go

# Make plotly work with Jupyter notebook
init_notebook_mode()

keys=['one','two','three']
values=[1,2,3]

iplot({
    "data": [go.Bar(x=keys, y=values)],
    "layout": go.Layout(title="Sample Bar Chart")
})
root: DEBUG: output: status
root: DEBUG: output: execute_input
root: DEBUG: output: display_data
root: DEBUG: output: display_data
root: DEBUG: output: status
root: DEBUG: Executing cell:

root: DEBUG: output: status
root: DEBUG: output: execute_input
root: DEBUG: output: status
root: DEBUG: Applying preprocessor: coalesce_streams
root: DEBUG: Applying preprocessor: CSSHTMLHeaderPreprocessor
root: DEBUG: Applying preprocessor: HighlightMagicsPreprocessor
root: DEBUG: Attempting to load template full.tpl
root: DEBUG: Loaded template full.tpl
--------------------- >> end captured logging << ---------------------

======================================================================
FAIL: test_js (test_jupyter.PlotlyJupyterConnectedTrueTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ee/PyCharmProjects/python-api/plotly/tests/test_optional/test_jupyter/test_jupyter.py", line 55, in test_js
    self.fail('One or more javascript test failed')
AssertionError: One or more javascript test failed
-------------------- >> begin captured logging << --------------------
root: INFO: Executing notebook with kernel: python2
root: DEBUG: Native kernel (python2) available from /Users/ee/venvs/python-api/lib/python2.7/site-packages/ipykernel/resources
root: DEBUG: Starting kernel: ['/Users/ee/venvs/python-api/bin/python2.7', '-m', 'ipykernel', '-f', u'/var/folders/r8/xjmvqr192r589r78rrx8_ft80000gn/T/tmpWTCkTH.json']
root: DEBUG: Connecting to: tcp://127.0.0.1:63196
root: DEBUG: connecting shell channel to tcp://127.0.0.1:63193
root: DEBUG: Connecting to: tcp://127.0.0.1:63193
root: DEBUG: connecting iopub channel to tcp://127.0.0.1:63194
root: DEBUG: Connecting to: tcp://127.0.0.1:63194
root: DEBUG: connecting stdin channel to tcp://127.0.0.1:63195
root: DEBUG: Connecting to: tcp://127.0.0.1:63195
root: DEBUG: connecting heartbeat channel to tcp://127.0.0.1:63197
root: DEBUG: Executing cell:
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.graph_objs as go

# Make plotly work with Jupyter notebook
init_notebook_mode(connected=True)

keys=['one','two','three']
values=[1,2,3]

iplot({
    "data": [go.Bar(x=keys, y=values)],
    "layout": go.Layout(title="Sample Bar Chart")
})
root: DEBUG: output: status
root: DEBUG: output: execute_input
root: DEBUG: output: display_data
root: DEBUG: output: display_data
root: DEBUG: output: status
root: DEBUG: Executing cell:

root: DEBUG: output: status
root: DEBUG: output: execute_input
root: DEBUG: output: status
root: DEBUG: Applying preprocessor: coalesce_streams
root: DEBUG: Applying preprocessor: CSSHTMLHeaderPreprocessor
root: DEBUG: Applying preprocessor: HighlightMagicsPreprocessor
root: DEBUG: Attempting to load template full.tpl
root: DEBUG: Loaded template full.tpl
--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 2 tests in 12.386s

FAILED (failures=2)

It's not clear to me why this is failing, thoughts?

@theengineear
Copy link
Contributor

Also, I did a little (emphasis on little) about testing jupyter notebooks:

Not sure if you saw either of these, but it might be sweet to try and use a 3rd party tool so we don't have to maintain (ipython_nose). I'm not 100% sure if we can test what we need to test from inside a notebook cell, but I might take some time to check that out.

@theengineear
Copy link
Contributor

^^ nvm, all good. helps if you npm install 😸

@theengineear
Copy link
Contributor

Holy intermittent image server tests... getting a ton of:

ERROR: test_image_get_returns_valid_image_test(jpeg, 300, 300, None) (plotly.tests.test_core.test_image.test_image.TestImage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ubuntu/plotly.py/plotly/tests/test_core/test_image/test_image.py", line 27, in test
    image = py.image.get(self.data, image_format, width, height, scale)
  File "/home/ubuntu/plotly.py/plotly/plotly/plotly.py", line 715, in get
    raise exceptions.PlotlyError("The response "
nose.proxy.PlotlyError: The response from plotly could not be translated.

@theengineear
Copy link
Contributor

#649

^^ for the image server fails...

@theengineear
Copy link
Contributor

Aight, gonna merge this one in while everything is 🎏.

//cc @etpinard @chriddyp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants