예제 #1
0
def test_preprocess():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    files = preprocessor.preprocess()
    converted_notebook_path = posixpath.join(os.path.dirname(
        NOTEBOOK_PATH), os.path.basename(preprocessor.executable))
    os.remove(converted_notebook_path)
    assert Path(converted_notebook_path) in files
예제 #2
0
def test_get_command():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    preprocessor.preprocess()
    command = preprocessor.get_command()
    conv_notebook_context_path = posixpath.join(DEFAULT_DEST_PREFIX,
                                                CONVERTED_NOTEBOOK_PATH)
    expected_command = 'python {}'.format(conv_notebook_context_path)
    assert command == expected_command.split()
예제 #3
0
def test_overwrite_file_for_multiple_runs():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    files = preprocessor.preprocess()
    files_overwrite = preprocessor.preprocess()
    converted_notebook_path = posixpath.join(os.path.dirname(
        NOTEBOOK_PATH), os.path.basename(preprocessor.executable))
    os.remove(converted_notebook_path)
    assert files == files_overwrite
def test_get_command():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    preprocessor.preprocess()
    command = preprocessor.get_command()
    converted_notebook_path = posixpath.join(os.path.dirname(NOTEBOOK_PATH), os.path.basename(preprocessor.executable))
    conv_notebook_context_path = posixpath.join(DEFAULT_DEST_PREFIX, converted_notebook_path)
    expected_command = 'python {}'.format(conv_notebook_context_path)
    os.remove(converted_notebook_path)
    assert command == expected_command.split()
예제 #5
0
def test_context_tar_gz():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    context_file, _ = preprocessor.context_tar_gz()
    tar = tarfile.open(context_file)
    relative_path_prefix = posixpath.relpath(DEFAULT_DEST_PREFIX, "/")
    notebook_context_path = posixpath.join(relative_path_prefix,
                                           CONVERTED_NOTEBOOK_PATH)
    tar_notebook = tar.extractfile(tar.getmember(notebook_context_path))
    assert "print('Hello World')" in tar_notebook.read().decode()
def test_context_tar_gz():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    context_file, _ = preprocessor.context_tar_gz()
    tar = tarfile.open(context_file)
    relative_path_prefix = posixpath.relpath(DEFAULT_DEST_PREFIX, "/")
    converted_notebook_path = posixpath.join(os.path.dirname(NOTEBOOK_PATH), os.path.basename(preprocessor.executable))
    notebook_context_path = posixpath.join(relative_path_prefix, converted_notebook_path)
    tar_notebook = tar.extractfile(tar.getmember(notebook_context_path))
    os.remove(converted_notebook_path)
    assert "print('Hello World')" in tar_notebook.read().decode()
def test_filter_include_cell():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH,
                                               notebook_preprocessor=FilterIncludeCell)
    context_file, _ = preprocessor.context_tar_gz()
    tar = tarfile.open(context_file)
    relative_path_prefix = posixpath.relpath(DEFAULT_DEST_PREFIX, "/")
    converted_notebook_path = posixpath.join(os.path.dirname(NOTEBOOK_PATH), os.path.basename(preprocessor.executable))
    notebook_context_path = posixpath.join(relative_path_prefix, converted_notebook_path)
    tar_notebook = tar.extractfile(tar.getmember(notebook_context_path))
    tar_notebook_text = tar_notebook.read().decode()
    os.remove(converted_notebook_path)
    assert "print('This cell includes fairing:include-cell')" in tar_notebook_text
예제 #8
0
def test_preprocess():
    preprocessor = ConvertNotebookPreprocessor(notebook_file=NOTEBOOK_PATH)
    files = preprocessor.preprocess()
    assert Path(CONVERTED_NOTEBOOK_PATH) in files