Skip to content

Commit

Permalink
unit tests from #449 capturing current behaviour of this PR (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Aug 29, 2024
1 parent 0b7c06e commit 8dd3b5b
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/test_rich_markup_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,75 @@ def main(arg: str):
arg_start = [i for i, row in enumerate(result_lines) if "Arguments" in row][0]
assert help_start != -1
assert result_lines[help_start:arg_start] == lines


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

@app.command()
def main(arg: str):
"""First line
- 1
- 2
- 3
"""
print(f"Hello {arg}")

assert app.rich_markup_mode == mode

result = runner.invoke(app, ["World"])
assert "Hello World" in result.stdout

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")
arg_start = [i for i, row in enumerate(result_lines) if "Arguments" in row][0]
assert help_start != -1
assert result_lines[help_start:arg_start] == lines


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

@app.command()
def main(arg: str):
"""First line
- 1
- 2
- a
- b
- 3
"""
print(f"Hello {arg}")

assert app.rich_markup_mode == mode

result = runner.invoke(app, ["World"])
assert "Hello World" in result.stdout

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")
arg_start = [i for i, row in enumerate(result_lines) if "Arguments" in row][0]
assert help_start != -1
assert result_lines[help_start:arg_start] == lines

0 comments on commit 8dd3b5b

Please sign in to comment.