Coverage for tests/test_discover.py: 100%
41 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-11 09:18 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-11 09:18 +0000
1from pathlib import Path 1abcdefghijklmn
3import pytest 1abcdefghijklmn
5from fastapi_cli.discover import ( 1abcdefghijklmn
6 ImportData,
7 get_import_data_from_import_string,
8)
9from fastapi_cli.exceptions import FastAPICLIException 1abcdefghijklmn
11assets_path = Path(__file__).parent / "assets" 1abcdefghijklmn
14def test_get_import_data_from_import_string_valid() -> None: 1abcdefghijklmn
15 result = get_import_data_from_import_string("module.submodule:app", False) 1opqrstuvwxyzAB
17 assert isinstance(result, ImportData) 1opqrstuvwxyzAB
18 assert result.app_name == "app" 1opqrstuvwxyzAB
19 assert result.import_string == "module.submodule:app" 1opqrstuvwxyzAB
20 assert result.module_data.module_import_str == "module.submodule" 1opqrstuvwxyzAB
21 assert result.module_data.extra_sys_path == Path(".").resolve() 1opqrstuvwxyzAB
22 assert result.module_data.module_paths == [] 1opqrstuvwxyzAB
23 assert result.module_config_source == "entrypoint-option" 1opqrstuvwxyzAB
24 assert result.app_name_config_source == "entrypoint-option" 1opqrstuvwxyzAB
27def test_get_import_data_from_import_string_pyproject_valid() -> None: 1abcdefghijklmn
28 result = get_import_data_from_import_string("module.submodule:app", True) 1CDEFGHIJKLMNOP
30 assert isinstance(result, ImportData) 1CDEFGHIJKLMNOP
31 assert result.app_name == "app" 1CDEFGHIJKLMNOP
32 assert result.import_string == "module.submodule:app" 1CDEFGHIJKLMNOP
33 assert result.module_data.module_import_str == "module.submodule" 1CDEFGHIJKLMNOP
34 assert result.module_data.extra_sys_path == Path(".").resolve() 1CDEFGHIJKLMNOP
35 assert result.module_data.module_paths == [] 1CDEFGHIJKLMNOP
36 assert result.module_config_source == "entrypoint-pyproject" 1CDEFGHIJKLMNOP
37 assert result.app_name_config_source == "entrypoint-pyproject" 1CDEFGHIJKLMNOP
40def test_get_import_data_from_import_string_missing_colon() -> None: 1abcdefghijklmn
41 with pytest.raises(FastAPICLIException) as exc_info: 1QRSTUVWXYZ0123
42 get_import_data_from_import_string("module.submodule", False) 1QRSTUVWXYZ0123
44 assert "Import string must be in the format module.submodule:app_name" in str( 1QRSTUVWXYZ0123
45 exc_info.value
46 )
49def test_get_import_data_from_import_string_missing_app() -> None: 1abcdefghijklmn
50 with pytest.raises(FastAPICLIException) as exc_info: 1456789!#$%'()*
51 get_import_data_from_import_string("module.submodule:", False) 1456789!#$%'()*
53 assert "Import string must be in the format module.submodule:app_name" in str( 1456789!#$%'()*
54 exc_info.value
55 )
58def test_get_import_data_from_import_string_missing_module() -> None: 1abcdefghijklmn
59 with pytest.raises(FastAPICLIException) as exc_info: 1+,-./:;=?@[]^_
60 get_import_data_from_import_string(":app", False) 1+,-./:;=?@[]^_
62 assert "Import string must be in the format module.submodule:app_name" in str( 1+,-./:;=?@[]^_
63 exc_info.value
64 )
67def test_get_import_data_from_import_string_empty() -> None: 1abcdefghijklmn
68 with pytest.raises(FastAPICLIException) as exc_info: 2` { | } ~ abbbcbdbebfbgbhbib
69 get_import_data_from_import_string("", False) 2` { | } ~ abbbcbdbebfbgbhbib
70 assert "Import string must be in the format module.submodule:app_name" in str( 2` { | } ~ abbbcbdbebfbgbhbib
71 exc_info.value
72 )