Skip to content

Commit

Permalink
unit tests to capture current behaviour of this PR (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Aug 28, 2024
1 parent 7414b8f commit 46f0f82
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List

import pytest
import typer
import typer.completion
from typer.testing import CliRunner
Expand Down Expand Up @@ -38,3 +41,67 @@ def main(arg: str):

result = runner.invoke(app, ["--help"])
assert any(c in result.stdout for c in rounded)


@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "Line 1", "", "Line 2", ""]),
("rich", ["First line", "", "Line 1", "", "Line 2", ""]),
("none", ["First line", "", "Line 1", "Line 2", ""]),
],
)
def test_markup_mode_newline_pr815(mode: str, lines: List[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
def main():
"""First line
Line 1
Line 2
"""
pass

assert app.rich_markup_mode == mode

result = runner.invoke(app, ["--help"])
result_lines = [line.strip() for line in result.stdout.split("\n")]
assert any(c in result.stdout for c in rounded)
help_start = result_lines.index("First line")
options_start = [i for i, row in enumerate(result_lines) if "Options" in row][0]
assert help_start != -1
assert result_lines[help_start:options_start] == lines


@pytest.mark.parametrize(
"mode,lines",
[
("markdown", ["First line", "", "Line 1 Line 2 Line 3", ""]),
("rich", ["First line", "", "Line 1", "Line 2", "Line 3", ""]),
("none", ["First line", "", "Line 1 Line 2 Line 3", ""]),
],
)
def test_markup_mode_newline_issue447(mode: str, lines: List[str]):
app = typer.Typer(rich_markup_mode=mode)

@app.command()
def main():
"""First line
Line 1
Line 2
Line 3
"""
pass

assert app.rich_markup_mode == mode

result = runner.invoke(app, ["--help"])
result_lines = [line.strip() for line in result.stdout.split("\n")]
assert any(c in result.stdout for c in rounded)
help_start = result_lines.index("First line")
options_start = [i for i, row in enumerate(result_lines) if "Options" in row][0]
assert help_start != -1
assert result_lines[help_start:options_start] == lines

0 comments on commit 46f0f82

Please sign in to comment.