@@ -36,48 +36,48 @@ def test_compute_HVAC_energy(self) -> None:
3636 # np.trapezoid on [0, ..., 0.99] with constant 10 gives 9.9.
3737 self .assertAlmostEqual (energy [0 ], 9.9 , places = 1 )
3838
39- @patch ("routee.transit.thermal_energy.fetch_counties_gdf" )
40- @patch ("routee.transit.thermal_energy.download_tmy_files" )
41- @patch ("routee.transit.thermal_energy.get_hourly_temperature" )
42- def test_add_HVAC_energy (
39+ def _make_mock_feed_and_trips (
4340 self ,
44- mock_get_hourly : MagicMock ,
45- mock_download : MagicMock ,
46- mock_fetch_counties : MagicMock ,
47- ) -> None :
48- # Setup mock Feed
41+ ) -> tuple [MagicMock , pd .DataFrame , gpd .GeoDataFrame , pd .DataFrame ]:
4942 mock_feed = MagicMock ()
5043 mock_feed .stops = pd .DataFrame (
5144 {"stop_id" : ["S1" ], "stop_lat" : [40.0 ], "stop_lon" : [- 105.0 ]}
5245 )
53- # Mock stop_times for HVAC calculation (integration needs start/end)
5446 mock_feed .stop_times = pd .DataFrame (
5547 {
5648 "trip_id" : ["T1" , "T1" ],
5749 "arrival_time" : [pd .Timedelta (hours = 8 ), pd .Timedelta (hours = 9 )],
5850 "stop_id" : ["S1" , "S1" ],
5951 }
6052 )
61-
62- # Setup mock trips
6353 trips_df = pd .DataFrame ({"trip_id" : ["T1" ]})
64-
65- # Mock dependencies
6654 mock_county_gdf = gpd .GeoDataFrame (
6755 {
68- "county_id" : ["G0800130" ], # Example FIPS
56+ "county_id" : ["G0800130" ],
6957 "STATEFP" : ["08" ],
7058 "COUNTYFP" : ["013" ],
7159 "geometry" : [Point (- 105.0 , 40.0 ).buffer (1.0 )],
7260 },
7361 crs = "EPSG:4269" ,
7462 )
75- mock_fetch_counties .return_value = mock_county_gdf
76-
77- # Mock hourly temperature and power mapping
7863 mock_hourly_temp = pd .DataFrame (
7964 {"hour" : list (range (24 )), "Dry Bulb Temperature [°C]" : [20.0 ] * 24 }
8065 )
66+ return mock_feed , trips_df , mock_county_gdf , mock_hourly_temp
67+
68+ @patch ("routee.transit.thermal_energy.fetch_counties_gdf" )
69+ @patch ("routee.transit.thermal_energy.download_tmy_files" )
70+ @patch ("routee.transit.thermal_energy.get_hourly_temperature" )
71+ def test_add_HVAC_energy (
72+ self ,
73+ mock_get_hourly : MagicMock ,
74+ mock_download : MagicMock ,
75+ mock_fetch_counties : MagicMock ,
76+ ) -> None :
77+ mock_feed , trips_df , mock_county_gdf , mock_hourly_temp = (
78+ self ._make_mock_feed_and_trips ()
79+ )
80+ mock_fetch_counties .return_value = mock_county_gdf
8181 mock_get_hourly .return_value = mock_hourly_temp
8282
8383 # use a temp directory for output
@@ -90,6 +90,29 @@ def test_add_HVAC_energy(
9090 # Should have results for 3 scenarios: summer, winter, median
9191 self .assertEqual (len (result ), 3 )
9292
93+ @patch ("routee.transit.thermal_energy.fetch_counties_gdf" )
94+ @patch ("routee.transit.thermal_energy.download_tmy_files" )
95+ @patch ("routee.transit.thermal_energy.get_hourly_temperature" )
96+ def test_add_HVAC_energy_no_output_dir (
97+ self ,
98+ mock_get_hourly : MagicMock ,
99+ mock_download : MagicMock ,
100+ mock_fetch_counties : MagicMock ,
101+ ) -> None :
102+ """add_HVAC_energy should work without output_dir using a default cache path."""
103+ mock_feed , trips_df , mock_county_gdf , mock_hourly_temp = (
104+ self ._make_mock_feed_and_trips ()
105+ )
106+ mock_fetch_counties .return_value = mock_county_gdf
107+ mock_get_hourly .return_value = mock_hourly_temp
108+
109+ # Call without specifying output_dir (previously raised an exception)
110+ result = add_HVAC_energy (mock_feed , trips_df , output_dir = None )
111+
112+ self .assertIn ("hvac_energy_kWh" , result .columns )
113+ self .assertIn ("scenario" , result .columns )
114+ self .assertEqual (len (result ), 3 )
115+
93116
94117if __name__ == "__main__" :
95118 unittest .main ()
0 commit comments