Esempio n. 1
0
    def test_text_content(self,
                          mocker,
                          prefix,
                          width,
                          count,
                          short_text,
                          caption="caption"):
        mocker.patch(STREAMBUTTON + ".mark_muted")
        show_function = mocker.Mock()

        # To test having more space available with no bullet, but using
        # same short text, reduce the effective space available
        if prefix == "":
            width -= 2

        if isinstance(prefix, tuple):
            prefix = prefix[1]  # just checking text, not color

        if prefix is None:
            top_button = TopButton(
                controller=mocker.Mock(),
                caption=caption,
                show_function=show_function,
                width=width,
                count=count,
            )
            prefix = "\N{BULLET}"
        else:
            top_button = TopButton(
                controller=mocker.Mock(),
                caption=caption,
                show_function=show_function,
                prefix_character=prefix,
                width=width,
                count=count,
            )

        text = top_button._w._original_widget.get_text()
        count_str = "" if count == 0 else str(count)
        expected_text = " {}{}{}{}".format(
            (prefix + " ") if prefix else "",
            short_text,
            (width - 2 -
             (2 if prefix else 0) - len(short_text) - len(count_str)) * " ",
            count_str,
        )
        assert len(text[0]) == len(expected_text) == (width - 1)
        assert text[0] == expected_text
Esempio n. 2
0
 def top_button(self, mocker):
     top_button = TopButton(
         controller=self.controller,
         caption="caption",
         show_function=self.show_function,
         prefix_character="-",
         count=0,
     )
     return top_button
Esempio n. 3
0
    def test_update_count(
        self,
        mocker: MockerFixture,
        top_button: TopButton,
        old_count: int,
        new_count: int,
        new_count_str: str,
        text_color: Optional[str],
    ) -> None:
        top_button.count = old_count
        top_button_update_widget = mocker.patch(MODULE +
                                                ".TopButton.update_widget")

        top_button.update_count(new_count, text_color)

        top_button_update_widget.assert_called_once_with(
            (top_button.count_style, new_count_str),
            text_color,
        )
Esempio n. 4
0
    def test_update_count(self,
                          mocker,
                          old_count,
                          new_count,
                          new_count_str,
                          width=12):
        top_button = TopButton(
            controller=mocker.Mock(),
            caption="caption",
            show_function=mocker.Mock(),
            width=width,
            count=old_count,
            count_style="starred_count",
        )
        # Avoid testing use in initialization by patching afterwards
        update_widget = mocker.patch(TOPBUTTON + ".update_widget")

        top_button.update_count(new_count)

        update_widget.assert_called_once_with(
            (top_button.count_style, new_count_str),
            None,
        )
Esempio n. 5
0
    def test_update_widget(
        self,
        mocker: MockerFixture,
        top_button: TopButton,
        prefix: str,
        expected_prefix: List[str],
        text_color: Optional[str],
        count_text: Tuple[Optional[str], str],
        expected_suffix: List[Any],
    ) -> None:
        top_button.prefix_character = prefix
        top_button.button_prefix = mocker.patch(MODULE + ".urwid.Text")
        top_button.set_label = mocker.patch(MODULE + ".urwid.Button.set_label")
        top_button.button_suffix = mocker.patch(MODULE + ".urwid.Text")
        set_attr_map = mocker.patch.object(top_button._w, "set_attr_map")

        top_button.update_widget(count_text, text_color)

        top_button.button_prefix.set_text.assert_called_once_with(
            expected_prefix)
        top_button.set_label.assert_called_once_with(top_button._caption)
        top_button.button_suffix.set_text.assert_called_once_with(
            expected_suffix)
        set_attr_map.assert_called_once_with({None: text_color})