Exemplo n.º 1
0
 def render_section(self, section):
     renderer = Renderer(tui=self.tui, section=section)
     self.text_area = FormattedTextArea(
         merge_formatted_text(renderer.render()),
         scrollbar=True,
         focusable=True,
         after_copy=partial(notify_after_copy, self.tui),
     )
     self.reset(self.text_area)
Exemplo n.º 2
0
    def test_unknow_codeblock(self):
        expected = """
Unknown

This is an unknown or unsupported language:

┌─ [ Copy ] ─────────────────────────

  I don't exist.

└────────────────────────────────────"""
        expected = expected.lstrip()
        toc = self.chapters[0].toc()
        section = toc[1][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        content = renderer.render()
        assert self._to_text(content) == expected
Exemplo n.º 3
0
    def test_test_block_edit_action_none(self, click_edit):
        toc = self.chapters[1].toc()
        section = toc[1][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        renderer.render()
        text = "He's the creator of something..."
        node = section.children[1]
        assert node.tagname == "TestBlock"
        assert node.text() == text

        click_edit.return_value = None

        renderer._edit_action(node)
        click_edit.assert_called_once_with(
            text=text,
            extension=".txt",
        )
        assert node.text() == text
Exemplo n.º 4
0
    def test_test_block_no_language(self):
        expected = """
Plain text

This is just plain text:

┌─ Who is Guido? ────────────────────

- [ Edit ] [ Reset ] [ Check ] (•) --

  He's the creator of something...

└────────────────────────────────────"""
        expected = expected.lstrip()
        toc = self.chapters[1].toc()
        section = toc[1][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        content = renderer.render()
        assert self._to_text(content) == expected
Exemplo n.º 5
0
    def test_code_block(self):
        expected = """
Python

This is a Python code block:

┌─ [ Copy ] ─────────────────────────

  for _ in range(3):
      print("Hello world")


└────────────────────────────────────"""
        expected = expected.lstrip()
        toc = self.chapters[0].toc()
        section = toc[0][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        content = renderer.render()
        assert self._to_text(content) == expected
Exemplo n.º 6
0
    def test_test_block(self):
        expected = """
Python

This is a Python test block:

┌─ Write a comment ──────────────────

- [ Edit ] [ Reset ] [ Check ] (•) --

  # Put your comment below


└────────────────────────────────────"""
        expected = expected.lstrip()
        toc = self.chapters[1].toc()
        section = toc[0][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        content = renderer.render()
        assert self._to_text(content) == expected
Exemplo n.º 7
0
    def test_test_block_edit_action(self, click_edit):
        toc = self.chapters[1].toc()
        section = toc[1][0]
        renderer = Renderer(tui=self.tui, section=section, width=37)
        renderer.render()
        text = "He's the creator of something..."
        new_text = "One\nTwo\nThree\n"
        node = section.children[1]
        assert node.tagname == "TestBlock"
        assert node.text() == text

        click_edit.return_value = new_text

        mouse_event = MouseEvent(Point(0, 0), MouseEventType.MOUSE_UP)
        renderer._edit_action(node, mouse_event)
        click_edit.assert_called_once_with(
            text=text,
            extension=".txt",
        )
        assert node.text() == new_text

        renderer._reset_action(node, mouse_event)
        assert node.text() == text
Exemplo n.º 8
0
 def update_section(self, section):
     renderer = Renderer(tui=self.tui, section=section)
     self.text_area.text = merge_formatted_text(renderer.render())
     self.reset(self.text_area)