-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime_context.py
More file actions
59 lines (49 loc) · 2.32 KB
/
Copy pathtest_runtime_context.py
File metadata and controls
59 lines (49 loc) · 2.32 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
import json
import tempfile
import unittest
from pathlib import Path
from runtime_context import build_runtime_context, build_workspace_lookup, load_link_catalog
class RuntimeContextTests(unittest.TestCase):
def test_workspace_lookup_groups_records(self):
lookup = build_workspace_lookup([
{"workspace_code": "energy-systems", "variable": "A"},
{"workspace_code": "energy-systems", "variable": "B"},
{"workspace_code": "buildings-transf", "variable": "C"},
{"variable": "D"},
])
self.assertEqual(len(lookup["energy-systems"]), 2)
self.assertEqual(len(lookup["buildings-transf"]), 1)
self.assertEqual(len(lookup["unknown"]), 1)
def test_load_link_catalog_returns_empty_for_missing_file(self):
self.assertEqual(load_link_catalog(Path("missing-link-catalog.json")), [])
def test_build_runtime_context_exposes_dict_like_resources(self):
with tempfile.TemporaryDirectory() as temp_dir:
temp_path = Path(temp_dir)
link_catalog_path = temp_path / "links.json"
metadata_cache = temp_path / "metadata.pkl"
link_catalog_path.write_text(json.dumps([{"title": "IAM PARIS Results"}]))
context = build_runtime_context(
models=[{"modelName": "GCAM"}],
ts=[
{
"workspace_code": "energy-systems",
"variable": "Emissions|CO2",
"region": "World",
"scenario": "Baseline",
"modelName": "GCAM",
"unit": "Mt CO2/yr",
}
],
vector_store="vector-store",
env={"OPENAI_API_KEY": "test"},
bot="bot",
link_catalog_path=link_catalog_path,
metadata_cache_file=str(metadata_cache),
)
self.assertEqual(context["models"][0]["modelName"], "GCAM")
self.assertEqual(context.get("vector_store"), "vector-store")
self.assertEqual(context.link_catalog[0]["title"], "IAM PARIS Results")
self.assertIn("energy-systems", context.workspace_lookup)
self.assertIn("GCAM", context.metadata.all_model_names)
if __name__ == "__main__":
unittest.main()