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