Skip to content

Commit

Permalink
Fix default values
Browse files Browse the repository at this point in the history
  • Loading branch information
svlandeg committed Sep 11, 2024
1 parent b77a29f commit 8312bb8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs_src/parameter_types/enum/tutorial004.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LogLevel(enum.Enum):
warning = logging.WARNING


def main(log_level: LogLevel = typer.Option(LogLevel.warning, enum_by_name=True)):
def main(log_level: LogLevel = typer.Option("warning", enum_by_name=True)):
typer.echo(f"Log level set to: {logging.getLevelName(log_level.value)}")


Expand Down
2 changes: 1 addition & 1 deletion docs_src/parameter_types/enum/tutorial005.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Access(enum.IntEnum):
open = 4


def main(access: Access = typer.Option(Access.private, enum_by_name=True)):
def main(access: Access = typer.Option("private", enum_by_name=True)):
typer.echo(f"Access level: {access.name} ({access.value})")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
app.command()(mod.main)


def test_enum_names_default():
result = runner.invoke(app)
assert result.exit_code == 0
assert "Log level set to: WARNING" in result.output


def test_enum_names():
result = runner.invoke(app, ["--log-level", "debug"])
assert result.exit_code == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
app.command()(mod.main)


def test_int_enum_default():
result = runner.invoke(app)
assert result.exit_code == 0
assert "Access level: private (1)" in result.output


def test_int_enum():
result = runner.invoke(app, ["--access", "open"])
assert result.exit_code == 0
assert "Access level: open" in result.output
assert "Access level: open (4)" in result.output


def test_script():
Expand Down

0 comments on commit 8312bb8

Please sign in to comment.