Ejemplo n.º 1
0
class TestBook:
    def setup_method(self):
        self.book = Book(root=books_path / "example")

    def test_book_metadata(self):
        self.book.parse()
        metadata = {
            "language": "en",
            "title": "Basic Introducction to Python",
            "description": "Basic introduction to Python",
            "created": "16/10/2020",
            "updated": "16/10/2020",
            "authors": ["Santos Gallegos"],
            "contents": {
                "Introducction": "intro.rst",
                "Nested Content": "nested.rst",
            },
        }
        assert self.book.metadata == metadata

    def test_book_chapters(self):
        self.book.parse()

        chapters = self.book.chapters
        assert len(chapters) == 2

        chapter_one = chapters[0]
        assert isinstance(chapter_one, BookChapter)
        assert chapter_one.title == "Introducction"
        assert chapter_one.file.name == "intro.rst"

        chapter_two = chapters[1]
        assert isinstance(chapter_two, BookChapter)
        assert chapter_two.title == "Nested Content"
        assert chapter_two.file.name == "nested.rst"
Ejemplo n.º 2
0
    def __init__(self, path):
        self.theme = "default"
        sections_list = []
        for section in ["text", "prompt"]:
            sections_list.append(sections[section])

        book = Book(root=path)
        book.parse()
        chapters = book.chapters[1]
        chapters.parse()

        contents = chapters.contents[0]
        render = self.get_label(contents)
        label = Label(merge_formatted_text(render))

        self.container = HSplit(
            [
                VSplit(
                    [
                        sections["menu"],
                        sections["vseparator"],
                        HSplit([label, sections["prompt"]]),
                    ]
                ),
                sections["hseparator"],
                sections["status"],
            ]
        )
Ejemplo n.º 3
0
class TestBookChapter:
    def setup_method(self):
        self.book = Book(root=books_path / "example")
        self.book.parse(all=True)
        self.chapter_one = self.book.chapters[0]
        self.chapter_two = self.book.chapters[1]

    def test_chapter_metadata(self):
        metadata = {
            "tags": "comments",
            "level": "easy",
        }
        assert self.chapter_one.metadata == metadata

        metadata = {
            "tags": "nested content, toc",
            "level": "medium",
        }
        assert self.chapter_two.metadata == metadata

    def test_chapter_toc(self):
        toc = [
            ("Comments", []),
        ]
        assert self.chapter_one.toc() == toc

        toc = [
            (
                "I'm a title",
                [
                    ("I'm a subtitle", []),
                    ("I'm another subtitle", []),
                ],
            )
        ]
        assert self.chapter_two.toc() == toc

    def test_chapter_toc_custom_min_depth(self):
        toc = [("I'm a title", [])]
        assert self.chapter_two.toc(depth=1) == toc

    def test_chapter_toc_custom_max_depth(self):
        toc = [
            (
                "I'm a title",
                [
                    ("I'm a subtitle", []),
                    (
                        "I'm another subtitle",
                        [("Another one", [])],
                    ),
                ],
            )
        ]
        assert self.chapter_two.toc(depth=99) == toc
Ejemplo n.º 4
0
 def setup_method(self):
     book = Book(root=books_path / "renderer")
     book.parse(all=True)
     self.tui = mock.MagicMock()
     self.chapters = book.chapters
Ejemplo n.º 5
0
class TestBookChapter:
    def setup_method(self):
        self.book = Book(root=books_path / "example")
        self.book.parse(all=True)
        self.chapter_one = self.book.chapters[0]
        self.chapter_two = self.book.chapters[1]

    def assert_toc(self, toc, expected_toc):
        """Recursively check that `toc` has the same hierarchy as `expected`."""
        if isinstance(expected_toc, list):
            assert isinstance(toc, list)
            assert len(toc) == len(expected_toc)
            for element, expected_element in zip(toc, expected_toc):
                self.assert_toc(element, expected_element)
        else:
            section = toc[0]
            content = toc[1]
            assert section.options.title == expected_toc[0]
            self.assert_toc(content, expected_toc[1])

    def test_chapter_metadata(self):
        metadata = {
            "tags": "comments",
            "level": "easy",
        }
        assert self.chapter_one.metadata == metadata

        metadata = {
            "tags": "nested content, toc",
            "level": "medium",
        }
        assert self.chapter_two.metadata == metadata

    def test_chapter_toc(self):
        toc = [
            ("Comments", []),
        ]
        self.assert_toc(
            self.chapter_one.toc(),
            toc,
        )

        toc = [(
            "I'm a title",
            [
                ("I'm a subtitle", []),
                ("I'm another subtitle", []),
            ],
        )]
        self.assert_toc(
            self.chapter_two.toc(),
            toc,
        )

    def test_chapter_toc_custom_min_depth(self):
        toc = [("I'm a title", [])]
        self.assert_toc(
            self.chapter_two.toc(depth=1),
            toc,
        )

    def test_chapter_toc_custom_max_depth(self):
        toc = [(
            "I'm a title",
            [
                ("I'm a subtitle", []),
                (
                    "I'm another subtitle",
                    [("Another one", [])],
                ),
            ],
        )]
        self.assert_toc(
            self.chapter_two.toc(depth=99),
            toc,
        )

    def test_chapter_repr(self):
        assert str(self.chapter_one) == "<BookChapter: Introduction>"
        assert str(self.chapter_two) == "<BookChapter: Nested Content>"