cadis 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cadis-0.1.0/LICENSE +21 -0
- cadis-0.1.0/PKG-INFO +170 -0
- cadis-0.1.0/README.md +155 -0
- cadis-0.1.0/cadis/__init__.py +6 -0
- cadis-0.1.0/cadis/_api.py +99 -0
- cadis-0.1.0/cadis/_cache.py +27 -0
- cadis-0.1.0/cadis/_cli.py +66 -0
- cadis-0.1.0/cadis/_errors.py +38 -0
- cadis-0.1.0/cadis/_manager.py +52 -0
- cadis-0.1.0/cadis.egg-info/PKG-INFO +170 -0
- cadis-0.1.0/cadis.egg-info/SOURCES.txt +18 -0
- cadis-0.1.0/cadis.egg-info/dependency_links.txt +1 -0
- cadis-0.1.0/cadis.egg-info/entry_points.txt +2 -0
- cadis-0.1.0/cadis.egg-info/requires.txt +5 -0
- cadis-0.1.0/cadis.egg-info/top_level.txt +1 -0
- cadis-0.1.0/pyproject.toml +34 -0
- cadis-0.1.0/setup.cfg +4 -0
- cadis-0.1.0/tests/test_cadis.py +102 -0
- cadis-0.1.0/tests/test_cli.py +67 -0
- cadis-0.1.0/tests/test_errors.py +8 -0
cadis-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 isempty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
cadis-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cadis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Public facade entrypoint for Cadis global lookup
|
|
5
|
+
Author: Cadis
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cadis-global>=0.1.0
|
|
11
|
+
Requires-Dist: platformdirs>=4.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# cadis
|
|
17
|
+
|
|
18
|
+
`cadis` is the public facade entrypoint of the Cadis system.
|
|
19
|
+
|
|
20
|
+
It provides a zero-configuration global lookup interface while hiding
|
|
21
|
+
runtime, dataset, and bootstrap orchestration details.
|
|
22
|
+
|
|
23
|
+
`cadis` is **not** a runtime, dataset engine, or CDN client.
|
|
24
|
+
It is a thin facade layer built on top of `cadis-global`.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install cadis
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from cadis import lookup, info
|
|
40
|
+
|
|
41
|
+
result = lookup(25.0330, 121.5654)
|
|
42
|
+
print(result["lookup_status"])
|
|
43
|
+
|
|
44
|
+
print(info())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## CLI
|
|
50
|
+
|
|
51
|
+
`cadis` also provides a minimal CLI entrypoint:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cadis lookup <lat> <lon>
|
|
55
|
+
cadis lookup <lat> <lon> --json
|
|
56
|
+
cadis info
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cadis lookup 25.0330 121.5654
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cadis lookup 25.0330 121.5654 --json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cadis info
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
CLI mode semantics (v0.1):
|
|
74
|
+
|
|
75
|
+
* `lookup` calls the same `cadis.lookup()` API as Python mode.
|
|
76
|
+
* Default `lookup` output is human-friendly status text.
|
|
77
|
+
* `lookup --json` prints the full API envelope as JSON.
|
|
78
|
+
* `info` prints the full `cadis.info()` payload as JSON.
|
|
79
|
+
* CLI does not add bootstrap/download orchestration logic.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Public API
|
|
84
|
+
|
|
85
|
+
### `lookup(lat: float, lon: float) -> dict`
|
|
86
|
+
|
|
87
|
+
Zero-configuration lookup entrypoint.
|
|
88
|
+
|
|
89
|
+
Behavior:
|
|
90
|
+
|
|
91
|
+
* Lazy initialization on first call
|
|
92
|
+
* No network or bootstrap work at import time
|
|
93
|
+
* Deterministic response envelope
|
|
94
|
+
* Stable public error semantics
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### `info() -> dict`
|
|
99
|
+
|
|
100
|
+
Returns capability metadata for the current environment.
|
|
101
|
+
|
|
102
|
+
The output includes:
|
|
103
|
+
|
|
104
|
+
* `version`: public API version
|
|
105
|
+
* `system_iso2`: ISO2 codes available to this installation
|
|
106
|
+
* `offline_iso2`: ISO2 datasets currently available in local cache
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"schema_version": "1",
|
|
113
|
+
"version": "0.1.0",
|
|
114
|
+
"system_iso2": ["JP", "TW"],
|
|
115
|
+
"offline_iso2": ["TW"]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`info()` has no side effects and performs no network operations.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Architecture
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
cadis (facade)
|
|
127
|
+
-> cadis-global
|
|
128
|
+
-> cadis-runtime
|
|
129
|
+
-> cadis-core + cadis-cdn
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Cache Policy
|
|
135
|
+
|
|
136
|
+
Cache directory resolution order:
|
|
137
|
+
|
|
138
|
+
1. `CADIS_CACHE_DIR` environment variable
|
|
139
|
+
2. OS standard cache directory (via `platformdirs`)
|
|
140
|
+
3. Fallback path
|
|
141
|
+
|
|
142
|
+
Examples:
|
|
143
|
+
|
|
144
|
+
* macOS: `~/Library/Caches/cadis`
|
|
145
|
+
* Linux: `~/.cache/cadis`
|
|
146
|
+
* Windows: `%LOCALAPPDATA%\\cadis\\Cache`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Design Principles
|
|
151
|
+
|
|
152
|
+
* Facade-only orchestration
|
|
153
|
+
* Lazy initialization
|
|
154
|
+
* Deterministic behavior
|
|
155
|
+
* Minimal public surface
|
|
156
|
+
* Stable error contract
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Versioning
|
|
161
|
+
|
|
162
|
+
`cadis` version represents the public API contract.
|
|
163
|
+
|
|
164
|
+
It does **not** represent dataset version or internal runtime version.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
cadis-0.1.0/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# cadis
|
|
2
|
+
|
|
3
|
+
`cadis` is the public facade entrypoint of the Cadis system.
|
|
4
|
+
|
|
5
|
+
It provides a zero-configuration global lookup interface while hiding
|
|
6
|
+
runtime, dataset, and bootstrap orchestration details.
|
|
7
|
+
|
|
8
|
+
`cadis` is **not** a runtime, dataset engine, or CDN client.
|
|
9
|
+
It is a thin facade layer built on top of `cadis-global`.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install cadis
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from cadis import lookup, info
|
|
25
|
+
|
|
26
|
+
result = lookup(25.0330, 121.5654)
|
|
27
|
+
print(result["lookup_status"])
|
|
28
|
+
|
|
29
|
+
print(info())
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## CLI
|
|
35
|
+
|
|
36
|
+
`cadis` also provides a minimal CLI entrypoint:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cadis lookup <lat> <lon>
|
|
40
|
+
cadis lookup <lat> <lon> --json
|
|
41
|
+
cadis info
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cadis lookup 25.0330 121.5654
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
cadis lookup 25.0330 121.5654 --json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cadis info
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
CLI mode semantics (v0.1):
|
|
59
|
+
|
|
60
|
+
* `lookup` calls the same `cadis.lookup()` API as Python mode.
|
|
61
|
+
* Default `lookup` output is human-friendly status text.
|
|
62
|
+
* `lookup --json` prints the full API envelope as JSON.
|
|
63
|
+
* `info` prints the full `cadis.info()` payload as JSON.
|
|
64
|
+
* CLI does not add bootstrap/download orchestration logic.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Public API
|
|
69
|
+
|
|
70
|
+
### `lookup(lat: float, lon: float) -> dict`
|
|
71
|
+
|
|
72
|
+
Zero-configuration lookup entrypoint.
|
|
73
|
+
|
|
74
|
+
Behavior:
|
|
75
|
+
|
|
76
|
+
* Lazy initialization on first call
|
|
77
|
+
* No network or bootstrap work at import time
|
|
78
|
+
* Deterministic response envelope
|
|
79
|
+
* Stable public error semantics
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### `info() -> dict`
|
|
84
|
+
|
|
85
|
+
Returns capability metadata for the current environment.
|
|
86
|
+
|
|
87
|
+
The output includes:
|
|
88
|
+
|
|
89
|
+
* `version`: public API version
|
|
90
|
+
* `system_iso2`: ISO2 codes available to this installation
|
|
91
|
+
* `offline_iso2`: ISO2 datasets currently available in local cache
|
|
92
|
+
|
|
93
|
+
Example:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"schema_version": "1",
|
|
98
|
+
"version": "0.1.0",
|
|
99
|
+
"system_iso2": ["JP", "TW"],
|
|
100
|
+
"offline_iso2": ["TW"]
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`info()` has no side effects and performs no network operations.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Architecture
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
cadis (facade)
|
|
112
|
+
-> cadis-global
|
|
113
|
+
-> cadis-runtime
|
|
114
|
+
-> cadis-core + cadis-cdn
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Cache Policy
|
|
120
|
+
|
|
121
|
+
Cache directory resolution order:
|
|
122
|
+
|
|
123
|
+
1. `CADIS_CACHE_DIR` environment variable
|
|
124
|
+
2. OS standard cache directory (via `platformdirs`)
|
|
125
|
+
3. Fallback path
|
|
126
|
+
|
|
127
|
+
Examples:
|
|
128
|
+
|
|
129
|
+
* macOS: `~/Library/Caches/cadis`
|
|
130
|
+
* Linux: `~/.cache/cadis`
|
|
131
|
+
* Windows: `%LOCALAPPDATA%\\cadis\\Cache`
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Design Principles
|
|
136
|
+
|
|
137
|
+
* Facade-only orchestration
|
|
138
|
+
* Lazy initialization
|
|
139
|
+
* Deterministic behavior
|
|
140
|
+
* Minimal public surface
|
|
141
|
+
* Stable error contract
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Versioning
|
|
146
|
+
|
|
147
|
+
`cadis` version represents the public API contract.
|
|
148
|
+
|
|
149
|
+
It does **not** represent dataset version or internal runtime version.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Public API facade for cadis."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from ._cache import resolve_cache_dir
|
|
9
|
+
from ._errors import normalize_reason
|
|
10
|
+
from ._manager import get_manager
|
|
11
|
+
|
|
12
|
+
SCHEMA_VERSION = "1"
|
|
13
|
+
VERSION = "0.1.0"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _to_iso2_list(value: Any) -> list[str]:
|
|
17
|
+
if isinstance(value, (list, tuple, set)):
|
|
18
|
+
return sorted({str(v).upper() for v in value if str(v).strip()})
|
|
19
|
+
return []
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _global_info_probe() -> tuple[list[str], list[str]]:
|
|
23
|
+
"""Best-effort static info probe with no lookup/bootstrap side effects."""
|
|
24
|
+
system_iso2: list[str] = []
|
|
25
|
+
offline_iso2: list[str] = _offline_iso2_from_cache()
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
import cadis_global as module
|
|
29
|
+
except Exception:
|
|
30
|
+
return system_iso2, offline_iso2
|
|
31
|
+
|
|
32
|
+
for attr_name in ("SYSTEM_ISO2", "DEFAULT_ISO2", "SUPPORTED_ISO2"):
|
|
33
|
+
if not system_iso2 and hasattr(module, attr_name):
|
|
34
|
+
system_iso2 = _to_iso2_list(getattr(module, attr_name))
|
|
35
|
+
|
|
36
|
+
return system_iso2, offline_iso2
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _offline_iso2_from_cache() -> list[str]:
|
|
40
|
+
"""Derive cached ISO2s from local cache directory names."""
|
|
41
|
+
path = resolve_cache_dir()
|
|
42
|
+
if not path.exists() or not path.is_dir():
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
iso2: list[str] = []
|
|
46
|
+
for child in path.iterdir():
|
|
47
|
+
if child.is_dir() and re.fullmatch(r"[A-Za-z]{2}", child.name):
|
|
48
|
+
iso2.append(child.name.upper())
|
|
49
|
+
|
|
50
|
+
return sorted(set(iso2))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _failure_envelope(reason: Any) -> dict[str, Any]:
|
|
54
|
+
return {
|
|
55
|
+
"lookup_status": "failed",
|
|
56
|
+
"engine": "cadis",
|
|
57
|
+
"version": VERSION,
|
|
58
|
+
"reason": normalize_reason(reason),
|
|
59
|
+
"world_context": None,
|
|
60
|
+
"admin_result": None,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def lookup(lat: float, lon: float) -> dict[str, Any]:
|
|
65
|
+
if not isinstance(lat, (float, int)) or not isinstance(lon, (float, int)):
|
|
66
|
+
return _failure_envelope(ValueError("invalid coordinate type"))
|
|
67
|
+
if lat < -90 or lat > 90 or lon < -180 or lon > 180:
|
|
68
|
+
return _failure_envelope(ValueError("invalid coordinate range"))
|
|
69
|
+
|
|
70
|
+
manager = get_manager()
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
global_lookup = manager.get_or_init()
|
|
74
|
+
result = global_lookup.lookup(float(lat), float(lon))
|
|
75
|
+
except Exception as exc:
|
|
76
|
+
return _failure_envelope(exc)
|
|
77
|
+
|
|
78
|
+
if not isinstance(result, dict):
|
|
79
|
+
return _failure_envelope("runtime_invalid_response")
|
|
80
|
+
|
|
81
|
+
payload = dict(result)
|
|
82
|
+
payload["engine"] = "cadis"
|
|
83
|
+
payload["version"] = VERSION
|
|
84
|
+
|
|
85
|
+
reason = payload.get("reason")
|
|
86
|
+
if reason is not None:
|
|
87
|
+
payload["reason"] = normalize_reason(reason)
|
|
88
|
+
|
|
89
|
+
return payload
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def info() -> dict[str, Any]:
|
|
93
|
+
system_iso2, offline_iso2 = _global_info_probe()
|
|
94
|
+
return {
|
|
95
|
+
"schema_version": SCHEMA_VERSION,
|
|
96
|
+
"version": VERSION,
|
|
97
|
+
"system_iso2": system_iso2,
|
|
98
|
+
"offline_iso2": offline_iso2,
|
|
99
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Cache directory resolution for the cadis facade."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from platformdirs import user_cache_dir
|
|
9
|
+
|
|
10
|
+
_ENV_CACHE_DIR = "CADIS_CACHE_DIR"
|
|
11
|
+
_FALLBACK_CACHE_DIR = Path.home() / ".cache" / "cadis"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def resolve_cache_dir() -> Path:
|
|
15
|
+
"""Resolve cache path from env, OS defaults, then fallback."""
|
|
16
|
+
env_value = os.getenv(_ENV_CACHE_DIR)
|
|
17
|
+
if env_value and env_value.strip():
|
|
18
|
+
return Path(env_value).expanduser()
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
cache_dir = user_cache_dir(appname="cadis", appauthor="cadis")
|
|
22
|
+
if cache_dir:
|
|
23
|
+
return Path(cache_dir).expanduser()
|
|
24
|
+
except Exception:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
return _FALLBACK_CACHE_DIR
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Command-line interface for cadis."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
from typing import Any, Sequence
|
|
8
|
+
|
|
9
|
+
from . import info as api_info
|
|
10
|
+
from . import lookup as api_lookup
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
14
|
+
parser = argparse.ArgumentParser(prog="cadis")
|
|
15
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
16
|
+
|
|
17
|
+
lookup_parser = subparsers.add_parser("lookup")
|
|
18
|
+
lookup_parser.add_argument("lat", type=float)
|
|
19
|
+
lookup_parser.add_argument("lon", type=float)
|
|
20
|
+
lookup_parser.add_argument("--json", action="store_true", dest="as_json")
|
|
21
|
+
|
|
22
|
+
subparsers.add_parser("info")
|
|
23
|
+
return parser
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _print_json(payload: Any) -> None:
|
|
27
|
+
print(json.dumps(payload, ensure_ascii=False, indent=2))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _print_lookup_human(payload: dict[str, Any]) -> int:
|
|
31
|
+
status = payload.get("lookup_status")
|
|
32
|
+
reason = payload.get("reason")
|
|
33
|
+
|
|
34
|
+
if status == "failed":
|
|
35
|
+
message = reason if isinstance(reason, str) and reason else "unknown_error"
|
|
36
|
+
print(f"Lookup failed: {message}")
|
|
37
|
+
return 1
|
|
38
|
+
|
|
39
|
+
if status == "partial":
|
|
40
|
+
message = reason if isinstance(reason, str) and reason else "partial_result"
|
|
41
|
+
print(f"Lookup partial: {message}")
|
|
42
|
+
return 0
|
|
43
|
+
|
|
44
|
+
print("Lookup succeeded")
|
|
45
|
+
return 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
49
|
+
parser = _build_parser()
|
|
50
|
+
args = parser.parse_args(argv)
|
|
51
|
+
|
|
52
|
+
if args.command == "info":
|
|
53
|
+
_print_json(api_info())
|
|
54
|
+
return 0
|
|
55
|
+
|
|
56
|
+
payload = api_lookup(args.lat, args.lon)
|
|
57
|
+
|
|
58
|
+
if args.as_json:
|
|
59
|
+
_print_json(payload)
|
|
60
|
+
return 0
|
|
61
|
+
|
|
62
|
+
if isinstance(payload, dict):
|
|
63
|
+
return _print_lookup_human(payload)
|
|
64
|
+
|
|
65
|
+
print("Lookup failed: internal_error")
|
|
66
|
+
return 1
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Stable reason normalization for cadis public envelopes."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
KNOWN_REASONS = {
|
|
8
|
+
"unsupported_country_dataset",
|
|
9
|
+
"missing_dataset",
|
|
10
|
+
"runtime_bootstrap_error",
|
|
11
|
+
"runtime_dispatch_error",
|
|
12
|
+
"runtime_invalid_response",
|
|
13
|
+
"admin_interpretation_unavailable",
|
|
14
|
+
"world_resolution_error",
|
|
15
|
+
"invalid_input",
|
|
16
|
+
"global_lookup_unavailable",
|
|
17
|
+
"global_init_failed",
|
|
18
|
+
"lookup_failed",
|
|
19
|
+
"internal_error",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def normalize_reason(reason: Any) -> str:
|
|
24
|
+
"""Return a stable public reason code."""
|
|
25
|
+
if isinstance(reason, str) and reason in KNOWN_REASONS:
|
|
26
|
+
return reason
|
|
27
|
+
|
|
28
|
+
if isinstance(reason, ValueError):
|
|
29
|
+
return "invalid_input"
|
|
30
|
+
if isinstance(reason, ImportError):
|
|
31
|
+
return "global_lookup_unavailable"
|
|
32
|
+
if isinstance(reason, RuntimeError):
|
|
33
|
+
return "global_init_failed"
|
|
34
|
+
|
|
35
|
+
if isinstance(reason, str):
|
|
36
|
+
return "lookup_failed"
|
|
37
|
+
|
|
38
|
+
return "internal_error"
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Internal singleton manager around cadis-global."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import threading
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ._cache import resolve_cache_dir
|
|
9
|
+
from ._errors import normalize_reason
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CadisManager:
|
|
13
|
+
"""Process-level manager for a single GlobalLookup instance."""
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self._lookup = None
|
|
17
|
+
self._lock = threading.Lock()
|
|
18
|
+
|
|
19
|
+
def is_initialized(self) -> bool:
|
|
20
|
+
return self._lookup is not None
|
|
21
|
+
|
|
22
|
+
def get_or_init(self):
|
|
23
|
+
if self._lookup is not None:
|
|
24
|
+
return self._lookup
|
|
25
|
+
|
|
26
|
+
with self._lock:
|
|
27
|
+
if self._lookup is not None:
|
|
28
|
+
return self._lookup
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
from cadis_global import GlobalLookup
|
|
32
|
+
except Exception as exc: # pragma: no cover - exercised via tests with import stubs
|
|
33
|
+
raise ImportError(normalize_reason(exc)) from None
|
|
34
|
+
|
|
35
|
+
cache_dir: Path = resolve_cache_dir()
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
self._lookup = GlobalLookup.from_defaults(
|
|
39
|
+
cache_dir=cache_dir,
|
|
40
|
+
update_to_latest=False,
|
|
41
|
+
)
|
|
42
|
+
except Exception as exc:
|
|
43
|
+
raise RuntimeError(normalize_reason(exc)) from None
|
|
44
|
+
|
|
45
|
+
return self._lookup
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
_MANAGER = CadisManager()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def get_manager() -> CadisManager:
|
|
52
|
+
return _MANAGER
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cadis
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Public facade entrypoint for Cadis global lookup
|
|
5
|
+
Author: Cadis
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: cadis-global>=0.1.0
|
|
11
|
+
Requires-Dist: platformdirs>=4.0
|
|
12
|
+
Provides-Extra: dev
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# cadis
|
|
17
|
+
|
|
18
|
+
`cadis` is the public facade entrypoint of the Cadis system.
|
|
19
|
+
|
|
20
|
+
It provides a zero-configuration global lookup interface while hiding
|
|
21
|
+
runtime, dataset, and bootstrap orchestration details.
|
|
22
|
+
|
|
23
|
+
`cadis` is **not** a runtime, dataset engine, or CDN client.
|
|
24
|
+
It is a thin facade layer built on top of `cadis-global`.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install cadis
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from cadis import lookup, info
|
|
40
|
+
|
|
41
|
+
result = lookup(25.0330, 121.5654)
|
|
42
|
+
print(result["lookup_status"])
|
|
43
|
+
|
|
44
|
+
print(info())
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## CLI
|
|
50
|
+
|
|
51
|
+
`cadis` also provides a minimal CLI entrypoint:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cadis lookup <lat> <lon>
|
|
55
|
+
cadis lookup <lat> <lon> --json
|
|
56
|
+
cadis info
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
cadis lookup 25.0330 121.5654
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cadis lookup 25.0330 121.5654 --json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
cadis info
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
CLI mode semantics (v0.1):
|
|
74
|
+
|
|
75
|
+
* `lookup` calls the same `cadis.lookup()` API as Python mode.
|
|
76
|
+
* Default `lookup` output is human-friendly status text.
|
|
77
|
+
* `lookup --json` prints the full API envelope as JSON.
|
|
78
|
+
* `info` prints the full `cadis.info()` payload as JSON.
|
|
79
|
+
* CLI does not add bootstrap/download orchestration logic.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Public API
|
|
84
|
+
|
|
85
|
+
### `lookup(lat: float, lon: float) -> dict`
|
|
86
|
+
|
|
87
|
+
Zero-configuration lookup entrypoint.
|
|
88
|
+
|
|
89
|
+
Behavior:
|
|
90
|
+
|
|
91
|
+
* Lazy initialization on first call
|
|
92
|
+
* No network or bootstrap work at import time
|
|
93
|
+
* Deterministic response envelope
|
|
94
|
+
* Stable public error semantics
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### `info() -> dict`
|
|
99
|
+
|
|
100
|
+
Returns capability metadata for the current environment.
|
|
101
|
+
|
|
102
|
+
The output includes:
|
|
103
|
+
|
|
104
|
+
* `version`: public API version
|
|
105
|
+
* `system_iso2`: ISO2 codes available to this installation
|
|
106
|
+
* `offline_iso2`: ISO2 datasets currently available in local cache
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"schema_version": "1",
|
|
113
|
+
"version": "0.1.0",
|
|
114
|
+
"system_iso2": ["JP", "TW"],
|
|
115
|
+
"offline_iso2": ["TW"]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`info()` has no side effects and performs no network operations.
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Architecture
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
cadis (facade)
|
|
127
|
+
-> cadis-global
|
|
128
|
+
-> cadis-runtime
|
|
129
|
+
-> cadis-core + cadis-cdn
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Cache Policy
|
|
135
|
+
|
|
136
|
+
Cache directory resolution order:
|
|
137
|
+
|
|
138
|
+
1. `CADIS_CACHE_DIR` environment variable
|
|
139
|
+
2. OS standard cache directory (via `platformdirs`)
|
|
140
|
+
3. Fallback path
|
|
141
|
+
|
|
142
|
+
Examples:
|
|
143
|
+
|
|
144
|
+
* macOS: `~/Library/Caches/cadis`
|
|
145
|
+
* Linux: `~/.cache/cadis`
|
|
146
|
+
* Windows: `%LOCALAPPDATA%\\cadis\\Cache`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Design Principles
|
|
151
|
+
|
|
152
|
+
* Facade-only orchestration
|
|
153
|
+
* Lazy initialization
|
|
154
|
+
* Deterministic behavior
|
|
155
|
+
* Minimal public surface
|
|
156
|
+
* Stable error contract
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Versioning
|
|
161
|
+
|
|
162
|
+
`cadis` version represents the public API contract.
|
|
163
|
+
|
|
164
|
+
It does **not** represent dataset version or internal runtime version.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
cadis/__init__.py
|
|
5
|
+
cadis/_api.py
|
|
6
|
+
cadis/_cache.py
|
|
7
|
+
cadis/_cli.py
|
|
8
|
+
cadis/_errors.py
|
|
9
|
+
cadis/_manager.py
|
|
10
|
+
cadis.egg-info/PKG-INFO
|
|
11
|
+
cadis.egg-info/SOURCES.txt
|
|
12
|
+
cadis.egg-info/dependency_links.txt
|
|
13
|
+
cadis.egg-info/entry_points.txt
|
|
14
|
+
cadis.egg-info/requires.txt
|
|
15
|
+
cadis.egg-info/top_level.txt
|
|
16
|
+
tests/test_cadis.py
|
|
17
|
+
tests/test_cli.py
|
|
18
|
+
tests/test_errors.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
cadis
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cadis"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Public facade entrypoint for Cadis global lookup"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Cadis" }]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"cadis-global>=0.1.0",
|
|
15
|
+
"platformdirs>=4.0",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.optional-dependencies]
|
|
19
|
+
dev = [
|
|
20
|
+
"pytest>=8.0",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
cadis = "cadis._cli:main"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
include-package-data = true
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
include = ["cadis*"]
|
|
31
|
+
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
34
|
+
addopts = "-q"
|
cadis-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import sys
|
|
5
|
+
from types import ModuleType
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class _FakeLookup:
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
self.calls = []
|
|
11
|
+
|
|
12
|
+
def lookup(self, lat: float, lon: float):
|
|
13
|
+
self.calls.append((lat, lon))
|
|
14
|
+
return {
|
|
15
|
+
"lookup_status": "ok",
|
|
16
|
+
"reason": None,
|
|
17
|
+
"world_context": {"iso2": "TW"},
|
|
18
|
+
"admin_result": {"ok": True},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class _FakeGlobalLookup:
|
|
23
|
+
init_calls = 0
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def from_defaults(cls, **kwargs):
|
|
27
|
+
cls.init_calls += 1
|
|
28
|
+
return _FakeLookup()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _install_fake_cadis_global(module: ModuleType) -> None:
|
|
32
|
+
sys.modules["cadis_global"] = module
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _reload_cadis_modules() -> None:
|
|
36
|
+
for name in ["cadis", "cadis._api", "cadis._manager"]:
|
|
37
|
+
sys.modules.pop(name, None)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_lookup_is_lazy_singleton(monkeypatch):
|
|
41
|
+
fake_mod = ModuleType("cadis_global")
|
|
42
|
+
fake_mod.GlobalLookup = _FakeGlobalLookup
|
|
43
|
+
|
|
44
|
+
_install_fake_cadis_global(fake_mod)
|
|
45
|
+
_reload_cadis_modules()
|
|
46
|
+
|
|
47
|
+
cadis = importlib.import_module("cadis")
|
|
48
|
+
assert _FakeGlobalLookup.init_calls == 0
|
|
49
|
+
|
|
50
|
+
first = cadis.lookup(25.03, 121.56)
|
|
51
|
+
second = cadis.lookup(35.68, 139.76)
|
|
52
|
+
|
|
53
|
+
assert _FakeGlobalLookup.init_calls == 1
|
|
54
|
+
assert first["lookup_status"] == "ok"
|
|
55
|
+
assert second["lookup_status"] == "ok"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_info_has_no_lookup_side_effect(monkeypatch, tmp_path):
|
|
59
|
+
class _NoInitGlobalLookup:
|
|
60
|
+
@classmethod
|
|
61
|
+
def from_defaults(cls, **kwargs):
|
|
62
|
+
raise AssertionError("from_defaults must not be called by info()")
|
|
63
|
+
|
|
64
|
+
fake_mod = ModuleType("cadis_global")
|
|
65
|
+
fake_mod.GlobalLookup = _NoInitGlobalLookup
|
|
66
|
+
fake_mod.SUPPORTED_ISO2 = ["tw", "jp"]
|
|
67
|
+
|
|
68
|
+
cache_dir = tmp_path / "cadis-cache"
|
|
69
|
+
cache_dir.mkdir()
|
|
70
|
+
(cache_dir / "tw").mkdir()
|
|
71
|
+
(cache_dir / "not-iso").mkdir()
|
|
72
|
+
monkeypatch.setenv("CADIS_CACHE_DIR", str(cache_dir))
|
|
73
|
+
|
|
74
|
+
_install_fake_cadis_global(fake_mod)
|
|
75
|
+
_reload_cadis_modules()
|
|
76
|
+
|
|
77
|
+
cadis = importlib.import_module("cadis")
|
|
78
|
+
payload = cadis.info()
|
|
79
|
+
|
|
80
|
+
assert payload["schema_version"] == "1"
|
|
81
|
+
assert payload["system_iso2"] == ["JP", "TW"]
|
|
82
|
+
assert payload["offline_iso2"] == ["TW"]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_reason_normalization_runtime_error(monkeypatch):
|
|
86
|
+
class _BrokenGlobalLookup:
|
|
87
|
+
@classmethod
|
|
88
|
+
def from_defaults(cls, **kwargs):
|
|
89
|
+
raise Exception("boom")
|
|
90
|
+
|
|
91
|
+
fake_mod = ModuleType("cadis_global")
|
|
92
|
+
fake_mod.GlobalLookup = _BrokenGlobalLookup
|
|
93
|
+
|
|
94
|
+
_install_fake_cadis_global(fake_mod)
|
|
95
|
+
_reload_cadis_modules()
|
|
96
|
+
|
|
97
|
+
cadis = importlib.import_module("cadis")
|
|
98
|
+
payload = cadis.lookup(25.03, 121.56)
|
|
99
|
+
|
|
100
|
+
assert payload["lookup_status"] == "failed"
|
|
101
|
+
assert payload["reason"] in {"global_init_failed", "internal_error"}
|
|
102
|
+
assert "traceback" not in str(payload).lower()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from cadis import _cli
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def test_lookup_json_passthrough(monkeypatch, capsys):
|
|
9
|
+
payload = {
|
|
10
|
+
"lookup_status": "ok",
|
|
11
|
+
"engine": "cadis",
|
|
12
|
+
"version": "0.1.0",
|
|
13
|
+
"reason": None,
|
|
14
|
+
"world_context": {"iso2": "TW"},
|
|
15
|
+
"admin_result": {"name": "Xinyi District"},
|
|
16
|
+
}
|
|
17
|
+
monkeypatch.setattr(_cli, "api_lookup", lambda lat, lon: payload)
|
|
18
|
+
|
|
19
|
+
code = _cli.main(["lookup", "25.0330", "121.5654", "--json"])
|
|
20
|
+
out = capsys.readouterr().out
|
|
21
|
+
|
|
22
|
+
assert code == 0
|
|
23
|
+
assert json.loads(out) == payload
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_lookup_failed_human(monkeypatch, capsys):
|
|
27
|
+
monkeypatch.setattr(
|
|
28
|
+
_cli,
|
|
29
|
+
"api_lookup",
|
|
30
|
+
lambda lat, lon: {"lookup_status": "failed", "reason": "missing_dataset"},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
code = _cli.main(["lookup", "25.0330", "121.5654"])
|
|
34
|
+
out = capsys.readouterr().out
|
|
35
|
+
|
|
36
|
+
assert code == 1
|
|
37
|
+
assert out.strip() == "Lookup failed: missing_dataset"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_lookup_partial_human(monkeypatch, capsys):
|
|
41
|
+
monkeypatch.setattr(
|
|
42
|
+
_cli,
|
|
43
|
+
"api_lookup",
|
|
44
|
+
lambda lat, lon: {"lookup_status": "partial", "reason": "missing_dataset"},
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
code = _cli.main(["lookup", "25.0330", "121.5654"])
|
|
48
|
+
out = capsys.readouterr().out
|
|
49
|
+
|
|
50
|
+
assert code == 0
|
|
51
|
+
assert out.strip() == "Lookup partial: missing_dataset"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_info_json_passthrough(monkeypatch, capsys):
|
|
55
|
+
payload = {
|
|
56
|
+
"schema_version": "1",
|
|
57
|
+
"version": "0.1.0",
|
|
58
|
+
"system_iso2": ["JP", "TW"],
|
|
59
|
+
"offline_iso2": ["TW"],
|
|
60
|
+
}
|
|
61
|
+
monkeypatch.setattr(_cli, "api_info", lambda: payload)
|
|
62
|
+
|
|
63
|
+
code = _cli.main(["info"])
|
|
64
|
+
out = capsys.readouterr().out
|
|
65
|
+
|
|
66
|
+
assert code == 0
|
|
67
|
+
assert json.loads(out) == payload
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from cadis._errors import normalize_reason
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_normalize_reason_map():
|
|
5
|
+
assert normalize_reason("missing_dataset") == "missing_dataset"
|
|
6
|
+
assert normalize_reason(ValueError("bad")) == "invalid_input"
|
|
7
|
+
assert normalize_reason(RuntimeError("broken")) == "global_init_failed"
|
|
8
|
+
assert normalize_reason(Exception("x")) == "internal_error"
|