import importlib.util import pathlib _PATH = pathlib.Path(__file__).resolve().parent.parent / "scripts" / "capacity-scan.py" _spec = importlib.util.spec_from_file_location("capacity_scan", _PATH) cs = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(cs) def test_parse_table_keys_on_header_and_ignores_extra_cols(): md = """ intro text | node | cores | ram_gb | disk_gb | notes | |------|-------|--------|---------|-------| | pve0 | 20 | 64 | 4000 | nvme | | pve1 | 20 | 64 | 4000 | nvme | trailing text """ rows = cs.parse_table(md, ["node", "cores", "ram_gb", "disk_gb"]) assert rows == [ {"node": "pve0", "cores": "20", "ram_gb": "64", "disk_gb": "4000", "notes": "nvme"}, {"node": "pve1", "cores": "20", "ram_gb": "64", "disk_gb": "4000", "notes": "nvme"}, ] def test_parse_table_returns_empty_when_header_absent(): assert cs.parse_table("no tables here", ["node", "cores"]) == []