Skip to content

Commit 096d3b5

Browse files
committed
Add tests
1 parent 86c4d4e commit 096d3b5

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def test_dev() -> None:
3535
"log_config": get_uvicorn_log_config(),
3636
}
3737
assert "Using import string: single_file_app:app" in result.output
38+
assert "Configuration sources:" in result.output
39+
assert "Module: path CLI argument" in result.output
40+
assert "App name: auto-discovery" in result.output
3841
assert "Starting development server 🚀" in result.output
3942
assert "Server started at http://127.0.0.1:8000" in result.output
4043
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
@@ -59,6 +62,8 @@ def test_dev_no_args_auto_discovery() -> None:
5962
assert mock_run.call_args.kwargs["port"] == 8000
6063
assert mock_run.call_args.kwargs["reload"] is True
6164
assert "Using import string: main:app" in result.output
65+
assert "Configuration sources:" in result.output
66+
assert "Import string: auto-discovery" in result.output
6267

6368

6469
def test_dev_package() -> None:
@@ -81,6 +86,8 @@ def test_dev_package() -> None:
8186
"log_config": get_uvicorn_log_config(),
8287
}
8388
assert "Using import string: nested_package.package:app" in result.output
89+
assert "Module: path CLI argument" in result.output
90+
assert "App name: auto-discovery" in result.output
8491
assert "Starting development server 🚀" in result.output
8592
assert "Server started at http://127.0.0.1:8000" in result.output
8693
assert "Documentation at http://127.0.0.1:8000/docs" in result.output
@@ -131,6 +138,8 @@ def test_dev_args() -> None:
131138
"log_config": get_uvicorn_log_config(),
132139
}
133140
assert "Using import string: single_file_app:api" in result.output
141+
assert "Module: path CLI argument" in result.output
142+
assert "App name: --app CLI option" in result.output
134143
assert "Starting development server 🚀" in result.output
135144
assert "Server started at http://192.168.0.2:8080" in result.output
136145
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
@@ -162,6 +171,8 @@ def test_dev_env_vars() -> None:
162171
"log_config": get_uvicorn_log_config(),
163172
}
164173
assert "Using import string: single_file_app:app" in result.output
174+
assert "Module: path CLI argument" in result.output
175+
assert "App name: auto-discovery" in result.output
165176
assert "Starting development server 🚀" in result.output
166177
assert "Server started at http://127.0.0.1:8111" in result.output
167178
assert "Documentation at http://127.0.0.1:8111/docs" in result.output
@@ -200,6 +211,8 @@ def test_dev_env_vars_and_args() -> None:
200211
"log_config": get_uvicorn_log_config(),
201212
}
202213
assert "Using import string: single_file_app:app" in result.output
214+
assert "Module: path CLI argument" in result.output
215+
assert "App name: auto-discovery" in result.output
203216
assert "Starting development server 🚀" in result.output
204217
assert "Server started at http://127.0.0.1:8080" in result.output
205218
assert "Documentation at http://127.0.0.1:8080/docs" in result.output
@@ -246,6 +259,8 @@ def test_run() -> None:
246259
"log_config": get_uvicorn_log_config(),
247260
}
248261
assert "Using import string: single_file_app:app" in result.output
262+
assert "Module: path CLI argument" in result.output
263+
assert "App name: auto-discovery" in result.output
249264
assert "Starting production server 🚀" in result.output
250265
assert "Server started at http://0.0.0.0:8000" in result.output
251266
assert "Documentation at http://0.0.0.0:8000/docs" in result.output
@@ -321,6 +336,8 @@ def test_run_args() -> None:
321336
}
322337

323338
assert "Using import string: single_file_app:api" in result.output
339+
assert "Module: path CLI argument" in result.output
340+
assert "App name: --app CLI option" in result.output
324341
assert "Starting production server 🚀" in result.output
325342
assert "Server started at http://192.168.0.2:8080" in result.output
326343
assert "Documentation at http://192.168.0.2:8080/docs" in result.output
@@ -352,6 +369,8 @@ def test_run_env_vars() -> None:
352369
"log_config": get_uvicorn_log_config(),
353370
}
354371
assert "Using import string: single_file_app:app" in result.output
372+
assert "Module: path CLI argument" in result.output
373+
assert "App name: auto-discovery" in result.output
355374
assert "Starting production server 🚀" in result.output
356375
assert "Server started at http://0.0.0.0:8111" in result.output
357376
assert "Documentation at http://0.0.0.0:8111/docs" in result.output
@@ -386,6 +405,8 @@ def test_run_env_vars_and_args() -> None:
386405
"log_config": get_uvicorn_log_config(),
387406
}
388407
assert "Using import string: single_file_app:app" in result.output
408+
assert "Module: path CLI argument" in result.output
409+
assert "App name: auto-discovery" in result.output
389410
assert "Starting production server 🚀" in result.output
390411
assert "Server started at http://0.0.0.0:8080" in result.output
391412
assert "Documentation at http://0.0.0.0:8080/docs" in result.output
@@ -498,6 +519,7 @@ def test_dev_with_import_string() -> None:
498519
"log_config": get_uvicorn_log_config(),
499520
}
500521
assert "Using import string: single_file_app:api" in result.output
522+
assert "Import string: --entrypoint CLI option" in result.output
501523

502524

503525
def test_run_with_import_string() -> None:
@@ -520,6 +542,7 @@ def test_run_with_import_string() -> None:
520542
"log_config": get_uvicorn_log_config(),
521543
}
522544
assert "Using import string: single_file_app:app" in result.output
545+
assert "Import string: --entrypoint CLI option" in result.output
523546

524547

525548
def test_script() -> None:

tests/test_cli_pyproject.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def test_dev_with_pyproject_app_config_uses() -> None:
2626
assert mock_run.call_args.kwargs["reload"] is True
2727

2828
assert "Using import string: my_module:app" in result.output
29+
assert "Configuration sources:" in result.output
30+
assert "Import string: entrypoint in pyproject.toml" in result.output
2931

3032

3133
def test_run_with_pyproject_app_config() -> None:
@@ -42,6 +44,8 @@ def test_run_with_pyproject_app_config() -> None:
4244
assert mock_run.call_args.kwargs["reload"] is False
4345

4446
assert "Using import string: my_module:app" in result.output
47+
assert "Configuration sources:" in result.output
48+
assert "Import string: entrypoint in pyproject.toml" in result.output
4549

4650

4751
def test_cli_arg_overrides_pyproject_config() -> None:
@@ -54,6 +58,9 @@ def test_cli_arg_overrides_pyproject_config() -> None:
5458
assert result.exit_code == 0, result.output
5559

5660
assert mock_run.call_args.kwargs["app"] == "another_module:app"
61+
assert "Configuration sources:" in result.output
62+
assert "Module: path CLI argument" in result.output
63+
assert "App name: auto-discovery" in result.output
5764

5865

5966
def test_pyproject_app_config_invalid_format() -> None:

0 commit comments

Comments
 (0)