-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtest_config.py
More file actions
76 lines (58 loc) · 2.24 KB
/
test_config.py
File metadata and controls
76 lines (58 loc) · 2.24 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
73
74
75
76
#!/usr/bin/env python3
import logging
import sys
import yaml
logger = logging.getLogger(__name__)
def validate_config(config_path: str = "config.yml") -> int:
"""Validate job source configuration and company totals.
Args:
config_path: Path to the YAML configuration file.
Returns:
int: Exit-style status code.
- 0 when config is valid and total companies meet threshold.
- 1 for warning threshold miss or any validation error.
"""
try:
with open(config_path, "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
apis = config["apis"]
gh = len(apis["greenhouse"]["companies"])
lever = len(apis["lever"]["companies"])
workday = len(apis.get("workday", {}).get("companies", []))
logger.info("✅ YAML loaded successfully!")
logger.info("Greenhouse: %s companies", gh)
logger.info("Lever: %s companies", lever)
logger.info("Workday: %s companies", workday)
total = gh + lever + workday
logger.info("TOTAL: %s companies", total)
min_expected = config.get("filtering", {}).get("min_expected_companies", 200)
if total < min_expected:
logger.warning(
"⚠️ WARNING: Expected ~%s companies but only loaded %s!",
f"{min_expected:,}",
total,
)
return 1
logger.info("✅ All companies loaded correctly!")
return 0
except FileNotFoundError:
logger.error("❌ Config file not found: %s", config_path)
return 1
except yaml.YAMLError as err:
logger.error("❌ Invalid YAML in %s: %s", config_path, err)
return 1
except KeyError as err:
logger.error("❌ Missing required config key: %s", err)
return 1
except TypeError as err:
logger.error("❌ Invalid config structure in %s: %s", config_path, err)
return 1
def main() -> int:
"""Run config validation using the default config path.
Returns:
int: Exit-style status code from ``validate_config``.
"""
logging.basicConfig(level=logging.INFO, format="%(message)s")
return validate_config("config.yml")
if __name__ == "__main__":
sys.exit(main())