예제 #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()
예제 #2
0
파일: row.py 프로젝트: cariad/progrow
    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()
예제 #3
0
def test_width__forced() -> None:
    assert Style(width=7).width == 7
예제 #4
0
def test_init__color_empty() -> None:
    assert Style().color
예제 #5
0
def test_percent_prefix(show_fraction: bool, expect: str) -> None:
    assert Style(show_fraction=show_fraction).percent_prefix == expect
예제 #6
0
def test_fraction_separator() -> None:
    assert Style().fraction_separator == " / "
예제 #7
0
def test_fraction_prefix() -> None:
    assert Style().fraction_prefix == " "
예제 #8
0
def test_init__show_percent_set() -> None:
    assert Style(show_percent=True).show_percent
예제 #9
0
def test_init__show_fraction_set() -> None:
    assert Style(show_fraction=True).show_fraction
예제 #10
0
def test_init__show_fraction_empty() -> None:
    assert not Style().show_fraction
예제 #11
0
def test_init__name_suffix_set() -> None:
    assert Style(name_suffix="x").name_suffix == "x"
예제 #12
0
def test_init__name_suffix_empty() -> None:
    assert Style().name_suffix == " "
예제 #13
0
파일: test_row.py 프로젝트: cariad/progrow
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%",
        ),
예제 #14
0
파일: test_rows.py 프로젝트: cariad/progrow
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 ███████▉"
예제 #15
0
파일: test_rows.py 프로젝트: cariad/progrow
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,
예제 #16
0
def test_width__auto() -> None:
    assert Style().width > 0
예제 #17
0
def test_init__color_set() -> None:
    assert not Style(color=False).color
예제 #18
0
def test_init__show_percent_empty() -> None:
    assert not Style().show_percent