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.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
Used to test globbing.
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"nbformat_minor": 0,
|
||||
"cells": [],
|
||||
"nbformat": 4,
|
||||
"metadata": {}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Used to test globbing.
|
|
@ -0,0 +1,80 @@
|
|||
"""Test the bundlers API."""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import io
|
||||
from os.path import join as pjoin
|
||||
|
||||
from notebook.tests.launchnotebook import NotebookTestBase
|
||||
from nbformat import write
|
||||
from nbformat.v4 import (
|
||||
new_notebook, new_markdown_cell, new_code_cell, new_output,
|
||||
)
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
def bundle(handler, model):
|
||||
"""Bundler test stub. Echo the notebook path."""
|
||||
handler.finish(model['path'])
|
||||
|
||||
class BundleAPITest(NotebookTestBase):
|
||||
"""Test the bundlers web service API"""
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
"""Make a test notebook. Borrowed from nbconvert test. Assumes the class
|
||||
teardown will clean it up in the end."""
|
||||
super(BundleAPITest, cls).setup_class()
|
||||
nbdir = cls.notebook_dir
|
||||
|
||||
nb = new_notebook()
|
||||
|
||||
nb.cells.append(new_markdown_cell(u'Created by test'))
|
||||
cc1 = new_code_cell(source=u'print(2*6)')
|
||||
cc1.outputs.append(new_output(output_type="stream", text=u'12'))
|
||||
nb.cells.append(cc1)
|
||||
|
||||
with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w',
|
||||
encoding='utf-8') as f:
|
||||
write(nb, f, version=4)
|
||||
|
||||
def test_missing_bundler_arg(self):
|
||||
"""Should respond with 400 error about missing bundler arg"""
|
||||
resp = self.request('GET', 'bundle/fake.ipynb')
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertIn('Missing argument bundler', resp.text)
|
||||
|
||||
def test_notebook_not_found(self):
|
||||
"""Shoudl respond with 404 error about missing notebook"""
|
||||
resp = self.request('GET', 'bundle/fake.ipynb',
|
||||
params={'bundler': 'fake_bundler'})
|
||||
self.assertEqual(resp.status_code, 404)
|
||||
self.assertIn('Not Found', resp.text)
|
||||
|
||||
def test_bundler_not_enabled(self):
|
||||
"""Should respond with 400 error about disabled bundler"""
|
||||
resp = self.request('GET', 'bundle/testnb.ipynb',
|
||||
params={'bundler': 'fake_bundler'})
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertIn('Bundler fake_bundler not enabled', resp.text)
|
||||
|
||||
def test_bundler_import_error(self):
|
||||
"""Should respond with 500 error about failure to load bundler module"""
|
||||
with patch('notebook.bundler.handlers.BundlerHandler.get_bundler') as mock:
|
||||
mock.return_value = {'module_name': 'fake_module'}
|
||||
resp = self.request('GET', 'bundle/testnb.ipynb',
|
||||
params={'bundler': 'fake_bundler'})
|
||||
mock.assert_called_with('fake_bundler')
|
||||
self.assertEqual(resp.status_code, 500)
|
||||
self.assertIn('Could not import bundler fake_bundler', resp.text)
|
||||
|
||||
def test_bundler_invoke(self):
|
||||
"""Should respond with 200 and output from test bundler stub"""
|
||||
with patch('notebook.bundler.handlers.BundlerHandler.get_bundler') as mock:
|
||||
mock.return_value = {'module_name': 'notebook.bundler.tests.test_bundler_api'}
|
||||
resp = self.request('GET', 'bundle/testnb.ipynb',
|
||||
params={'bundler': 'stub_bundler'})
|
||||
mock.assert_called_with('stub_bundler')
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertIn('testnb.ipynb', resp.text)
|
|
@ -0,0 +1,124 @@
|
|||
"""Test the bundler tools."""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import notebook.bundler.tools as tools
|
||||
|
||||
HERE = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
class TestBundlerTools(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tmp, ignore_errors=True)
|
||||
|
||||
def test_get_no_cell_references(self):
|
||||
'''Should find no references in a regular HTML comment.'''
|
||||
no_references = tools.get_cell_reference_patterns({'source':'''!<--
|
||||
a
|
||||
b
|
||||
c
|
||||
-->''', 'cell_type':'markdown'})
|
||||
self.assertEqual(len(no_references), 0)
|
||||
|
||||
def test_get_cell_reference_patterns_comment_multiline(self):
|
||||
'''Should find two references and ignore a comment within an HTML comment.'''
|
||||
cell = {'cell_type':'markdown', 'source':'''<!--associate:
|
||||
a
|
||||
b/
|
||||
#comment
|
||||
-->'''}
|
||||
references = tools.get_cell_reference_patterns(cell)
|
||||
self.assertTrue('a' in references and 'b/' in references, str(references))
|
||||
self.assertEqual(len(references), 2, str(references))
|
||||
|
||||
def test_get_cell_reference_patterns_comment_trailing_filename(self):
|
||||
'''Should find three references within an HTML comment.'''
|
||||
cell = {'cell_type':'markdown', 'source':'''<!--associate:c
|
||||
a
|
||||
b/
|
||||
#comment
|
||||
-->'''}
|
||||
references = tools.get_cell_reference_patterns(cell)
|
||||
self.assertTrue('a' in references and 'b/' in references and 'c' in references, str(references))
|
||||
self.assertEqual(len(references), 3, str(references))
|
||||
|
||||
def test_get_cell_reference_patterns_precode(self):
|
||||
'''Should find no references in a fenced code block in a *code* cell.'''
|
||||
self.assertTrue(tools.get_cell_reference_patterns)
|
||||
no_references = tools.get_cell_reference_patterns({'source':'''```
|
||||
foo
|
||||
bar
|
||||
baz
|
||||
```
|
||||
''', 'cell_type':'code'})
|
||||
self.assertEqual(len(no_references), 0)
|
||||
|
||||
def test_get_cell_reference_patterns_precode_mdcomment(self):
|
||||
'''Should find two references and ignore a comment in a fenced code block.'''
|
||||
cell = {'cell_type':'markdown', 'source':'''```
|
||||
a
|
||||
b/
|
||||
#comment
|
||||
```'''}
|
||||
references = tools.get_cell_reference_patterns(cell)
|
||||
self.assertTrue('a' in references and 'b/' in references, str(references))
|
||||
self.assertEqual(len(references), 2, str(references))
|
||||
|
||||
def test_get_cell_reference_patterns_precode_backticks(self):
|
||||
'''Should find three references in a fenced code block.'''
|
||||
cell = {'cell_type':'markdown', 'source':'''```c
|
||||
a
|
||||
b/
|
||||
#comment
|
||||
```'''}
|
||||
references = tools.get_cell_reference_patterns(cell)
|
||||
self.assertTrue('a' in references and 'b/' in references and 'c' in references, str(references))
|
||||
self.assertEqual(len(references), 3, str(references))
|
||||
|
||||
def test_glob_dir(self):
|
||||
'''Should expand to single file in the resources/ subfolder.'''
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'),
|
||||
tools.expand_references(HERE, ['resources/empty.ipynb']))
|
||||
|
||||
def test_glob_subdir(self):
|
||||
'''Should expand to all files in the resources/ subfolder.'''
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'),
|
||||
tools.expand_references(HERE, ['resources/']))
|
||||
|
||||
def test_glob_splat(self):
|
||||
'''Should expand to all contents under this test/ directory.'''
|
||||
globs = tools.expand_references(HERE, ['*'])
|
||||
self.assertIn('test_bundler_tools.py', globs, globs)
|
||||
self.assertIn('resources', globs, globs)
|
||||
|
||||
def test_glob_splatsplat_in_middle(self):
|
||||
'''Should expand to test_file.txt deep under this test/ directory.'''
|
||||
globs = tools.expand_references(HERE, ['resources/**/test_file.txt'])
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_glob_splatsplat_trailing(self):
|
||||
'''Should expand to all descendants of this test/ directory.'''
|
||||
globs = tools.expand_references(HERE, ['resources/**'])
|
||||
self.assertIn(os.path.join('resources', 'empty.ipynb'), globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_glob_splatsplat_leading(self):
|
||||
'''Should expand to test_file.txt under any path.'''
|
||||
globs = tools.expand_references(HERE, ['**/test_file.txt'])
|
||||
self.assertIn(os.path.join('resources', 'subdir', 'test_file.txt'), globs, globs)
|
||||
self.assertIn(os.path.join('resources', 'another_subdir', 'test_file.txt'), globs, globs)
|
||||
|
||||
def test_copy_filelist(self):
|
||||
'''Should copy select files from source to destination'''
|
||||
globs = tools.expand_references(HERE, ['**/test_file.txt'])
|
||||
tools.copy_filelist(HERE, self.tmp, globs)
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources', 'subdir', 'test_file.txt')))
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.tmp, 'resources', 'another_subdir', 'test_file.txt')))
|
||||
self.assertFalse(os.path.isfile(os.path.join(self.tmp, 'resources', 'empty.ipynb')))
|
|
@ -0,0 +1,72 @@
|
|||
"""Test the bundlerextension CLI."""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from unittest.mock import patch
|
||||
from ipython_genutils.tempdir import TemporaryDirectory
|
||||
from ipython_genutils import py3compat
|
||||
|
||||
from traitlets.tests.utils import check_help_all_output
|
||||
|
||||
import notebook.nbextensions as nbextensions
|
||||
from notebook.config_manager import BaseJSONConfigManager
|
||||
from ..bundlerextensions import (_get_config_dir, enable_bundler_python,
|
||||
disable_bundler_python)
|
||||
|
||||
def test_help_output():
|
||||
check_help_all_output('notebook.bundler.bundlerextensions')
|
||||
check_help_all_output('notebook.bundler.bundlerextensions', ['enable'])
|
||||
check_help_all_output('notebook.bundler.bundlerextensions', ['disable'])
|
||||
|
||||
class TestBundlerExtensionCLI(unittest.TestCase):
|
||||
"""Tests the bundlerextension CLI against the example zip_bundler."""
|
||||
def setUp(self):
|
||||
"""Build an isolated config environment."""
|
||||
td = TemporaryDirectory()
|
||||
|
||||
self.test_dir = py3compat.cast_unicode(td.name)
|
||||
self.data_dir = os.path.join(self.test_dir, 'data')
|
||||
self.config_dir = os.path.join(self.test_dir, 'config')
|
||||
self.system_data_dir = os.path.join(self.test_dir, 'system_data')
|
||||
self.system_path = [self.system_data_dir]
|
||||
|
||||
# Use temp directory, not real user or system config paths
|
||||
self.patch_env = patch.dict('os.environ', {
|
||||
'JUPYTER_CONFIG_DIR': self.config_dir,
|
||||
'JUPYTER_DATA_DIR': self.data_dir,
|
||||
})
|
||||
self.patch_env.start()
|
||||
self.patch_system_path = patch.object(nbextensions,
|
||||
'SYSTEM_JUPYTER_PATH', self.system_path)
|
||||
self.patch_system_path.start()
|
||||
|
||||
def tearDown(self):
|
||||
"""Remove the test config environment."""
|
||||
shutil.rmtree(self.test_dir, ignore_errors=True)
|
||||
self.patch_env.stop()
|
||||
self.patch_system_path.stop()
|
||||
|
||||
def test_enable(self):
|
||||
"""Should add the bundler to the notebook configuration."""
|
||||
enable_bundler_python('notebook.bundler.zip_bundler')
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
bundlers = cm.get('notebook').get('bundlerextensions', {})
|
||||
self.assertEqual(len(bundlers), 1)
|
||||
self.assertIn('notebook_zip_download', bundlers)
|
||||
|
||||
def test_disable(self):
|
||||
"""Should remove the bundler from the notebook configuration."""
|
||||
self.test_enable()
|
||||
disable_bundler_python('notebook.bundler.zip_bundler')
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
bundlers = cm.get('notebook').get('bundlerextensions', {})
|
||||
self.assertEqual(len(bundlers), 0)
|
Loading…
Add table
Add a link
Reference in a new issue