Beispiel #1
0
    def render(self, style: Optional[Style] = None) -> str:
        """ Renders the rows. """

        style = style or Style()

        layout = self.calculate_layout(style)
        rendered = ""

        for row in self.rows:
            rendered += row.render(layout, style) + "\n"

        return rendered.rstrip()
Beispiel #2
0
    def render(
        self,
        layout: Optional[Layout] = None,
        style: Optional[Style] = None,
    ) -> str:
        """ Renders the row. """

        style = style or Style()
        layout = layout or Layout()

        name, name_len = self.render_name(
            color=style.color,
            suffix=style.name_suffix,
            length=layout.name_length,
        )

        if style.show_fraction:
            fraction, fraction_len = self.render_fraction(
                color=style.color,
                prefix=style.fraction_prefix,
                separator=style.fraction_separator,
                left_length=layout.left_fraction_length,
                right_length=layout.right_fraction_length,
            )
        else:
            fraction = ""
            fraction_len = 0

        if style.show_percent:
            percent, percent_len = self.render_percent(
                color=style.color,
                prefix=style.percent_prefix,
                length=layout.percent_length,
            )
        else:
            percent = ""
            percent_len = 0

        bar = self.render_bar(
            color=style.color,
            length=style.width - name_len - fraction_len - percent_len,
        )

        return (name + bar + fraction + percent).rstrip()
Beispiel #3
0
def test_width__forced() -> None:
    assert Style(width=7).width == 7
Beispiel #4
0
def test_init__color_empty() -> None:
    assert Style().color
Beispiel #5
0
def test_percent_prefix(show_fraction: bool, expect: str) -> None:
    assert Style(show_fraction=show_fraction).percent_prefix == expect
Beispiel #6
0
def test_fraction_separator() -> None:
    assert Style().fraction_separator == " / "
Beispiel #7
0
def test_fraction_prefix() -> None:
    assert Style().fraction_prefix == " "
Beispiel #8
0
def test_init__show_percent_set() -> None:
    assert Style(show_percent=True).show_percent
Beispiel #9
0
def test_init__show_fraction_set() -> None:
    assert Style(show_fraction=True).show_fraction
Beispiel #10
0
def test_init__show_fraction_empty() -> None:
    assert not Style().show_fraction
Beispiel #11
0
def test_init__name_suffix_set() -> None:
    assert Style(name_suffix="x").name_suffix == "x"
Beispiel #12
0
def test_init__name_suffix_empty() -> None:
    assert Style().name_suffix == " "
Beispiel #13
0
from progrow.style import Style

fraction_part_test_cases = [
    (0, False, None, ("0", 1)),
    (1, False, None, ("1", 1)),
    (1.2, False, None, ("1.2", 3)),
    (-3.4, False, None, ("-3.4", 4)),
]


@mark.parametrize(
    "row, style, layout, expect",
    [
        (
            Row(name="foo", maximum=9, current=1),
            Style(color=False, width=40),
            Layout(),
            "foo ████",
        ),
        (
            Row(name="foo", maximum=9, current=1),
            Style(color=False, show_fraction=True, width=40),
            Layout(),
            "foo ███▍                           1 / 9",
        ),
        (
            Row(name="foo", maximum=9, current=1),
            Style(color=False, show_percent=True, width=40),
            Layout(),
            "foo ███▌                             11%",
        ),
Beispiel #14
0
def test_append() -> None:
    rows = Rows([Row(name="foo", current=1, maximum=9)])
    rows.append(name="bar", current=2, maximum=9)
    style = Style(color=False, width=40)
    assert rows.render(style) == "foo ████\nbar ███████▉"
Beispiel #15
0
def test_append() -> None:
    rows = Rows([Row(name="foo", current=1, maximum=9)])
    rows.append(name="bar", current=2, maximum=9)
    style = Style(color=False, width=40)
    assert rows.render(style) == "foo ████\nbar ███████▉"


@mark.parametrize(
    "rows, style, expect",
    [
        (
            Rows([
                Row(name="red", current=1, maximum=9),
            ]),
            Style(width=40, name_suffix=""),
            Layout(name_length=3),
        ),
        (
            Rows([
                Row(name="red", current=1, maximum=9),
            ]),
            Style(width=40, name_suffix="x"),
            Layout(name_length=4),
        ),
        (
            Rows([
                Row(name="red", current=1, maximum=9),
            ]),
            Style(width=40, name_suffix="", show_fraction=True),
            Layout(name_length=3,
Beispiel #16
0
def test_width__auto() -> None:
    assert Style().width > 0
Beispiel #17
0
def test_init__color_set() -> None:
    assert not Style(color=False).color
Beispiel #18
0
def test_init__show_percent_empty() -> None:
    assert not Style().show_percent