Esempio n. 1
0
def test_is_jupyter_notebook():
    nbtext = """
    {
        "cells": [],
        "metadata": {},
        "nbformat": 4,
        "nbformat_minor": 2
    }
    """
    with TempDir() as d:
        f = open(os.path.join(d, "sample.txt"), "w")
        assert not util.is_jupyter_notebook(f.name)
        f = open(os.path.join(d, "null.ipynb"), "w")
        assert util.is_jupyter_notebook(f.name, check_contents=False)
        assert not util.is_jupyter_notebook(f.name)
        f = open(os.path.join(d, "basic.ipynb"), "w")
        f.write(nbtext)
        f.close()
        assert util.is_jupyter_notebook(f.name)
        f = open(os.path.join(d, "random.ipynb"), "w")
        f.write('{"random": [1,2,3]}')
        f.close()
        assert not util.is_jupyter_notebook(f.name)
Esempio n. 2
0
def test_is_jupyter_notebook():
    nbtext = """
    {
        "cells": [],
        "metadata": {},
        "nbformat": 4,
        "nbformat_minor": 2
    }
    """
    tmp_dir = scratch_path / "is_jupyter_notebook"
    tmp_dir.mkdir()
    f = (tmp_dir / "sample.txt").open("w")
    assert not util.is_jupyter_notebook(f.name)
    f = (tmp_dir / "null.ipynb").open("w")
    assert util.is_jupyter_notebook(f.name, check_contents=False)
    assert not util.is_jupyter_notebook(f.name)
    f = (tmp_dir / "basic.ipynb").open("w")
    f.write(nbtext)
    f.close()
    assert util.is_jupyter_notebook(f.name)
    f = (tmp_dir / "random.ipynb").open("w")
    f.write('{"random": [1,2,3]}')
    f.close()
    assert not util.is_jupyter_notebook(f.name)