1+ import polars as pl
12import pytest
3+ from polars .testing import assert_frame_equal
24
35from npa_howtopay .params import (
46 ScenarioParams ,
@@ -26,6 +28,75 @@ def web_params():
2628 }
2729
2830
31+ @pytest .fixture
32+ def expected_gas_bau_lpp_costs_no_inflation ():
33+ """Expected gas BAU LPP costs for 2025-2030 with no inflation"""
34+ return pl .DataFrame ({
35+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
36+ "cost" : [100.0 , 100.0 , 100.0 , 100.0 , 100.0 , 100.0 ],
37+ })
38+
39+
40+ @pytest .fixture
41+ def expected_gas_fixed_overhead_costs_no_inflation ():
42+ """Expected gas fixed overhead costs for 2025-2030 with no inflation"""
43+ return pl .DataFrame ({
44+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
45+ "cost" : [100.0 , 100.0 , 100.0 , 100.0 , 100.0 , 100.0 ],
46+ })
47+
48+
49+ @pytest .fixture
50+ def expected_electric_fixed_overhead_costs_no_inflation ():
51+ """Expected electric fixed overhead costs for 2025-2030 with no inflation"""
52+ return pl .DataFrame ({
53+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
54+ "cost" : [100.0 , 100.0 , 100.0 , 100.0 , 100.0 , 100.0 ],
55+ })
56+
57+
58+ @pytest .fixture
59+ def expected_gas_bau_lpp_costs_with_inflation ():
60+ """Expected gas BAU LPP costs for 2025-2030 with 5% inflation"""
61+ return pl .DataFrame ({
62+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
63+ "cost" : [100.0 , 105.0 , 110.25 , 115.7625 , 121.550625 , 127.62815625 ],
64+ })
65+
66+
67+ @pytest .fixture
68+ def expected_gas_fixed_overhead_costs_with_inflation ():
69+ """Expected gas fixed overhead costs for 2025-2030 with 5% inflation"""
70+ return pl .DataFrame ({
71+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
72+ "cost" : [100.0 , 105.0 , 110.25 , 115.7625 , 121.550625 , 127.62815625 ],
73+ })
74+
75+
76+ @pytest .fixture
77+ def expected_electric_fixed_overhead_costs_with_inflation ():
78+ """Expected electric fixed overhead costs for 2025-2030 with 5% inflation"""
79+ return pl .DataFrame ({
80+ "year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
81+ "cost" : [100.0 , 105.0 , 110.25 , 115.7625 , 121.550625 , 127.62815625 ],
82+ })
83+
84+
85+ @pytest .fixture
86+ def expected_npa_projects ():
87+ """Expected NPA projects for 2025-2030"""
88+ return pl .DataFrame ({
89+ "project_year" : [2025 , 2026 , 2027 , 2028 , 2029 , 2030 ],
90+ "num_converts" : [100 , 100 , 100 , 100 , 100 , 100 ],
91+ "pipe_value_per_user" : [1000.0 , 1000.0 , 1000.0 , 1000.0 , 1000.0 , 1000.0 ],
92+ "pipe_decomm_cost_per_user" : [100.0 , 100.0 , 100.0 , 100.0 , 100.0 , 100.0 ],
93+ "peak_kw_winter_headroom" : [10.0 , 10.0 , 10.0 , 10.0 , 10.0 , 10.0 ],
94+ "peak_kw_summer_headroom" : [10.0 , 10.0 , 10.0 , 10.0 , 10.0 , 10.0 ],
95+ "aircon_percent_adoption_pre_npa" : [0.8 , 0.8 , 0.8 , 0.8 , 0.8 , 0.8 ],
96+ "is_scattershot" : [False , False , False , False , False , False ],
97+ })
98+
99+
29100def test_load_sample_yaml ():
30101 """Test loading the sample.yaml file"""
31102 # Load the sample scenario
@@ -34,36 +105,54 @@ def test_load_sample_yaml():
34105 assert params is not None
35106
36107
37- def test_load_web_params (web_params ):
38- """Test loading the web params"""
39- params = load_time_series_params_from_web_params (web_params , 2025 , 2050 )
40- # Verify params has expected structure
108+ def test_load_web_params_no_inflation (
109+ web_params ,
110+ expected_gas_bau_lpp_costs_no_inflation ,
111+ expected_gas_fixed_overhead_costs_no_inflation ,
112+ expected_electric_fixed_overhead_costs_no_inflation ,
113+ expected_npa_projects ,
114+ ):
115+ """Test loading the web params without inflation"""
116+ params = load_time_series_params_from_web_params (web_params , 2025 , 2030 )
117+
118+ # Verify params is not None
41119 assert params is not None
42120
43- # Verify gas_bau_lpp_costs df has correct shape and columns
44- assert params .gas_bau_lpp_costs_per_year .shape == (26 , 2 )
45- assert set (params .gas_bau_lpp_costs_per_year .columns ) == {"year" , "cost" }
121+ # Test each DataFrame against expected values
122+ assert params .gas_bau_lpp_costs_per_year .equals (expected_gas_bau_lpp_costs_no_inflation )
123+ assert params .gas_fixed_overhead_costs .equals (expected_gas_fixed_overhead_costs_no_inflation )
124+ assert params .electric_fixed_overhead_costs .equals (expected_electric_fixed_overhead_costs_no_inflation )
125+ assert params .npa_projects .equals (expected_npa_projects )
46126
47- # Verify gas_fixed_overhead_costs df has correct shape and columns
48- assert params .gas_fixed_overhead_costs .shape == (26 , 2 )
49- assert set (params .gas_fixed_overhead_costs .columns ) == {"year" , "cost" }
50127
51- # Verify electric_fixed_overhead_costs df has correct shape and columns
52- assert params .electric_fixed_overhead_costs .shape == (26 , 2 )
53- assert set (params .electric_fixed_overhead_costs .columns ) == {"year" , "cost" }
128+ def test_load_web_params_with_inflation (
129+ web_params ,
130+ expected_gas_bau_lpp_costs_with_inflation ,
131+ expected_gas_fixed_overhead_costs_with_inflation ,
132+ expected_electric_fixed_overhead_costs_with_inflation ,
133+ expected_npa_projects ,
134+ ):
135+ """Test loading the web params with 5% inflation"""
136+ params = load_time_series_params_from_web_params (web_params , 2025 , 2030 , cost_inflation_rate = 0.05 )
54137
55- # Verify npa_projects df has correct shape and columns
56- assert params .npa_projects .shape == (26 , 8 )
57- assert set (params .npa_projects .columns ) == {
58- "project_year" ,
59- "num_converts" ,
60- "pipe_value_per_user" ,
61- "pipe_decomm_cost_per_user" ,
62- "peak_kw_winter_headroom" ,
63- "peak_kw_summer_headroom" ,
64- "aircon_percent_adoption_pre_npa" ,
65- "is_scattershot" ,
66- }
138+ # Verify params is not None
139+ assert params is not None
140+
141+ # Test each DataFrame against expected values with proper float tolerance
142+ assert_frame_equal (
143+ params .gas_bau_lpp_costs_per_year , expected_gas_bau_lpp_costs_with_inflation , check_exact = False , atol = 1e-10
144+ )
145+ assert_frame_equal (
146+ params .gas_fixed_overhead_costs , expected_gas_fixed_overhead_costs_with_inflation , check_exact = False , atol = 1e-10
147+ )
148+ assert_frame_equal (
149+ params .electric_fixed_overhead_costs ,
150+ expected_electric_fixed_overhead_costs_with_inflation ,
151+ check_exact = False ,
152+ atol = 1e-10 ,
153+ )
154+ # NPA projects should match exactly (no floats)
155+ assert params .npa_projects .equals (expected_npa_projects )
67156
68157
69158def test_load_time_series_params_from_yaml ():
0 commit comments