예제 #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()
예제 #2
0
def test_template_can_generate_preview(template_dir, template_name, flask_app):
    flask_app.config["PY_TEMPLATE_DIR"] = ""
    with flask_app.app_context():
        preview = _get_preview(template_name,
                               notebooker_disable_git=True,
                               py_template_dir="",
                               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)
예제 #3
0
def run_report_get_preview(report_name):
    """
    Get a preview of the Notebook Template which is about to be executed.

    :param report_name: The parameter here should be a "/"-delimited string which mirrors the directory structure of \
        the notebook templates.

    :returns: An HTML rendering of a notebook template which has been converted from .py -> .ipynb -> .html
    """
    report_name = convert_report_name_url_to_path(report_name)
    # Handle the case where a rendered ipynb asks for "custom.css"
    if ".css" in report_name:
        return ""
    return _get_preview(report_name)
예제 #4
0
def run_report_get_preview(report_name):
    """
    Get a preview of the Notebook Template which is about to be executed.

    :param report_name: The parameter here should be a "/"-delimited string which mirrors the directory structure of \
        the notebook templates.

    :returns: An HTML rendering of a notebook template which has been converted from .py -> .ipynb -> .html
    """
    report_name = convert_report_name_url_to_path(report_name)
    # Handle the case where a rendered ipynb asks for "custom.css"
    if ".css" in report_name:
        return ""
    return _get_preview(
        report_name,
        notebooker_disable_git=current_app.config["NOTEBOOKER_DISABLE_GIT"],
        py_template_dir=_get_python_template_dir(),
    )
예제 #5
0
def test_template_can_generate_preview(template_dir, template_name):
    print(template_name)
    preview = _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)