forked from EnergieID/entsoe-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
111 lines (95 loc) · 4.03 KB
/
tests.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import unittest
import pandas as pd
from bs4 import BeautifulSoup
from entsoe import EntsoeRawClient, EntsoePandasClient
from entsoe.exceptions import NoMatchingDataError
from settings import api_key
class EntsoeRawClientTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.client = EntsoeRawClient(api_key=api_key)
cls.start = pd.Timestamp('20180101', tz='Europe/Brussels')
cls.end = pd.Timestamp('20180107', tz='Europe/Brussels')
cls.country_code = 'BE'
def test_datetime_to_str(self):
start_str = self.client._datetime_to_str(dtm=self.start)
self.assertIsInstance(start_str, str)
self.assertEqual(start_str, '201712312300')
def test_basic_queries(self):
queries = [
self.client.query_day_ahead_prices,
self.client.query_load,
self.client.query_wind_and_solar_forecast,
self.client.query_load_forecast,
self.client.query_generation,
self.client.query_generation_forecast,
self.client.query_installed_generation_capacity,
self.client.query_imbalance_prices
]
for query in queries:
text = query(country_code=self.country_code, start=self.start,
end=self.end)
self.assertIsInstance(text, str)
try:
BeautifulSoup(text, 'html.parser')
except Exception as e:
self.fail(f'Parsing of response failed with exception: {e}')
def query_crossborder_flows(self):
text = self.client.query_crossborder_flows(
country_code_from='BE', country_code_to='NL', start=self.start,
end=self.end)
self.assertIsInstance(text, str)
try:
BeautifulSoup(text, 'html.parser')
except Exception as e:
self.fail(f'Parsing of response failed with exception: {e}')
def test_query_unavailability_of_generation_units(self):
text = self.client.query_unavailability_of_generation_units(
country_code='BE', start=self.start,
end=self.end)
self.assertIsInstance(text, bytes)
def test_query_withdrawn_unavailability_of_generation_units(self):
with self.assertRaises(NoMatchingDataError):
self.client.query_withdrawn_unavailability_of_generation_units(
country_code='BE', start=self.start, end=self.end)
class EntsoePandasClientTest(EntsoeRawClientTest):
@classmethod
def setUpClass(cls):
cls.client = EntsoePandasClient(api_key=api_key)
cls.start = pd.Timestamp('20180101', tz='Europe/Brussels')
cls.end = pd.Timestamp('20180107', tz='Europe/Brussels')
cls.country_code = 'BE'
def test_basic_queries(self):
pass
def test_basic_series(self):
queries = [
self.client.query_day_ahead_prices,
self.client.query_load,
self.client.query_load_forecast,
self.client.query_generation_forecast
]
for query in queries:
ts = query(country_code=self.country_code, start=self.start,
end=self.end)
self.assertIsInstance(ts, pd.Series)
def query_crossborder_flows(self):
ts = self.client.query_crossborder_flows(
country_code_from='BE', country_code_to='NL', start=self.start,
end=self.end)
self.assertIsInstance(ts, pd.Series)
def test_basic_dataframes(self):
queries = [
self.client.query_wind_and_solar_forecast,
self.client.query_generation,
self.client.query_installed_generation_capacity,
self.client.query_imbalance_prices,
self.client.query_unavailability_of_generation_units,
]
for query in queries:
ts = query(country_code=self.country_code, start=self.start,
end=self.end)
self.assertIsInstance(ts, pd.DataFrame)
def test_query_unavailability_of_generation_units(self):
pass
if __name__ == '__main__':
unittest.main()