Skip to content

Commit

Permalink
[tests] test yaml files using jupyter_nbextensions_configurator
Browse files Browse the repository at this point in the history
to avoid typos which may prevent nbextensions getting installed
  • Loading branch information
jcb91 committed Oct 5, 2017
1 parent 375a9be commit 2dc13a5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ requirements:
- jupyter_core
- jupyter_highlight_selected_word >=0.0.10
- jupyter_latex_envs >=1.3.8
- jupyter_nbextensions_configurator >=0.2.6
- jupyter_nbextensions_configurator >=0.2.8
- nbconvert >=4.2
- notebook >=4.0
- pyyaml
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ipython
jupyter_highlight_selected_word>=0.0.5
jupyter_latex_envs>=1.3.4
jupyter_nbextensions_configurator
jupyter_nbextensions_configurator>=0.2.8
readthedocs-sphinx-ext
recommonmark>=0.4.0
sphinx>=1.3.6,<1.6
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def main():
'jupyter_core',
'jupyter_highlight_selected_word >=0.0.10',
'jupyter_latex_envs >=1.3.8',
'jupyter_nbextensions_configurator >=0.2.6',
'jupyter_nbextensions_configurator >=0.2.8',
'nbconvert >=4.2',
'notebook >=4.0',
'pyyaml',
Expand Down
31 changes: 31 additions & 0 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
absolute_import, division, print_function, unicode_literals,
)

import io
import itertools
import json
import logging
Expand All @@ -14,15 +15,18 @@

import jupyter_core.paths
import nose.tools as nt
import yaml
from jupyter_contrib_core.notebook_compat import nbextensions
from jupyter_contrib_core.testing_utils import (
get_logger, patch_traitlets_app_logs,
)
from jupyter_contrib_core.testing_utils.jupyter_env import patch_jupyter_dirs
from jupyter_nbextensions_configurator import _process_nbextension_spec
from nose.plugins.skip import SkipTest
from traitlets.config import Config
from traitlets.tests.utils import check_help_all_output, check_help_output

import jupyter_contrib_nbextensions
from jupyter_contrib_nbextensions.application import main as main_app
from jupyter_contrib_nbextensions.application import (
BaseContribNbextensionsApp, BaseContribNbextensionsInstallApp,
Expand All @@ -31,6 +35,12 @@
)
from jupyter_contrib_nbextensions.install import toggle_install

# attempt to use LibYaml if available
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader

app_classes = (
BaseContribNbextensionsApp, BaseContribNbextensionsInstallApp,
ContribNbextensionsApp,
Expand Down Expand Up @@ -312,3 +322,24 @@ def test_15_app_install_only_config(self):
self.check_app_install(
argv=argv + ['--only-config'], dirs=dirs,
dirs_install={'conf': dirs['conf']})

def test_16_yaml_files(self):
"""Check that the configurator accepts all nbextension yaml files."""
errmsg = ''
root_nbext_dir = os.path.join(os.path.dirname(
jupyter_contrib_nbextensions.__file__), 'nbextensions')
for direct, dirs, files in os.walk(root_nbext_dir, followlinks=True):
for fname in files:
if os.path.splitext(fname)[1] not in ('.yml', '.yaml'):
continue
yaml_path = os.path.join(direct, fname)
with io.open(yaml_path, 'r', encoding='utf-8') as stream:
try:
spec = yaml.load(stream, Loader=SafeLoader)
except yaml.YAMLError:
errmsg += '\nFailed to load yaml: {}'.format(yaml_path)
continue
spec = _process_nbextension_spec(spec)
if not isinstance(spec, dict):
errmsg += '\n{}: {}'.format(spec, os.path.reyaml_path)
nt.assert_false(len(errmsg), 'Error loading yaml file(s):' + errmsg)

0 comments on commit 2dc13a5

Please sign in to comment.