55"""
66
77import unittest
8- from datetime import datetime , date
8+ from datetime import datetime , date , time
99import pytz
1010
1111import pandas .api .types as ptypes
@@ -18,7 +18,14 @@ def setUp(self):
1818 """
1919 Setup the instance of class.
2020 """
21- self .api = PVLive ()
21+ self .api = PVLive (
22+ retries = 3 ,
23+ proxies = None ,
24+ ssl_verify = True ,
25+ # domain_url="api0.solar.sheffield.ac.uk",
26+ domain_url = "api.solar.sheffield.ac.uk" ,
27+ # domain_url="api.pvlive.uk"
28+ )
2229 self .expected_dtypes = {
2330 "pes_id" : ptypes .is_integer_dtype ,
2431 "gsp_id" : ptypes .is_integer_dtype ,
@@ -118,20 +125,31 @@ def test_latest(self):
118125 data = self .api .latest (entity_type = "pes" , entity_id = 0 , dataframe = True )
119126 self .check_df_columns (data )
120127 self .check_df_dtypes (data )
121- data = self .api .latest (entity_type = "pes" , entity_id = 0 ,
122- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
123- dataframe = True )
128+ data = self .api .latest (
129+ entity_type = "pes" ,
130+ entity_id = 0 ,
131+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
132+ dataframe = True
133+ )
124134 self .check_df_columns (data )
125135 self .check_df_dtypes (data )
126- data = self .api .latest (entity_type = "pes" , entity_id = 0 , period = 5 )
136+ data = self .api .latest (
137+ entity_type = "pes" ,
138+ entity_id = 0 ,
139+ period = 5
140+ )
127141 self .check_pes_tuple (data )
128142 self .check_pes_tuple_dtypes (data )
129143 data = self .api .latest (entity_type = "pes" , entity_id = 0 , period = 5 , dataframe = True )
130144 self .check_df_columns (data )
131145 self .check_df_dtypes (data )
132- data = self .api .latest (entity_type = "pes" , entity_id = 0 ,
133- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
134- period = 5 , dataframe = True )
146+ data = self .api .latest (
147+ entity_type = "pes" ,
148+ entity_id = 0 ,
149+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
150+ period = 5 ,
151+ dataframe = True
152+ )
135153 self .check_df_columns (data )
136154 self .check_df_dtypes (data )
137155 data = self .api .latest (entity_type = "gsp" , entity_id = 103 )
@@ -143,31 +161,50 @@ def test_latest(self):
143161
144162 def test_day_peak (self ):
145163 """Tests the day_peak function."""
146- data = self .api .day_peak (d = date (2023 , 12 , 1 ), entity_type = "pes" , entity_id = 0 )
164+ test_date = date (2024 , 12 , 17 )
165+ data = self .api .day_peak (d = test_date , entity_type = "pes" , entity_id = 0 )
147166 self .check_pes_tuple (data )
148167 self .check_pes_tuple_dtypes (data )
149- data = self .api .day_peak (d = date ( 2023 , 12 , 1 ) , entity_type = "pes" , entity_id = 0 , dataframe = True )
168+ data = self .api .day_peak (d = test_date , entity_type = "pes" , entity_id = 0 , dataframe = True )
150169 self .check_df_columns (data )
151170 self .check_df_dtypes (data )
152- data = self .api .day_peak (d = date (2023 , 12 , 1 ),
153- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
154- entity_type = "pes" , entity_id = 0 , dataframe = True )
155- data = self .api .day_peak (d = date (2023 , 12 , 1 ), entity_type = "pes" , entity_id = 0 , period = 5 )
171+ data = self .api .day_peak (
172+ d = test_date ,
173+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
174+ entity_type = "pes" ,
175+ entity_id = 0 ,
176+ dataframe = True
177+ )
178+ data = self .api .day_peak (d = test_date , entity_type = "pes" , entity_id = 0 , period = 5 )
156179 self .check_pes_tuple (data )
157180 self .check_pes_tuple_dtypes (data )
158- data = self .api .day_peak (d = date (2023 , 12 , 1 ), entity_type = "pes" , entity_id = 0 , period = 5 ,
159- dataframe = True )
181+ data = self .api .day_peak (
182+ d = test_date ,
183+ entity_type = "pes" ,
184+ entity_id = 0 ,
185+ period = 5 ,
186+ dataframe = True
187+ )
160188 self .check_df_columns (data )
161189 self .check_df_dtypes (data )
162- data = self .api .day_peak (d = date (2023 , 12 , 1 ),
163- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
164- entity_type = "pes" , entity_id = 0 , period = 5 , dataframe = True )
190+ data = self .api .day_peak (
191+ d = test_date ,
192+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
193+ entity_type = "pes" ,
194+ entity_id = 0 ,
195+ period = 5 ,
196+ dataframe = True
197+ )
165198 self .check_df_dtypes (data )
166- data = self .api .day_peak (d = date ( 2023 , 12 , 1 ) , entity_type = "gsp" , entity_id = 54 )
199+ data = self .api .day_peak (d = test_date , entity_type = "gsp" , entity_id = 54 )
167200 self .check_gsp_tuple (data )
168201 self .check_gsp_tuple_dtypes (data )
169- data = self .api .day_peak (d = date (2023 , 12 , 1 ), entity_type = "gsp" , entity_id = 54 ,
170- dataframe = True )
202+ data = self .api .day_peak (
203+ d = test_date ,
204+ entity_type = "gsp" ,
205+ entity_id = 54 ,
206+ dataframe = True
207+ )
171208 self .check_df_columns (data )
172209 self .check_df_dtypes (data )
173210
@@ -178,61 +215,82 @@ def test_day_energy(self):
178215
179216 def test_between (self ):
180217 """Test the between function."""
181- data = self .api .between (start = datetime (2023 , 12 , 1 , 12 , 20 , tzinfo = pytz .utc ),
182- end = datetime (2023 , 12 , 1 , 14 , 0 , tzinfo = pytz .utc ),
183- entity_type = "pes" , entity_id = 0 )
218+ test_date = date (2024 , 12 , 17 )
219+ get_test_time = lambda h , m : datetime .combine (test_date , time (h , m ))\
220+ .replace (tzinfo = pytz .UTC )
221+ data = self .api .between (
222+ start = get_test_time (12 , 20 ),
223+ end = get_test_time (14 , 0 ),
224+ entity_type = "pes" ,
225+ entity_id = 0
226+ )
184227 with self .subTest ():
185228 assert isinstance (data , list )
186- data = self .api .between (start = datetime (2023 , 12 , 1 , 12 , 20 , tzinfo = pytz .utc ),
187- end = datetime (2023 , 12 , 1 , 14 , 0 , tzinfo = pytz .utc ),
188- entity_type = "pes" , entity_id = 0 , dataframe = True )
229+ data = self .api .between (
230+ start = get_test_time (12 , 20 ),
231+ end = get_test_time (14 , 0 ),
232+ entity_type = "pes" ,
233+ entity_id = 0 ,
234+ dataframe = True
235+ )
189236 self .check_df_columns (data )
190237 self .check_df_dtypes (data )
191- data = self .api .between (start = datetime (2023 , 12 , 1 , tzinfo = pytz .utc ),
192- end = datetime (2023 , 12 , 1 , 14 , 00 , tzinfo = pytz .utc ),
193- entity_type = "pes" , entity_id = 0 , period = 5 )
238+ data = self .api .between (
239+ start = get_test_time (0 , 0 ),
240+ end = get_test_time (14 , 0 ),
241+ entity_type = "pes" ,
242+ entity_id = 0 ,
243+ period = 5
244+ )
194245 with self .subTest ():
195246 assert isinstance (data , list )
196- data = self .api .between (start = datetime (2023 , 12 , 1 , 12 , 20 , tzinfo = pytz .utc ),
197- end = datetime (2023 , 12 , 1 , 14 , 00 , tzinfo = pytz .utc ),
198- entity_type = "pes" , entity_id = 0 , period = 5 , dataframe = True )
247+ data = self .api .between (
248+ start = get_test_time (12 , 20 ),
249+ end = get_test_time (14 , 0 ),
250+ entity_type = "pes" ,
251+ entity_id = 0 ,
252+ period = 5 ,
253+ dataframe = True
254+ )
199255 self .check_df_columns (data )
200256 self .check_df_dtypes (data )
201257
202258 def test_at_time (self ):
203259 """Test the at_time function."""
204- data = self . api . at_time ( dt = datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
205- entity_id = 0 )
260+ test_time = datetime (2024 , 12 , 18 , 12 , 35 , tzinfo = pytz .utc )
261+ data = self . api . at_time ( dt = test_time , entity_type = "pes" , entity_id = 0 )
206262 self .check_pes_tuple (data )
207263 self .check_pes_tuple_dtypes (data )
208- data = self .api .at_time (datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
209- entity_id = 0 , dataframe = True )
264+ data = self .api .at_time (test_time , entity_type = "pes" , entity_id = 0 , dataframe = True )
210265 self .check_df_columns (data )
211266 self .check_df_dtypes (data )
212- data = self .api .at_time (datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
213- entity_id = 0 ,
214- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
215- dataframe = True )
267+ data = self .api .at_time (
268+ test_time ,
269+ entity_type = "pes" ,
270+ entity_id = 0 ,
271+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
272+ dataframe = True
273+ )
216274 self .check_df_dtypes (data )
217- data = self .api .at_time (dt = datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
218- entity_id = 0 , period = 5 )
275+ data = self .api .at_time (dt = test_time , entity_type = "pes" , entity_id = 0 , period = 5 )
219276 self .check_pes_tuple (data )
220277 self .check_pes_tuple_dtypes (data )
221- data = self .api .at_time (datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
222- entity_id = 0 , period = 5 , dataframe = True )
278+ data = self .api .at_time (test_time , entity_type = "pes" , entity_id = 0 , period = 5 , dataframe = True )
223279 self .check_df_columns (data )
224280 self .check_df_dtypes (data )
225- data = self .api .at_time (datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "pes" ,
226- entity_id = 0 ,
227- extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
228- period = 5 , dataframe = True )
281+ data = self .api .at_time (
282+ test_time ,
283+ entity_type = "pes" ,
284+ entity_id = 0 ,
285+ extra_fields = "ucl_mw,lcl_mw,installedcapacity_mwp,stats_error" ,
286+ period = 5 ,
287+ dataframe = True
288+ )
229289 self .check_df_dtypes (data )
230- data = self .api .at_time (dt = datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "gsp" ,
231- entity_id = 26 )
290+ data = self .api .at_time (dt = test_time , entity_type = "gsp" , entity_id = 26 )
232291 self .check_gsp_tuple (data )
233292 self .check_gsp_tuple_dtypes (data )
234- data = self .api .at_time (datetime (2023 , 12 , 1 , 12 , 35 , tzinfo = pytz .utc ), entity_type = "gsp" ,
235- entity_id = 26 , dataframe = True )
293+ data = self .api .at_time (test_time , entity_type = "gsp" , entity_id = 26 , dataframe = True )
236294 self .check_df_columns (data )
237295 self .check_df_dtypes (data )
238296
0 commit comments