Beispiel #1
0
def test_xtick_labels() -> None:
    """It creates the x tick labels."""
    xaxis = axis.XAxis(
        min_data=0,
        max_data=10,
        tick_padding=3,
        min_tick_margin=1,
        width=24,
        tick_values=None,
        tick_labels=None,
        characters={"xtick_spacing": "_"},
    )
    actual_xtick_lables = xaxis.xtick_labels()
    expected_xtick_labels = [
        rich.text.Text("", style="xtick_spacing", overflow="crop"),
        rich.text.Text(
            "0.00", style="xtick_label", overflow="ellipsis", justify="center"
        ),
        rich.text.Text("_", style="xtick_spacing", overflow="crop"),
        rich.text.Text(
            "5.00", style="xtick_label", overflow="ellipsis", justify="center"
        ),
        rich.text.Text("_", style="xtick_spacing", overflow="crop"),
        rich.text.Text(
            "10.00", style="xtick_label", overflow="ellipsis", justify="center"
        ),
        rich.text.Text("_", style="xtick_spacing", overflow="crop"),
    ]
    assert actual_xtick_lables == expected_xtick_labels
Beispiel #2
0
def test_xaxis_rich_measure() -> None:
    """It's min width measures the axis' width."""
    width = 80
    xaxis = axis.XAxis(
        min_data=15, max_data=150, tick_padding=3, min_tick_margin=2, width=width
    )
    console = rich.console.Console()
    min_width, _ = xaxis.__rich_measure__(console=console, max_width=100)
    assert min_width == width
Beispiel #3
0
def test_tick_creation_hypothesis(
    min_data: int, max_data: int, tick_padding: int, min_tick_margin: int, width: int
) -> None:
    """It creates at at least one tick given any valid data."""
    hypothesis.assume(min_data <= max_data)
    hypothesis.assume((2 * tick_padding) < width)
    xaxis = axis.XAxis(
        min_data=min_data,
        max_data=max_data,
        tick_padding=tick_padding,
        min_tick_margin=min_tick_margin,
        width=width,
    )
    assert 1 <= xaxis.number_of_xticks
Beispiel #4
0
def test_axis_width_hypothesis(
    min_data: int, max_data: int, tick_padding: int, min_tick_margin: int, width: int
) -> None:
    """The width of the table created matches the available width."""
    hypothesis.assume(min_data <= max_data)
    hypothesis.assume((2 * tick_padding) < width)
    xaxis = axis.XAxis(
        min_data=min_data,
        max_data=max_data,
        tick_padding=tick_padding,
        min_tick_margin=min_tick_margin,
        width=width,
    )
    table_width = sum(column.width for column in xaxis.table_columns)
    assert table_width == width
Beispiel #5
0
def test_xaxis_console_render() -> None:
    """It renders an x axis."""
    width = 80
    console = rich.console.Console(file=io.StringIO(), width=width)
    console.print(
        axis.XAxis(
            min_data=15, max_data=150, tick_padding=3, min_tick_margin=2, width=width
        )
    )
    output = console.file.getvalue()  # type: ignore[attr-defined]
    assert output == (
        " ━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━"
        "━━━━━┳━━━━━━━━┳━━━\n  0.00     20.00    40.00    60.00"
        "    80.00   100.00   120.00   140.00   160.00 \n"
    )
Beispiel #6
0
def test_xline(characters: Dict[str, str], show_ticks: bool) -> None:
    """It creates the x line."""
    xaxis = axis.XAxis(
        min_data=0,
        max_data=10,
        tick_padding=3,
        min_tick_margin=1,
        width=24,
        tick_values=None,
        tick_labels=None,
        characters=characters,
        show_ticks=show_ticks,
    )
    actual_xline = xaxis.xline()
    tick_padding = rich.text.Text(
        characters["xline"] * 3, style="xaxis", overflow="crop"
    )
    xtick_section = rich.text.Text.assemble(
        tick_padding,
        rich.text.Text(
            characters["xtick"] if show_ticks else characters["xline"],
            style="xtick_label",
            overflow="crop",
        ),
        tick_padding,
    )
    margin_section = rich.text.Text(characters["xline"], style="xaxis", overflow="crop")
    expected_xline = [
        rich.text.Text("", style="xaxis", overflow="crop"),
        xtick_section,
        margin_section,
        xtick_section,
        margin_section,
        xtick_section,
        rich.text.Text(characters["xline"], style="xaxis", overflow="crop"),
    ]
    assert actual_xline == expected_xline
Beispiel #7
0
def test_fallback_ticks() -> None:
    """It will fallback to a simple algorithm when the range is low."""
    xaxis = axis.XAxis(
        min_data=0, max_data=6, tick_padding=0, min_tick_margin=0, width=2
    )
    assert xaxis.tick_values == [0.0, 6.0]
Beispiel #8
0
def test_raises_padding_too_big() -> None:
    """It raises a ValueError when the tick padding is too large."""
    with pytest.raises(ValueError):
        axis.XAxis(
            min_data=0, max_data=10, tick_padding=3_000, min_tick_margin=2, width=4
        )
Beispiel #9
0
def test_no_axis_subtractor() -> None:
    """It returns no label if there is nothing to subtract."""
    xaxis = axis.XAxis(
        min_data=0, max_data=1, tick_padding=0, min_tick_margin=0, width=101
    )
    assert xaxis.axis_subtractor_label is None
Beispiel #10
0
def test_negative_measurements() -> None:
    """It raises a ValueError if measurements are negative."""
    with pytest.raises(ValueError):
        axis.XAxis(
            min_data=10, max_data=4, tick_padding=3, min_tick_margin=1, width=-10
        )
Beispiel #11
0
def test_min_larger_max_xaxis() -> None:
    """It raises a ValueError is min_data is larger than max_data."""
    with pytest.raises(ValueError):
        axis.XAxis(min_data=10, max_data=4, tick_padding=3, min_tick_margin=1, width=10)