-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✅ Add more tests for the behaviour of rich_markup_mode
#964
base: master
Are you sure you want to change the base?
Changes from all commits
a1803cf
8ed12f2
007bb35
8514d1f
4b6047d
2eae2b1
1d673f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -38,3 +41,304 @@ def main(arg: str): | |
|
||
result = runner.invoke(app, ["--help"]) | ||
assert any(c in result.stdout for c in rounded) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mode,lines", | ||
[ | ||
pytest.param( | ||
"markdown", | ||
["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
pytest.param( | ||
"rich", | ||
["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
pytest.param( | ||
"none", | ||
["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_markup_mode_newline_pr815(mode: str, lines: List[str]): | ||
app = typer.Typer(rich_markup_mode=mode) | ||
|
||
@app.command() | ||
def main(arg: str): | ||
"""First line | ||
|
||
Line 1 | ||
|
||
Line 2 | ||
|
||
Line 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", | ||
[ | ||
pytest.param( | ||
"markdown", | ||
[ | ||
"This header is just pretty long really", | ||
"", | ||
"Line 1 of a very extremely super long line", | ||
"", | ||
"And a short line 2", | ||
"", | ||
], | ||
marks=pytest.mark.xfail, | ||
), | ||
pytest.param( | ||
"rich", | ||
[ | ||
"This header is just pretty long really", | ||
"", | ||
"Line 1 of a very extremely super long line", | ||
"", | ||
"And a short line 2", | ||
"", | ||
], | ||
marks=pytest.mark.xfail, | ||
), | ||
pytest.param( | ||
"none", | ||
[ | ||
"This header is just pretty long really", | ||
"", | ||
"Line 1 of a very extremely super long line", | ||
"", | ||
"And a short line 2", | ||
"", | ||
], | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_markup_mode_newline_issue447(mode: str, lines: List[str]): | ||
svlandeg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
app = typer.Typer(rich_markup_mode=mode) | ||
|
||
@app.command() | ||
def main(arg: str): | ||
"""This header | ||
is just | ||
pretty long | ||
really | ||
|
||
Line 1 of a very | ||
extremely super long | ||
line | ||
|
||
And a short line 2 | ||
""" | ||
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 = [i for i, row in enumerate(result_lines) if "This header" in row][0] | ||
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", ""]), | ||
pytest.param( | ||
"rich", ["First line", "", "- 1 - 2 - 3", ""], marks=pytest.mark.xfail | ||
), | ||
Comment on lines
+172
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that currently on
This may mean that some users could see it as a "breaking" change once we change the code to succeed this test. |
||
pytest.param( | ||
"none", ["First line", "", "- 1 - 2 - 3", ""], marks=pytest.mark.xfail | ||
), | ||
], | ||
) | ||
def test_markup_mode_bullets_single_newline(mode: str, lines: List[str]): | ||
# Note: cf discussion at https://github.com/fastapi/typer/pull/964: we don't aim to support lists separated by a single line | ||
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", "• 3", ""]), | ||
pytest.param( | ||
"rich", | ||
["First line", "", "- 1", "", "- 2", "", "- 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
Comment on lines
+212
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one fails on |
||
pytest.param( | ||
"none", | ||
["First line", "", "- 1", "", "- 2", "", "- 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_markup_mode_bullets_double_newline(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", ""]), | ||
pytest.param( | ||
"rich", | ||
["First line", "", "- 1 - 2 - a - b - 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
Comment on lines
+257
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that currently on
This may mean that some users could see it as a "breaking" change once we change the code to succeed this test. |
||
pytest.param( | ||
"none", | ||
["First line", "", "- 1 - 2 - a - b - 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_markup_mode_nested_bullets_single_newline(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 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mode,lines", | ||
[ | ||
("markdown", ["First line", "", "• 1", "• 2", "• a", "• b", "• 3", ""]), | ||
pytest.param( | ||
"rich", | ||
["First line", "", "- 1", "", "- 2", "", "- a", "", "- b", "", "- 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
Comment on lines
+302
to
+306
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one fails on |
||
pytest.param( | ||
"none", | ||
["First line", "", "- 1", "", "- 2", "", "- a", "", "- b", "", "- 3", ""], | ||
marks=pytest.mark.xfail, | ||
), | ||
], | ||
) | ||
def test_markup_mode_nested_bullets_double_newline(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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one fails on
master
only because of a missing""
right after the header