-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtest_discover.py
More file actions
72 lines (52 loc) · 2.58 KB
/
test_discover.py
File metadata and controls
72 lines (52 loc) · 2.58 KB
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
from pathlib import Path
import pytest
from fastapi_cli.discover import (
ImportData,
get_import_data_from_import_string,
)
from fastapi_cli.exceptions import FastAPICLIException
assets_path = Path(__file__).parent / "assets"
def test_get_import_data_from_import_string_valid() -> None:
result = get_import_data_from_import_string("module.submodule:app", False)
assert isinstance(result, ImportData)
assert result.app_name == "app"
assert result.import_string == "module.submodule:app"
assert result.module_data.module_import_str == "module.submodule"
assert result.module_data.extra_sys_path == Path(".").resolve()
assert result.module_data.module_paths == []
assert result.module_config_source == "entrypoint-option"
assert result.app_name_config_source == "entrypoint-option"
def test_get_import_data_from_import_string_pyproject_valid() -> None:
result = get_import_data_from_import_string("module.submodule:app", True)
assert isinstance(result, ImportData)
assert result.app_name == "app"
assert result.import_string == "module.submodule:app"
assert result.module_data.module_import_str == "module.submodule"
assert result.module_data.extra_sys_path == Path(".").resolve()
assert result.module_data.module_paths == []
assert result.module_config_source == "entrypoint-pyproject"
assert result.app_name_config_source == "entrypoint-pyproject"
def test_get_import_data_from_import_string_missing_colon() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("module.submodule", False)
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_missing_app() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("module.submodule:", False)
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_missing_module() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string(":app", False)
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)
def test_get_import_data_from_import_string_empty() -> None:
with pytest.raises(FastAPICLIException) as exc_info:
get_import_data_from_import_string("", False)
assert "Import string must be in the format module.submodule:app_name" in str(
exc_info.value
)