Skip to content

Commit 6f70af5

Browse files
committed
test: draft of moving unit tests to canonical test directory
1 parent 34daa30 commit 6f70af5

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/test_clients.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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()

tests/test_domains.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pandas as pd
2+
from settings import api_key
3+
from entsoe import EntsoeRawClient as Entsoe
4+
5+
6+
def test_czech_unavailability_of_production_units():
7+
e = Entsoe(api_key=api_key, retry_count=20, retry_delay=30)
8+
9+
start = pd.Timestamp("20170601", tz="Europe/Brussels")
10+
end = pd.Timestamp("20170603", tz="Europe/Brussels")
11+
12+
# s = e.query_imbalance_prices(country_code='BE', start=start, end=end, as_dataframe=True)
13+
14+
"""domains = [["10YIT-GRTN-----B", "Italy, IT CA / MBA"],
15+
["10Y1001A1001A885", "Italy_Saco_AC"],
16+
["10Y1001A1001A893", "Italy_Saco_DC"],
17+
["10Y1001A1001A699", "IT-Brindisi BZ"],
18+
["10Y1001A1001A70O", "IT-Centre-North BZ"],
19+
["10Y1001A1001A71M", "IT-Centre-South BZ"],
20+
["10Y1001A1001A72K", "IT-Foggia BZ"],
21+
["10Y1001A1001A66F", "IT-GR BZ"],
22+
["10Y1001A1001A84D", "IT-MACROZONE NORTH MBA"],
23+
["10Y1001A1001A85B", "IT-MACROZONE SOUTH MBA"],
24+
["10Y1001A1001A877", "IT-Malta BZ"],
25+
["10Y1001A1001A73I", "IT-North BZ"],
26+
["10Y1001A1001A80L", "IT-North-AT BZ"],
27+
["10Y1001A1001A68B", "IT-North-CH BZ"],
28+
["10Y1001A1001A81J", "IT-North-FR BZ"],
29+
["10Y1001A1001A67D", "IT-North-SI BZ"],
30+
["10Y1001A1001A76C", "IT-Priolo BZ"],
31+
["10Y1001A1001A77A", "IT-Rossano BZ"],
32+
["10Y1001A1001A74G", "IT-Sardinia BZ"],
33+
["10Y1001A1001A75E", "IT-Sicily BZ"],
34+
["10Y1001A1001A788", "IT-South BZ"]]
35+
"""
36+
37+
domains = [["CZ", "Czech bidding zone"]]
38+
39+
lst = []
40+
for bzn in domains:
41+
s = e.query_unavailability_of_production_units(
42+
country_code=bzn[0], docstatus=None, start=start, end=end
43+
)
44+
if s is not None:
45+
lst.append(s)
46+
47+
result = pd.concat(lst)
48+
result.to_csv("result.csv")

0 commit comments

Comments
 (0)