예제 #1
0
    def test_notebook_iter(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        if sys.version_info[0] == 2:
            # written in Python 3
            return
        temp = get_temp_folder(__file__, "temp_notebook_add_slides_metadata")
        nbfile = os.path.join(
            temp, "..", "data", "having_a_form_in_a_notebook.ipynb")
        assert os.path.exists(nbfile)
        nb = read_nb(nbfile, kernel=False)
        for i, cell in enumerate(nb.iter_cells()):
            ls = nb.cell_height(cell)
            #fLOG(i,"-",nb.cell_type(cell), l)
            #if l > 400: fLOG(cell)
            assert ls > 0
        return
        new_tags = nb.add_tag_slide()
        for k, v in sorted(new_tags.items()):
            a, b, c = v
            fLOG(k, a, b)

        assert len(new_tags) > 0
    def test_notebook_read_write(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_notebook_read_write")
        nbfile = os.path.join(temp, "..", "data", "simple_example.ipynb")
        assert os.path.exists(nbfile)
        nb = read_nb(nbfile)

        outfile = os.path.join(temp, "out_notebook.ipynb")
        nb.to_json(outfile)
        assert os.path.exists(outfile)

        with open(nbfile, "r", encoding="utf8") as f:
            c1 = f.read().replace("\r", "")
        with open(outfile, "r", encoding="utf8") as f:
            c2 = f.read().replace("\r", "")
        if c1 != c2:
            l1 = c1.strip("\n ").split("\n")
            l2 = c2.strip("\n ").split("\n")
            for i, cc in enumerate(zip(l1, l2)):
                a, b = cc
                if a.strip(" \n") != b.strip(" \n"):
                    raise Exception(
                        "difference at line {0}\n1: [{1}]-[{3}]\n2: [{2}]-[{4}]".format(i, a, b, type(a), type(b)))
            if len(l1) != len(l2):
                raise Exception("different length")
 def test_notebook_add_slides_bug(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     temp = get_temp_folder(__file__, "temp_notebook_add_slides_bug2")
     nbfile = os.path.join(
         temp, "..", "data", "simple_example_bis.ipynb")
     assert os.path.exists(nbfile)
     nb = read_nb(nbfile)
     assert len(nb) > 0
     nb2slides(nbfile, os.path.join(temp, "ooooo.html"))
예제 #4
0
 def test_notebook_present(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     temp = get_temp_folder(__file__, "temp_notebook_present")
     nbfile = os.path.join(
         temp, "..", "data", "simple_example_bis.ipynb")
     assert os.path.exists(nbfile)
     nb = read_nb(nbfile, kernel=False)
     assert len(nb) > 0
     output = os.path.join(temp, "ooooo.html")
     nb2present(nbfile, output)
     assert os.path.exists(output)
     content = nb2present(nbfile, None)
     if isinstance(content, list):
         content = content[0]
     if len(content) < 1000:
         raise Exception(content)
    def test_notebook_add_slides_bug(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        temp = get_temp_folder(__file__, "temp_notebook_add_slides_bug")
        nbfile = os.path.join(
            temp, "..", "data", "pyensae_text2table.ipynb")
        assert os.path.exists(nbfile)
        nb = read_nb(nbfile)
        for i, cell in enumerate(nb.iter_cells()):
            l = nb.cell_height(cell)
            #fLOG(i,"-",nb.cell_type(cell), l)
            #if l > 400: fLOG(cell)
            assert l > 0

        new_tags = nb.add_tag_slide()
        for k, v in sorted(new_tags.items()):
            a, b, c = v
            fLOG(k, a, b)

        assert len(new_tags) > 0
예제 #6
0
    def test_notebook_read_write(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")
        if sys.version_info[0] == 2:
            # written in Python 3
            return
        temp = get_temp_folder(__file__, "temp_notebook_read_write")
        nbfile = os.path.join(temp, "..", "data", "simple_example.ipynb")
        assert os.path.exists(nbfile)
        # For some reason, if this instruction is included in the build,
        # the travis build completes but never ends.
        # This is removed from the whole list on tavis.
        if is_travis_or_appveyor() == "travis":
            warnings.warn(
                "This test prevents travis from ending. The process never stops.")
            return
        nb = read_nb(nbfile, kernel=False)
        outfile = os.path.join(temp, "out_notebook.ipynb")
        nb.to_json(outfile)
        assert os.path.exists(outfile)

        with open(nbfile, "r", encoding="utf8") as f:
            c1 = f.read().replace("\r", "")
        with open(outfile, "r", encoding="utf8") as f:
            c2 = f.read().replace("\r", "")
        if c1 != c2:
            l1 = c1.strip("\n ").split("\n")
            l2 = c2.strip("\n ").split("\n")
            for i, cc in enumerate(zip(l1, l2)):
                a, b = cc
                if a.strip(" \n") != b.strip(" \n"):
                    raise Exception(
                        "difference at line {0}\n1: [{1}]-[{3}]\n2: [{2}]-[{4}]".format(i, a, b, type(a), type(b)))
            if len(l1) != len(l2):
                raise Exception("different length")