File: test_nbbase.py

package info (click to toggle)
nbformat 5.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,072 kB
  • sloc: python: 4,746; makefile: 167; javascript: 2
file content (38 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations

from unittest import TestCase

from nbformat.v1.nbbase import new_code_cell, new_notebook, new_text_cell


class TestCell(TestCase):
    def test_empty_code_cell(self):
        cc = new_code_cell()
        self.assertEqual(cc.cell_type, "code")
        self.assertEqual("code" not in cc, True)
        self.assertEqual("prompt_number" not in cc, True)

    def test_code_cell(self):
        cc = new_code_cell(code="a=10", prompt_number=0)
        self.assertEqual(cc.code, "a=10")
        self.assertEqual(cc.prompt_number, 0)

    def test_empty_text_cell(self):
        tc = new_text_cell()
        self.assertEqual(tc.cell_type, "text")
        self.assertEqual("text" not in tc, True)

    def test_text_cell(self):
        tc = new_text_cell("hi")
        self.assertEqual(tc.text, "hi")


class TestNotebook(TestCase):
    def test_empty_notebook(self):
        nb = new_notebook()
        self.assertEqual(nb.cells, [])

    def test_notebooke(self):
        cells = [new_code_cell(), new_text_cell()]
        nb = new_notebook(cells=cells)
        self.assertEqual(nb.cells, cells)