示例#1
0
def test_upgrade_without_nbminor_version():
    here = os.path.dirname(__file__)
    with open(os.path.join(here, os.pardir, "no_min_version.ipynb"), encoding="utf-8") as f:
        nb = reads(f.read())

    with pytest.raises(ValidationError):
        convert.upgrade(nb)
示例#2
0
def test_upgrade_v4_to_4_dot_5():
    here = os.path.dirname(__file__)
    with open(os.path.join(here, os.pardir, "test4.ipynb"), encoding="utf-8") as f:
        nb = reads(f.read())

    assert nb["nbformat_minor"] == 0
    validate(nb)
    assert nb.cells[0].get("id") is None

    nb_up = convert.upgrade(nb)
    assert nb_up["nbformat_minor"] == 5
    validate(nb_up)
    assert nb_up.cells[0]["id"] is not None
示例#3
0
 def test_read_jpeg(self):
     """JPEG output data is b64 unicode"""
     s = writes(nb0)
     nb1 = nbjson.reads(s)
     found_jpeg = False
     for cell in nb1.cells:
         if "outputs" not in cell:
             continue
         for output in cell.outputs:
             if "data" not in output:
                 continue
             if "image/jpeg" in output.data:
                 found_jpeg = True
                 jpegdata = output.data["image/jpeg"]
                 self.assertEqual(type(jpegdata), str)
                 # test that it is valid b64 data
                 b64bytes = jpegdata.encode("ascii")
                 raw_bytes = decodebytes(b64bytes)
     assert found_jpeg, "never found jpeg output"
示例#4
0
def test_sample_notebook():
    here = os.path.dirname(__file__)
    with open(os.path.join(here, os.pardir, os.pardir, "tests", "test4.ipynb"),
              encoding="utf-8") as f:
        nb = reads(f.read())
    validate4(nb)
示例#5
0
 def test_roundtrip_split(self):
     """Ensure that splitting multiline blocks is safe"""
     # This won't differ from test_roundtrip unless the default changes
     s = writes(nb0, split_lines=True)
     self.assertEqual(nbjson.reads(s), nb0)
示例#6
0
 def test_roundtrip_nosplit(self):
     """Ensure that multiline blobs are still readable"""
     # ensures that notebooks written prior to splitlines change
     # are still readable.
     s = writes(nb0, split_lines=False)
     self.assertEqual(nbjson.reads(s), nb0)