1
+ import unittest
2
+
3
+ import pandas as pd
4
+ from bs4 import BeautifulSoup
5
+
6
+ from entsoe import EntsoeRawClient , EntsoePandasClient
7
+ from entsoe .exceptions import NoMatchingDataError
8
+ from settings import api_key
9
+
10
+
11
+ class EntsoeRawClientTest (unittest .TestCase ):
12
+ @classmethod
13
+ def setUpClass (cls ):
14
+ cls .client = EntsoeRawClient (api_key = api_key )
15
+ cls .start = pd .Timestamp ('20180101' , tz = 'Europe/Brussels' )
16
+ cls .end = pd .Timestamp ('20180107' , tz = 'Europe/Brussels' )
17
+ cls .country_code = 'BE'
18
+
19
+ def test_datetime_to_str (self ):
20
+ start_str = self .client ._datetime_to_str (dtm = self .start )
21
+ self .assertIsInstance (start_str , str )
22
+ self .assertEqual (start_str , '201712312300' )
23
+
24
+ def test_basic_queries (self ):
25
+ queries = [
26
+ self .client .query_day_ahead_prices ,
27
+ self .client .query_load ,
28
+ self .client .query_wind_and_solar_forecast ,
29
+ self .client .query_load_forecast ,
30
+ self .client .query_generation ,
31
+ self .client .query_generation_forecast ,
32
+ self .client .query_installed_generation_capacity ,
33
+ self .client .query_imbalance_prices
34
+ ]
35
+ for query in queries :
36
+ text = query (country_code = self .country_code , start = self .start ,
37
+ end = self .end )
38
+ self .assertIsInstance (text , str )
39
+ try :
40
+ BeautifulSoup (text , 'html.parser' )
41
+ except Exception as e :
42
+ self .fail (f'Parsing of response failed with exception: { e } ' )
43
+
44
+ def query_crossborder_flows (self ):
45
+ text = self .client .query_crossborder_flows (
46
+ country_code_from = 'BE' , country_code_to = 'NL' , start = self .start ,
47
+ end = self .end )
48
+ self .assertIsInstance (text , str )
49
+ try :
50
+ BeautifulSoup (text , 'html.parser' )
51
+ except Exception as e :
52
+ self .fail (f'Parsing of response failed with exception: { e } ' )
53
+
54
+ def test_query_unavailability_of_generation_units (self ):
55
+ text = self .client .query_unavailability_of_generation_units (
56
+ country_code = 'BE' , start = self .start ,
57
+ end = self .end )
58
+ self .assertIsInstance (text , bytes )
59
+
60
+ def test_query_withdrawn_unavailability_of_generation_units (self ):
61
+ with self .assertRaises (NoMatchingDataError ):
62
+ self .client .query_withdrawn_unavailability_of_generation_units (
63
+ country_code = 'BE' , start = self .start , end = self .end )
64
+
65
+
66
+ class EntsoePandasClientTest (EntsoeRawClientTest ):
67
+ @classmethod
68
+ def setUpClass (cls ):
69
+ cls .client = EntsoePandasClient (api_key = api_key )
70
+ cls .start = pd .Timestamp ('20180101' , tz = 'Europe/Brussels' )
71
+ cls .end = pd .Timestamp ('20180107' , tz = 'Europe/Brussels' )
72
+ cls .country_code = 'BE'
73
+
74
+ def test_basic_queries (self ):
75
+ pass
76
+
77
+ def test_basic_series (self ):
78
+ queries = [
79
+ self .client .query_day_ahead_prices ,
80
+ self .client .query_load ,
81
+ self .client .query_load_forecast ,
82
+ self .client .query_generation_forecast
83
+ ]
84
+ for query in queries :
85
+ ts = query (country_code = self .country_code , start = self .start ,
86
+ end = self .end )
87
+ self .assertIsInstance (ts , pd .Series )
88
+
89
+ def query_crossborder_flows (self ):
90
+ ts = self .client .query_crossborder_flows (
91
+ country_code_from = 'BE' , country_code_to = 'NL' , start = self .start ,
92
+ end = self .end )
93
+ self .assertIsInstance (ts , pd .Series )
94
+
95
+ def test_basic_dataframes (self ):
96
+ queries = [
97
+ self .client .query_wind_and_solar_forecast ,
98
+ self .client .query_generation ,
99
+ self .client .query_installed_generation_capacity ,
100
+ self .client .query_imbalance_prices ,
101
+ self .client .query_unavailability_of_generation_units ,
102
+ ]
103
+ for query in queries :
104
+ ts = query (country_code = self .country_code , start = self .start ,
105
+ end = self .end )
106
+ self .assertIsInstance (ts , pd .DataFrame )
107
+
108
+ def test_query_unavailability_of_generation_units (self ):
109
+ pass
110
+
111
+
112
+ if __name__ == '__main__' :
113
+ unittest .main ()
0 commit comments