-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathtest_utils_default_dir.py
91 lines (77 loc) · 3.95 KB
/
test_utils_default_dir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from pathlib import Path
import pytest
from fastapi_cli.discover import get_import_string
from fastapi_cli.exceptions import FastAPICLIException
from pytest import CaptureFixture
from .utils import changing_dir
assets_path = Path(__file__).parent / "assets"
def test_app_dir_main(capsys: CaptureFixture[str]) -> None:
with changing_dir(assets_path / "default_files" / "default_app_dir_main"):
import_string, is_factory = get_import_string()
assert import_string == "app.main:app"
assert is_factory is False
captured = capsys.readouterr()
assert "Using path app/main.py" in captured.out
assert "Resolved absolute path" in captured.out
assert (
"/tests/assets/default_files/default_app_dir_main/app/main.py" in captured.out
)
assert "Importing from" in captured.out
assert "tests/assets/default_files/default_app_dir_main" in captured.out
assert "╭─ Python package file structure ─╮" in captured.out
assert "│ 📁 app" in captured.out
assert "│ ├── 🐍 __init__.py" in captured.out
assert "│ └── 🐍 main.py" in captured.out
assert "Importing module app.main" in captured.out
assert "Found importable FastAPI app" in captured.out
assert "Importable FastAPI app" in captured.out
assert "from app.main import app" in captured.out
assert "Using import string app.main:app" in captured.out
def test_app_dir_app(capsys: CaptureFixture[str]) -> None:
with changing_dir(assets_path / "default_files" / "default_app_dir_app"):
import_string, is_factory = get_import_string()
assert import_string == "app.app:app"
assert is_factory is False
captured = capsys.readouterr()
assert "Using path app/app.py" in captured.out
assert "Resolved absolute path" in captured.out
assert "/tests/assets/default_files/default_app_dir_app/app/app.py" in captured.out
assert "Importing from" in captured.out
assert "tests/assets/default_files/default_app_dir_app" in captured.out
assert "╭─ Python package file structure ─╮" in captured.out
assert "│ 📁 app" in captured.out
assert "│ ├── 🐍 __init__.py" in captured.out
assert "│ └── 🐍 app.py" in captured.out
assert "Importing module app.app" in captured.out
assert "Found importable FastAPI app" in captured.out
assert "Importable FastAPI app" in captured.out
assert "from app.app import app" in captured.out
assert "Using import string app.app:app" in captured.out
def test_app_dir_api(capsys: CaptureFixture[str]) -> None:
with changing_dir(assets_path / "default_files" / "default_app_dir_api"):
import_string, is_factory = get_import_string()
assert import_string == "app.api:app"
assert is_factory is False
captured = capsys.readouterr()
assert "Using path app/api.py" in captured.out
assert "Resolved absolute path" in captured.out
assert "/tests/assets/default_files/default_app_dir_api/app/api.py" in captured.out
assert "Importing from" in captured.out
assert "tests/assets/default_files/default_app_dir_api" in captured.out
assert "╭─ Python package file structure ─╮" in captured.out
assert "│ 📁 app" in captured.out
assert "│ ├── 🐍 __init__.py" in captured.out
assert "│ └── 🐍 api.py" in captured.out
assert "Importing module app.api" in captured.out
assert "Found importable FastAPI app" in captured.out
assert "Importable FastAPI app" in captured.out
assert "from app.api import app" in captured.out
assert "Using import string app.api:app" in captured.out
def test_app_dir_non_default() -> None:
with changing_dir(assets_path / "default_files" / "default_app_dir_non_default"):
with pytest.raises(FastAPICLIException) as e:
get_import_string()
assert (
"Could not find a default file to run, please provide an explicit path"
in e.value.args[0]
)