コード例 #1
0
def test_columns_reorient(position: Literal["left", "right"]) -> None:
    """It reorients its columns based on the position argument."""
    width = 10
    yaxis = axis.YAxis(
        min_data=0,
        max_data=10,
        min_tick_margin=2,
        length=50,
        width=10,
        position=position,
    )
    ytick_column = rich.table.Column(
        header="ytick", width=1, no_wrap=True, justify="left", overflow="crop",
    )
    label_column = rich.table.Column(
        header="ytick_label",
        width=width - 1,
        no_wrap=True,
        justify="left",
        overflow="ellipsis",
    )
    expected_columns = (
        [label_column, ytick_column]
        if position == "left"
        else [ytick_column, label_column]
    )
    assert yaxis.table_columns == expected_columns
コード例 #2
0
def test_yaxis_console_render() -> None:
    """It renders a y axis."""
    width = 7
    console = rich.console.Console(file=io.StringIO(), width=width)
    console.print(
        axis.YAxis(min_data=15, max_data=150, min_tick_margin=2, width=width, length=5)
    )
    output = console.file.getvalue()  # type: ignore[attr-defined]
    assert output == "┣150.00\n┃      \n┃      \n┃      \n┣15.00 \n"
コード例 #3
0
def test_yaxis_rich_measure() -> None:
    """It's min width measures the y axis' width."""
    width = 5
    yaxis = axis.YAxis(
        min_data=15, max_data=150, min_tick_margin=2, width=width, length=30
    )
    console = rich.console.Console()
    min_width, _ = yaxis.__rich_measure__(console=console, max_width=100)
    assert min_width == width
コード例 #4
0
def test_yline_right() -> None:
    """It uses the right character when positioned on the right."""
    yaxis = axis.YAxis(
        min_data=0, max_data=5, min_tick_margin=2, length=5, width=10, position="right",
    )
    ytick = rich.text.Text("┣", style="ytick")
    yline = rich.text.Text("┃", style="yaxis")
    expected_yline = [ytick] + 3 * [yline] + [ytick]
    assert yaxis.yline() == expected_yline
コード例 #5
0
def test_yline() -> None:
    """It creates the y line."""
    yaxis = axis.YAxis(
        min_data=0, max_data=5, min_tick_margin=2, length=5, width=10, position="left",
    )
    ytick = rich.text.Text("┫", style="ytick")
    yline = rich.text.Text("┃", style="yaxis")
    expected_yline = [ytick] + 3 * [yline] + [ytick]
    assert yaxis.yline() == expected_yline
コード例 #6
0
def test_ytick_labels() -> None:
    """It creates y labels."""
    yaxis = axis.YAxis(
        min_data=0, max_data=5, min_tick_margin=2, length=5, width=10, position="left",
    )
    expected_ytick_labels = (
        [rich.text.Text("5.00", style="ytick_label", overflow="ellipsis")]
        + 3 * [rich.text.Text(" ", style="ytick_spacing", overflow="crop")]
        + [rich.text.Text("0.00", style="ytick_label", overflow="ellipsis")]
    )
    assert yaxis.ytick_labels() == expected_ytick_labels
コード例 #7
0
def test_raises_value_error_on_bad_position() -> None:
    """It raises a ValueError if the position is not valid."""
    with pytest.raises(ValueError):
        axis.YAxis(
            min_data=0,
            max_data=10,
            min_tick_margin=2,
            length=50,
            width=10,
            position="bad value",  # type: ignore[arg-type]
        )
コード例 #8
0
def test_yline_no_ticks() -> None:
    """It doesn't draw ticks when show_ticks is set to False."""
    yaxis = axis.YAxis(
        min_data=0,
        max_data=5,
        min_tick_margin=2,
        length=5,
        width=10,
        position="right",
        show_ticks=False,
    )
    assert yaxis.yline() == 5 * [rich.text.Text("┃", style="yaxis")]
コード例 #9
0
def test_raises_value_error_on_negative(
    min_tick_margin: int, width: int, length: int
) -> None:
    """It raises a ValueError when measurement values are negative."""
    with pytest.raises(ValueError):
        axis.YAxis(
            min_data=0,
            max_data=10,
            min_tick_margin=min_tick_margin,
            length=length,
            width=width,
        )
コード例 #10
0
def test_yline_characters() -> None:
    """It uses the provided characters when drawing the y line."""
    yaxis = axis.YAxis(
        min_data=0,
        max_data=5,
        min_tick_margin=2,
        length=5,
        width=10,
        position="left",
        characters={"yline": "a", "left_tick": "b"},
    )
    ytick = rich.text.Text("b", style="ytick")
    yline = rich.text.Text("a", style="yaxis")
    expected_yline = [ytick] + 3 * [yline] + [ytick]
    assert yaxis.yline() == expected_yline
コード例 #11
0
def test_ytick_labels_characters() -> None:
    """It uses the provided characters when drawing the y labels."""
    yaxis = axis.YAxis(
        min_data=0,
        max_data=5,
        min_tick_margin=2,
        length=5,
        width=10,
        position="left",
        characters={"ytick_spacing": "q"},
    )
    expected_ytick_labels = (
        [rich.text.Text("5.00", style="ytick_label", overflow="ellipsis")]
        + 3 * [rich.text.Text("q", style="ytick_spacing", overflow="crop")]
        + [rich.text.Text("0.00", style="ytick_label", overflow="ellipsis")]
    )
    assert yaxis.ytick_labels() == expected_ytick_labels
コード例 #12
0
def test_long_labels() -> None:
    """It overflows tick labels to the next line if needed."""
    yaxis = axis.YAxis(
        min_data=0,
        max_data=5,
        min_tick_margin=2,
        length=5,
        width=3,
        position="right",
        tick_labels=["zzyyxx", "aabbccddee"],
    )
    expected_ylabels = [
        rich.text.Text("aa", style="ytick_label", overflow="ellipsis"),
        rich.text.Text("bb", style="ytick_label", overflow="ellipsis"),
        rich.text.Text("cc", style="ytick_label", overflow="ellipsis"),
        rich.text.Text("ddee", style="ytick_label", overflow="ellipsis"),
        rich.text.Text("zzyyxx", style="ytick_label", overflow="ellipsis"),
    ]
    assert yaxis.ytick_labels() == expected_ylabels