Skip to content

Commit bf2c972

Browse files
committed
Improve coverage
1 parent 44e471f commit bf2c972

File tree

9 files changed

+111
-0
lines changed

9 files changed

+111
-0
lines changed

tests/assets/nested_package/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .mod.api import api as api
2+
from .mod.app import app as app

tests/assets/nested_package/package/core/__init__.py

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def get_hello_world() -> str:
2+
return "Hello World"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .app import app as app
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from fastapi import FastAPI
2+
3+
first_other = FastAPI()
4+
5+
6+
@first_other.get("/")
7+
def first_other_root():
8+
return {"message": "package first_other"}
9+
10+
11+
second_other = FastAPI()
12+
13+
14+
@second_other.get("/")
15+
def second_other_root():
16+
return {"message": "package second_other"}
17+
18+
19+
api = FastAPI()
20+
21+
22+
@api.get("/")
23+
def api_root():
24+
return {"message": "package api"}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from fastapi import FastAPI
2+
3+
first_other = FastAPI()
4+
5+
6+
@first_other.get("/")
7+
def first_other_root():
8+
return {"message": "package first_other"}
9+
10+
11+
second_other = FastAPI()
12+
13+
14+
@second_other.get("/")
15+
def second_other_root():
16+
return {"message": "package second_other"}
17+
18+
19+
api = FastAPI()
20+
21+
22+
@api.get("/")
23+
def api_root():
24+
return {"message": "package api"}
25+
26+
27+
app = FastAPI()
28+
29+
30+
@app.get("/")
31+
def app_root():
32+
return {"message": "package app"}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from fastapi import FastAPI
2+
3+
first_other = FastAPI()
4+
5+
6+
@first_other.get("/")
7+
def first_other_root():
8+
return {"message": "package first_other"}
9+
10+
11+
second_other = FastAPI()
12+
13+
14+
@second_other.get("/")
15+
def second_other_root():
16+
return {"message": "package second_other"}

tests/test_cli.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,40 @@ def test_dev() -> None:
4141
in result.output
4242
)
4343

44+
assert "🐍 single_file_app.py" in result.output
45+
46+
47+
def test_dev_package() -> None:
48+
with changing_dir(assets_path):
49+
with patch.object(uvicorn, "run") as mock_run:
50+
result = runner.invoke(app, ["dev", "nested_package/package"])
51+
assert result.exit_code == 0, result.output
52+
assert mock_run.called
53+
assert mock_run.call_args
54+
assert mock_run.call_args.kwargs == {
55+
"app": "nested_package.package:app",
56+
"host": "127.0.0.1",
57+
"port": 8000,
58+
"reload": True,
59+
"workers": None,
60+
"root_path": "",
61+
"proxy_headers": True,
62+
"log_config": get_uvicorn_log_config(),
63+
}
64+
assert "Using import string: nested_package.package:app" in result.output
65+
assert "Starting development server 🚀" in result.output
66+
assert "Server started at https://127.0.0.1:8000" in result.output
67+
assert "Documentation at https://127.0.0.1:8000/docs" in result.output
68+
assert (
69+
"Running in development mode, for production use: fastapi run"
70+
in result.output
71+
)
72+
73+
assert "📁 package" in result.output
74+
assert "└── 🐍 __init__.py" in result.output
75+
assert "└── 📁 package" in result.output
76+
assert " └── 🐍 __init__.py" in result.output
77+
4478

4579
def test_dev_args() -> None:
4680
with changing_dir(assets_path):

0 commit comments

Comments
 (0)