Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,39 @@
|
|||
import json
|
||||
|
||||
from tornado import web
|
||||
|
||||
from ...base.handlers import APIHandler
|
||||
|
||||
|
||||
class NbconvertRootHandler(APIHandler):
|
||||
|
||||
@web.authenticated
|
||||
def get(self):
|
||||
self.check_xsrf_cookie()
|
||||
try:
|
||||
from nbconvert.exporters import base
|
||||
except ImportError as e:
|
||||
raise web.HTTPError(500, "Could not import nbconvert: %s" % e) from e
|
||||
res = {}
|
||||
exporters = base.get_export_names()
|
||||
for exporter_name in exporters:
|
||||
try:
|
||||
exporter_class = base.get_exporter(exporter_name)
|
||||
except ValueError:
|
||||
# I think the only way this will happen is if the entrypoint
|
||||
# is uninstalled while this method is running
|
||||
continue
|
||||
# XXX: According to the docs, it looks like this should be set to None
|
||||
# if the exporter shouldn't be exposed to the front-end and a friendly
|
||||
# name if it should. However, none of the built-in exports have it defined.
|
||||
# if not exporter_class.export_from_notebook:
|
||||
# continue
|
||||
res[exporter_name] = {
|
||||
"output_mimetype": exporter_class.output_mimetype,
|
||||
}
|
||||
|
||||
self.finish(json.dumps(res))
|
||||
|
||||
default_handlers = [
|
||||
(r"/api/nbconvert", NbconvertRootHandler),
|
||||
]
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,31 @@
|
|||
import requests
|
||||
|
||||
from notebook.utils import url_path_join
|
||||
from notebook.tests.launchnotebook import NotebookTestBase
|
||||
|
||||
class NbconvertAPI(object):
|
||||
"""Wrapper for nbconvert API calls."""
|
||||
def __init__(self, request):
|
||||
self.request = request
|
||||
|
||||
def _req(self, verb, path, body=None, params=None):
|
||||
response = self.request(verb,
|
||||
url_path_join('api/nbconvert', path),
|
||||
data=body, params=params,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
def list_formats(self):
|
||||
return self._req('GET', '')
|
||||
|
||||
class APITest(NotebookTestBase):
|
||||
def setUp(self):
|
||||
self.nbconvert_api = NbconvertAPI(self.request)
|
||||
|
||||
def test_list_formats(self):
|
||||
formats = self.nbconvert_api.list_formats().json()
|
||||
self.assertIsInstance(formats, dict)
|
||||
self.assertIn('python', formats)
|
||||
self.assertIn('html', formats)
|
||||
self.assertEqual(formats['python']['output_mimetype'], 'text/x-python')
|
Loading…
Add table
Add a link
Reference in a new issue