Exemple #1
0
def sanity_check(template_dir):
    logger.info("Starting sanity check")
    os.environ["PY_TEMPLATE_DIR"] = template_dir
    try:
        for template_name in templates._all_templates():
            logger.info(
                "========================[ Sanity checking {} ]========================"
                .format(template_name))
            # Test conversion to ipynb - this will throw if stuff goes wrong
            generate_ipynb_from_py(filesystem.get_template_dir(),
                                   template_name,
                                   warn_on_local=False)

            # Test that each template has parameters as expected
            nb = templates.template_name_to_notebook_node(template_name,
                                                          warn_on_local=False)
            param_idx = templates._get_parameters_cell_idx(nb)
            if param_idx is None:
                logger.warning(
                    'Template {} does not have a "parameters"-tagged cell.'.
                    format(template_name))

            # Test that we can generate a preview from the template
            preview = templates._get_preview(template_name,
                                             warn_on_local=False)
            # Previews in HTML are gigantic since they include all jupyter css and js.
            assert len(
                preview
            ) > 1000, "Preview was not properly generated for {}".format(
                template_name)
            logger.info(
                "========================[ {} PASSED ]========================"
                .format(template_name))
    finally:
        filesystem._cleanup_dirs()
Exemple #2
0
def test_template_has_parameters(template_name):
    generate_ipynb_from_py(get_template_dir(),
                           template_name,
                           warn_on_local=False)
    nb = template_name_to_notebook_node(template_name, warn_on_local=False)
    metadata_idx = _get_parameters_cell_idx(nb)
    assert metadata_idx is not None, 'Template {} does not have a "parameters"-tagged cell.'.format(
        template_name)
Exemple #3
0
def test_template_has_parameters(template_name, template_dir, flask_app):
    flask_app.config["PY_TEMPLATE_DIR"] = ""
    with flask_app.app_context():
        generate_ipynb_from_py(template_dir,
                               template_name,
                               notebooker_disable_git=True,
                               py_template_dir="",
                               warn_on_local=False)
        nb = template_name_to_notebook_node(template_name,
                                            notebooker_disable_git=True,
                                            py_template_dir="",
                                            warn_on_local=False)
        metadata_idx = _get_parameters_cell_idx(nb)
        assert metadata_idx is not None, 'Template {} does not have a "parameters"-tagged cell.'.format(
            template_name)