Exemple #1
0
def test_size_properties():
    console = Console(width=80, height=25)
    assert console.size == ConsoleDimensions(80, 25)
    console.size = (10, 20)
    assert console.size == ConsoleDimensions(10, 20)
    console.width = 5
    assert console.size == ConsoleDimensions(5, 20)
    console.height = 10
    assert console.size == ConsoleDimensions(5, 10)
Exemple #2
0
def test_config_list_lists_all_options(size) -> None:
    size.return_value = ConsoleDimensions(1000, 1000)

    result = CliRunner().invoke(lean, ["config", "list"])

    assert result.exit_code == 0

    for option in container.cli_config_manager().all_options:
        assert option.key in result.output
        assert option.description in result.output
Exemple #3
0
def test_rich_console(live_render):
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    rich_console = live_render.__rich_console__(Console(), options)
    assert [Segment("my string", Style.parse("none"))] == list(rich_console)
    live_render.style = "red"
    rich_console = live_render.__rich_console__(Console(), options)
    assert [Segment("my string", Style.parse("red"))] == list(rich_console)
Exemple #4
0
def test_config_list_does_not_show_complete_values_of_sensitive_options(
        size) -> None:
    container.cli_config_manager().user_id.set_value("123")
    container.cli_config_manager().api_token.set_value(
        "abcdefghijklmnopqrstuvwxyz")

    size.return_value = ConsoleDimensions(1000, 1000)

    result = CliRunner().invoke(lean, ["config", "list"])

    assert result.exit_code == 0

    assert "123" not in result.output
    assert "abcdefghijklmnopqrstuvwxyz" not in result.output
Exemple #5
0
def test_console_options_update_height():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        max_height=25,
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    assert options.height is None
    render_options = options.update_height(12)
    assert options.height is None
    assert render_options.height == 12
    assert render_options.max_height == 12
Exemple #6
0
def test_box_substitute():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        legacy_windows=True,
        min_width=1,
        max_width=100,
        is_terminal=True,
        encoding="utf-8",
    )
    assert HEAVY.substitute(options) == SQUARE

    options.legacy_windows = False
    assert HEAVY.substitute(options) == HEAVY

    options.encoding = "ascii"
    assert HEAVY.substitute(options) == ASCII
Exemple #7
0
def test_console_options_update():
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )
    options1 = options.update(width=15)
    assert options1.min_width == 15 and options1.max_width == 15

    options2 = options.update(min_width=5, max_width=15, justify="right")
    assert (options2.min_width == 5 and options2.max_width == 15
            and options2.justify == "right")

    options_copy = options.update()
    assert options_copy == options and options_copy is not options
Exemple #8
0
def test_rich_console():
    renderable = "test renderable"
    style = Style(color="red")
    options = ConsoleOptions(
        ConsoleDimensions(80, 25),
        legacy_windows=False,
        min_width=10,
        max_width=20,
        is_terminal=False,
        encoding="utf-8",
    )

    expected_outputs = [
        Segment(renderable, style=style),
        Segment(" " * (20 - len(renderable)), style=style),
        Segment("\n", style=None),
    ]
    padding_generator = Padding(renderable, style=style).__rich_console__(
        Console(), options)
    for output, expected in zip(padding_generator, expected_outputs):
        assert output == expected