pygazpar 1.3.0a14__py38-none-any.whl → 1.3.0a24__py38-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pygazpar/datasource.py +528 -522
- pygazpar/excelparser.py +138 -136
- pygazpar/version.py +1 -1
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/METADATA +12 -4
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/RECORD +11 -11
- tests/test_client.py +159 -159
- tests/test_datasource.py +166 -166
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/LICENSE.md +0 -0
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/WHEEL +0 -0
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/entry_points.txt +0 -0
- {pygazpar-1.3.0a14.dist-info → pygazpar-1.3.0a24.dist-info}/top_level.txt +0 -0
tests/test_client.py
CHANGED
@@ -1,159 +1,159 @@
|
|
1
|
-
from pygazpar.enum import Frequency
|
2
|
-
from pygazpar.client import Client
|
3
|
-
from pygazpar.datasource import JsonWebDataSource, TestDataSource, ExcelWebDataSource
|
4
|
-
import os
|
5
|
-
import pytest
|
6
|
-
|
7
|
-
|
8
|
-
class TestClient:
|
9
|
-
|
10
|
-
@classmethod
|
11
|
-
def setup_class(cls):
|
12
|
-
""" setup any state specific to the execution of the given class (which
|
13
|
-
usually contains tests).
|
14
|
-
"""
|
15
|
-
|
16
|
-
@classmethod
|
17
|
-
def teardown_class(cls):
|
18
|
-
""" teardown any state that was previously setup with a call to
|
19
|
-
setup_class.
|
20
|
-
"""
|
21
|
-
|
22
|
-
def setup_method(self):
|
23
|
-
""" setup any state tied to the execution of the given method in a
|
24
|
-
class. setup_method is invoked for every test method of a class.
|
25
|
-
"""
|
26
|
-
tmpdir = os.path.normpath(f"{os.getcwd()}/tmp")
|
27
|
-
|
28
|
-
# We create the tmp directory if not already exists.
|
29
|
-
if not os.path.exists(tmpdir):
|
30
|
-
os.mkdir(tmpdir)
|
31
|
-
|
32
|
-
self.__username = os.environ["GRDF_USERNAME"]
|
33
|
-
self.__password = os.environ["GRDF_PASSWORD"]
|
34
|
-
self.__pceIdentifier = os.environ["PCE_IDENTIFIER"]
|
35
|
-
self.__tmp_directory = tmpdir
|
36
|
-
|
37
|
-
def teardown_method(self):
|
38
|
-
""" teardown any state that was previously setup with a setup_method
|
39
|
-
call.
|
40
|
-
"""
|
41
|
-
|
42
|
-
def test_login_error(self):
|
43
|
-
client = Client(JsonWebDataSource("WrongUsername", "WrongPassword"))
|
44
|
-
|
45
|
-
with pytest.raises(Exception):
|
46
|
-
client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
47
|
-
|
48
|
-
def test_hourly_live(self):
|
49
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
50
|
-
|
51
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.HOURLY])
|
52
|
-
|
53
|
-
assert (len(data[Frequency.HOURLY.value]) == 0)
|
54
|
-
|
55
|
-
def test_one_day_jsonweb(self):
|
56
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
57
|
-
|
58
|
-
data = client.loadSince(self.__pceIdentifier, 1, [Frequency.DAILY])
|
59
|
-
|
60
|
-
assert (len(data[Frequency.DAILY.value]) <= 1)
|
61
|
-
|
62
|
-
def test_two_days_jsonweb(self):
|
63
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
64
|
-
|
65
|
-
data = client.loadSince(self.__pceIdentifier, 2, [Frequency.DAILY])
|
66
|
-
|
67
|
-
assert (len(data[Frequency.DAILY.value]) <= 2)
|
68
|
-
|
69
|
-
# @pytest.mark.skip(reason="Requires live data")
|
70
|
-
def test_daily_jsonweb(self):
|
71
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
72
|
-
|
73
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
74
|
-
|
75
|
-
assert (len(data[Frequency.DAILY.value]) > 0)
|
76
|
-
|
77
|
-
def test_weekly_jsonweb(self):
|
78
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
79
|
-
|
80
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
81
|
-
|
82
|
-
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
83
|
-
|
84
|
-
def test_monthly_jsonweb(self):
|
85
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
86
|
-
|
87
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
88
|
-
|
89
|
-
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)
|
90
|
-
|
91
|
-
def test_yearly_jsonweb(self):
|
92
|
-
client = Client(JsonWebDataSource(self.__username, self.__password))
|
93
|
-
|
94
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
95
|
-
|
96
|
-
assert (len(data[Frequency.YEARLY.value])
|
97
|
-
|
98
|
-
def test_daily_excelweb(self):
|
99
|
-
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
100
|
-
|
101
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
102
|
-
|
103
|
-
assert (len(data[Frequency.DAILY.value]) > 0)
|
104
|
-
|
105
|
-
def test_weekly_excelweb(self):
|
106
|
-
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
107
|
-
|
108
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
109
|
-
|
110
|
-
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
111
|
-
|
112
|
-
def test_monthly_excelweb(self):
|
113
|
-
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
114
|
-
|
115
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
116
|
-
|
117
|
-
assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
|
118
|
-
|
119
|
-
def test_yearly_excelweb(self):
|
120
|
-
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
121
|
-
|
122
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
123
|
-
|
124
|
-
assert (len(data[Frequency.YEARLY.value])
|
125
|
-
|
126
|
-
def test_hourly_sample(self):
|
127
|
-
client = Client(TestDataSource())
|
128
|
-
|
129
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.HOURLY])
|
130
|
-
|
131
|
-
assert (len(data[Frequency.HOURLY.value]) == 0)
|
132
|
-
|
133
|
-
def test_daily_sample(self):
|
134
|
-
client = Client(TestDataSource())
|
135
|
-
|
136
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
137
|
-
|
138
|
-
assert (len(data[Frequency.DAILY.value]) == 711)
|
139
|
-
|
140
|
-
def test_weekly_sample(self):
|
141
|
-
client = Client(TestDataSource())
|
142
|
-
|
143
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
144
|
-
|
145
|
-
assert (len(data[Frequency.WEEKLY.value]) > 0)
|
146
|
-
|
147
|
-
def test_monthly_sample(self):
|
148
|
-
client = Client(TestDataSource())
|
149
|
-
|
150
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
151
|
-
|
152
|
-
assert (len(data[Frequency.MONTHLY.value]) > 0)
|
153
|
-
|
154
|
-
def test_yearly_sample(self):
|
155
|
-
client = Client(TestDataSource())
|
156
|
-
|
157
|
-
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
158
|
-
|
159
|
-
assert (len(data[Frequency.YEARLY.value]) == 2)
|
1
|
+
from pygazpar.enum import Frequency
|
2
|
+
from pygazpar.client import Client
|
3
|
+
from pygazpar.datasource import JsonWebDataSource, TestDataSource, ExcelWebDataSource
|
4
|
+
import os
|
5
|
+
import pytest
|
6
|
+
|
7
|
+
|
8
|
+
class TestClient:
|
9
|
+
|
10
|
+
@classmethod
|
11
|
+
def setup_class(cls):
|
12
|
+
""" setup any state specific to the execution of the given class (which
|
13
|
+
usually contains tests).
|
14
|
+
"""
|
15
|
+
|
16
|
+
@classmethod
|
17
|
+
def teardown_class(cls):
|
18
|
+
""" teardown any state that was previously setup with a call to
|
19
|
+
setup_class.
|
20
|
+
"""
|
21
|
+
|
22
|
+
def setup_method(self):
|
23
|
+
""" setup any state tied to the execution of the given method in a
|
24
|
+
class. setup_method is invoked for every test method of a class.
|
25
|
+
"""
|
26
|
+
tmpdir = os.path.normpath(f"{os.getcwd()}/tmp")
|
27
|
+
|
28
|
+
# We create the tmp directory if not already exists.
|
29
|
+
if not os.path.exists(tmpdir):
|
30
|
+
os.mkdir(tmpdir)
|
31
|
+
|
32
|
+
self.__username = os.environ["GRDF_USERNAME"]
|
33
|
+
self.__password = os.environ["GRDF_PASSWORD"]
|
34
|
+
self.__pceIdentifier = os.environ["PCE_IDENTIFIER"]
|
35
|
+
self.__tmp_directory = tmpdir
|
36
|
+
|
37
|
+
def teardown_method(self):
|
38
|
+
""" teardown any state that was previously setup with a setup_method
|
39
|
+
call.
|
40
|
+
"""
|
41
|
+
|
42
|
+
def test_login_error(self):
|
43
|
+
client = Client(JsonWebDataSource("WrongUsername", "WrongPassword"))
|
44
|
+
|
45
|
+
with pytest.raises(Exception):
|
46
|
+
client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
47
|
+
|
48
|
+
def test_hourly_live(self):
|
49
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
50
|
+
|
51
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.HOURLY])
|
52
|
+
|
53
|
+
assert (len(data[Frequency.HOURLY.value]) == 0)
|
54
|
+
|
55
|
+
def test_one_day_jsonweb(self):
|
56
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
57
|
+
|
58
|
+
data = client.loadSince(self.__pceIdentifier, 1, [Frequency.DAILY])
|
59
|
+
|
60
|
+
assert (len(data[Frequency.DAILY.value]) <= 1)
|
61
|
+
|
62
|
+
def test_two_days_jsonweb(self):
|
63
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
64
|
+
|
65
|
+
data = client.loadSince(self.__pceIdentifier, 2, [Frequency.DAILY])
|
66
|
+
|
67
|
+
assert (len(data[Frequency.DAILY.value]) <= 2)
|
68
|
+
|
69
|
+
# @pytest.mark.skip(reason="Requires live data")
|
70
|
+
def test_daily_jsonweb(self):
|
71
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
72
|
+
|
73
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
74
|
+
|
75
|
+
assert (len(data[Frequency.DAILY.value]) > 0)
|
76
|
+
|
77
|
+
def test_weekly_jsonweb(self):
|
78
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
79
|
+
|
80
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
81
|
+
|
82
|
+
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
83
|
+
|
84
|
+
def test_monthly_jsonweb(self):
|
85
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
86
|
+
|
87
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
88
|
+
|
89
|
+
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)
|
90
|
+
|
91
|
+
def test_yearly_jsonweb(self):
|
92
|
+
client = Client(JsonWebDataSource(self.__username, self.__password))
|
93
|
+
|
94
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
95
|
+
|
96
|
+
assert (len(data[Frequency.YEARLY.value]) >= 1)
|
97
|
+
|
98
|
+
def test_daily_excelweb(self):
|
99
|
+
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
100
|
+
|
101
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
102
|
+
|
103
|
+
assert (len(data[Frequency.DAILY.value]) > 0)
|
104
|
+
|
105
|
+
def test_weekly_excelweb(self):
|
106
|
+
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
107
|
+
|
108
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
109
|
+
|
110
|
+
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
111
|
+
|
112
|
+
def test_monthly_excelweb(self):
|
113
|
+
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
114
|
+
|
115
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
116
|
+
|
117
|
+
assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
|
118
|
+
|
119
|
+
def test_yearly_excelweb(self):
|
120
|
+
client = Client(ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory))
|
121
|
+
|
122
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
123
|
+
|
124
|
+
assert (len(data[Frequency.YEARLY.value]) >= 1)
|
125
|
+
|
126
|
+
def test_hourly_sample(self):
|
127
|
+
client = Client(TestDataSource())
|
128
|
+
|
129
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.HOURLY])
|
130
|
+
|
131
|
+
assert (len(data[Frequency.HOURLY.value]) == 0)
|
132
|
+
|
133
|
+
def test_daily_sample(self):
|
134
|
+
client = Client(TestDataSource())
|
135
|
+
|
136
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.DAILY])
|
137
|
+
|
138
|
+
assert (len(data[Frequency.DAILY.value]) == 711)
|
139
|
+
|
140
|
+
def test_weekly_sample(self):
|
141
|
+
client = Client(TestDataSource())
|
142
|
+
|
143
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.WEEKLY])
|
144
|
+
|
145
|
+
assert (len(data[Frequency.WEEKLY.value]) > 0)
|
146
|
+
|
147
|
+
def test_monthly_sample(self):
|
148
|
+
client = Client(TestDataSource())
|
149
|
+
|
150
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.MONTHLY])
|
151
|
+
|
152
|
+
assert (len(data[Frequency.MONTHLY.value]) > 0)
|
153
|
+
|
154
|
+
def test_yearly_sample(self):
|
155
|
+
client = Client(TestDataSource())
|
156
|
+
|
157
|
+
data = client.loadSince(self.__pceIdentifier, 365, [Frequency.YEARLY])
|
158
|
+
|
159
|
+
assert (len(data[Frequency.YEARLY.value]) == 2)
|
tests/test_datasource.py
CHANGED
@@ -1,166 +1,166 @@
|
|
1
|
-
import os
|
2
|
-
from pygazpar.datasource import TestDataSource, JsonFileDataSource, ExcelFileDataSource, JsonWebDataSource, ExcelWebDataSource
|
3
|
-
from pygazpar.enum import Frequency
|
4
|
-
from datetime import date, timedelta
|
5
|
-
from dotenv import load_dotenv
|
6
|
-
|
7
|
-
|
8
|
-
class TestAllDataSource:
|
9
|
-
|
10
|
-
# ------------------------------------------------------
|
11
|
-
@classmethod
|
12
|
-
def setup_class(cls):
|
13
|
-
""" setup any state specific to the execution of the given class (which
|
14
|
-
usually contains tests).
|
15
|
-
"""
|
16
|
-
|
17
|
-
# ------------------------------------------------------
|
18
|
-
@classmethod
|
19
|
-
def teardown_class(cls):
|
20
|
-
""" teardown any state that was previously setup with a call to
|
21
|
-
setup_class.
|
22
|
-
"""
|
23
|
-
|
24
|
-
# ------------------------------------------------------
|
25
|
-
def setup_method(self):
|
26
|
-
""" setup any state tied to the execution of the given method in a
|
27
|
-
class. setup_method is invoked for every test method of a class.
|
28
|
-
"""
|
29
|
-
tmpdir = os.path.normpath(f"{os.getcwd()}/tmp")
|
30
|
-
|
31
|
-
# We create the tmp directory if not already exists.
|
32
|
-
if not os.path.exists(tmpdir):
|
33
|
-
os.mkdir(tmpdir)
|
34
|
-
|
35
|
-
load_dotenv()
|
36
|
-
|
37
|
-
self.__username = os.environ["GRDF_USERNAME"]
|
38
|
-
self.__password = os.environ["GRDF_PASSWORD"]
|
39
|
-
self.__pceIdentifier = os.environ["PCE_IDENTIFIER"]
|
40
|
-
self.__tmp_directory = tmpdir
|
41
|
-
|
42
|
-
# ------------------------------------------------------
|
43
|
-
def teardown_method(self):
|
44
|
-
""" teardown any state that was previously setup with a setup_method
|
45
|
-
call.
|
46
|
-
"""
|
47
|
-
|
48
|
-
# ------------------------------------------------------
|
49
|
-
def test_sample(self):
|
50
|
-
|
51
|
-
dataSource = TestDataSource()
|
52
|
-
|
53
|
-
endDate = date.today()
|
54
|
-
startDate = endDate + timedelta(days=-365)
|
55
|
-
|
56
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate)
|
57
|
-
|
58
|
-
assert (len(data[Frequency.DAILY.value]) == 711)
|
59
|
-
|
60
|
-
assert (len(data[Frequency.WEEKLY.value]) == 102)
|
61
|
-
|
62
|
-
assert (len(data[Frequency.MONTHLY.value]) == 24)
|
63
|
-
|
64
|
-
assert (len(data[Frequency.YEARLY.value]) == 2)
|
65
|
-
|
66
|
-
# ------------------------------------------------------
|
67
|
-
def test_jsonfile_sample(self):
|
68
|
-
|
69
|
-
dataSource = JsonFileDataSource("tests/resources/donnees_informatives.json", "tests/resources/temperatures.json")
|
70
|
-
|
71
|
-
endDate = date.today()
|
72
|
-
startDate = endDate + timedelta(days=-365)
|
73
|
-
|
74
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
75
|
-
|
76
|
-
assert (len(data[Frequency.DAILY.value]) == 1096)
|
77
|
-
|
78
|
-
assert (len(data[Frequency.WEEKLY.value]) == 155)
|
79
|
-
|
80
|
-
assert (len(data[Frequency.MONTHLY.value]) == 36)
|
81
|
-
|
82
|
-
assert (len(data[Frequency.YEARLY.value]) == 3)
|
83
|
-
|
84
|
-
# ------------------------------------------------------
|
85
|
-
def test_daily_excelfile_sample(self):
|
86
|
-
|
87
|
-
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_DAILY.xlsx")
|
88
|
-
|
89
|
-
endDate = date.today()
|
90
|
-
startDate = endDate + timedelta(days=-365)
|
91
|
-
|
92
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY])
|
93
|
-
|
94
|
-
assert (len(data[Frequency.DAILY.value]) == 363)
|
95
|
-
|
96
|
-
# ------------------------------------------------------
|
97
|
-
def test_weekly_excelfile_sample(self):
|
98
|
-
|
99
|
-
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_WEEKLY.xlsx")
|
100
|
-
|
101
|
-
endDate = date.today()
|
102
|
-
startDate = endDate + timedelta(days=-365)
|
103
|
-
|
104
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.WEEKLY])
|
105
|
-
|
106
|
-
assert (len(data[Frequency.WEEKLY.value]) == 53)
|
107
|
-
|
108
|
-
# ------------------------------------------------------
|
109
|
-
def test_monthly_excelfile_sample(self):
|
110
|
-
|
111
|
-
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_MONTHLY.xlsx")
|
112
|
-
|
113
|
-
endDate = date.today()
|
114
|
-
startDate = endDate + timedelta(days=-365)
|
115
|
-
|
116
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.MONTHLY])
|
117
|
-
|
118
|
-
assert (len(data[Frequency.MONTHLY.value]) == 13)
|
119
|
-
|
120
|
-
# ------------------------------------------------------
|
121
|
-
def test_yearly_excelfile_sample(self):
|
122
|
-
|
123
|
-
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_DAILY.xlsx")
|
124
|
-
|
125
|
-
endDate = date.today()
|
126
|
-
startDate = endDate + timedelta(days=-365)
|
127
|
-
|
128
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.YEARLY])
|
129
|
-
|
130
|
-
assert (len(data[Frequency.YEARLY.value]) == 1)
|
131
|
-
|
132
|
-
# ------------------------------------------------------
|
133
|
-
def test_jsonweb(self):
|
134
|
-
|
135
|
-
dataSource = JsonWebDataSource(self.__username, self.__password)
|
136
|
-
|
137
|
-
endDate = date.today()
|
138
|
-
startDate = endDate + timedelta(days=-365)
|
139
|
-
|
140
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
141
|
-
|
142
|
-
assert (len(data[Frequency.DAILY.value]) > 0)
|
143
|
-
|
144
|
-
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
145
|
-
|
146
|
-
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)
|
147
|
-
|
148
|
-
assert (len(data[Frequency.YEARLY.value])
|
149
|
-
|
150
|
-
# ------------------------------------------------------
|
151
|
-
def test_excelweb(self):
|
152
|
-
|
153
|
-
dataSource = ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory)
|
154
|
-
|
155
|
-
endDate = date.today()
|
156
|
-
startDate = endDate + timedelta(days=-365)
|
157
|
-
|
158
|
-
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
159
|
-
|
160
|
-
assert (len(data[Frequency.DAILY.value]) > 0)
|
161
|
-
|
162
|
-
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
163
|
-
|
164
|
-
assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
|
165
|
-
|
166
|
-
assert (len(data[Frequency.YEARLY.value])
|
1
|
+
import os
|
2
|
+
from pygazpar.datasource import TestDataSource, JsonFileDataSource, ExcelFileDataSource, JsonWebDataSource, ExcelWebDataSource
|
3
|
+
from pygazpar.enum import Frequency
|
4
|
+
from datetime import date, timedelta
|
5
|
+
from dotenv import load_dotenv
|
6
|
+
|
7
|
+
|
8
|
+
class TestAllDataSource:
|
9
|
+
|
10
|
+
# ------------------------------------------------------
|
11
|
+
@classmethod
|
12
|
+
def setup_class(cls):
|
13
|
+
""" setup any state specific to the execution of the given class (which
|
14
|
+
usually contains tests).
|
15
|
+
"""
|
16
|
+
|
17
|
+
# ------------------------------------------------------
|
18
|
+
@classmethod
|
19
|
+
def teardown_class(cls):
|
20
|
+
""" teardown any state that was previously setup with a call to
|
21
|
+
setup_class.
|
22
|
+
"""
|
23
|
+
|
24
|
+
# ------------------------------------------------------
|
25
|
+
def setup_method(self):
|
26
|
+
""" setup any state tied to the execution of the given method in a
|
27
|
+
class. setup_method is invoked for every test method of a class.
|
28
|
+
"""
|
29
|
+
tmpdir = os.path.normpath(f"{os.getcwd()}/tmp")
|
30
|
+
|
31
|
+
# We create the tmp directory if not already exists.
|
32
|
+
if not os.path.exists(tmpdir):
|
33
|
+
os.mkdir(tmpdir)
|
34
|
+
|
35
|
+
load_dotenv()
|
36
|
+
|
37
|
+
self.__username = os.environ["GRDF_USERNAME"]
|
38
|
+
self.__password = os.environ["GRDF_PASSWORD"]
|
39
|
+
self.__pceIdentifier = os.environ["PCE_IDENTIFIER"]
|
40
|
+
self.__tmp_directory = tmpdir
|
41
|
+
|
42
|
+
# ------------------------------------------------------
|
43
|
+
def teardown_method(self):
|
44
|
+
""" teardown any state that was previously setup with a setup_method
|
45
|
+
call.
|
46
|
+
"""
|
47
|
+
|
48
|
+
# ------------------------------------------------------
|
49
|
+
def test_sample(self):
|
50
|
+
|
51
|
+
dataSource = TestDataSource()
|
52
|
+
|
53
|
+
endDate = date.today()
|
54
|
+
startDate = endDate + timedelta(days=-365)
|
55
|
+
|
56
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate)
|
57
|
+
|
58
|
+
assert (len(data[Frequency.DAILY.value]) == 711)
|
59
|
+
|
60
|
+
assert (len(data[Frequency.WEEKLY.value]) == 102)
|
61
|
+
|
62
|
+
assert (len(data[Frequency.MONTHLY.value]) == 24)
|
63
|
+
|
64
|
+
assert (len(data[Frequency.YEARLY.value]) == 2)
|
65
|
+
|
66
|
+
# ------------------------------------------------------
|
67
|
+
def test_jsonfile_sample(self):
|
68
|
+
|
69
|
+
dataSource = JsonFileDataSource("tests/resources/donnees_informatives.json", "tests/resources/temperatures.json")
|
70
|
+
|
71
|
+
endDate = date.today()
|
72
|
+
startDate = endDate + timedelta(days=-365)
|
73
|
+
|
74
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
75
|
+
|
76
|
+
assert (len(data[Frequency.DAILY.value]) == 1096)
|
77
|
+
|
78
|
+
assert (len(data[Frequency.WEEKLY.value]) == 155)
|
79
|
+
|
80
|
+
assert (len(data[Frequency.MONTHLY.value]) == 36)
|
81
|
+
|
82
|
+
assert (len(data[Frequency.YEARLY.value]) == 3)
|
83
|
+
|
84
|
+
# ------------------------------------------------------
|
85
|
+
def test_daily_excelfile_sample(self):
|
86
|
+
|
87
|
+
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_DAILY.xlsx")
|
88
|
+
|
89
|
+
endDate = date.today()
|
90
|
+
startDate = endDate + timedelta(days=-365)
|
91
|
+
|
92
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY])
|
93
|
+
|
94
|
+
assert (len(data[Frequency.DAILY.value]) == 363)
|
95
|
+
|
96
|
+
# ------------------------------------------------------
|
97
|
+
def test_weekly_excelfile_sample(self):
|
98
|
+
|
99
|
+
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_WEEKLY.xlsx")
|
100
|
+
|
101
|
+
endDate = date.today()
|
102
|
+
startDate = endDate + timedelta(days=-365)
|
103
|
+
|
104
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.WEEKLY])
|
105
|
+
|
106
|
+
assert (len(data[Frequency.WEEKLY.value]) == 53)
|
107
|
+
|
108
|
+
# ------------------------------------------------------
|
109
|
+
def test_monthly_excelfile_sample(self):
|
110
|
+
|
111
|
+
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_MONTHLY.xlsx")
|
112
|
+
|
113
|
+
endDate = date.today()
|
114
|
+
startDate = endDate + timedelta(days=-365)
|
115
|
+
|
116
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.MONTHLY])
|
117
|
+
|
118
|
+
assert (len(data[Frequency.MONTHLY.value]) == 13)
|
119
|
+
|
120
|
+
# ------------------------------------------------------
|
121
|
+
def test_yearly_excelfile_sample(self):
|
122
|
+
|
123
|
+
dataSource = ExcelFileDataSource("tests/resources/Donnees_informatives_PCE_DAILY.xlsx")
|
124
|
+
|
125
|
+
endDate = date.today()
|
126
|
+
startDate = endDate + timedelta(days=-365)
|
127
|
+
|
128
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.YEARLY])
|
129
|
+
|
130
|
+
assert (len(data[Frequency.YEARLY.value]) == 1)
|
131
|
+
|
132
|
+
# ------------------------------------------------------
|
133
|
+
def test_jsonweb(self):
|
134
|
+
|
135
|
+
dataSource = JsonWebDataSource(self.__username, self.__password)
|
136
|
+
|
137
|
+
endDate = date.today()
|
138
|
+
startDate = endDate + timedelta(days=-365)
|
139
|
+
|
140
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
141
|
+
|
142
|
+
assert (len(data[Frequency.DAILY.value]) > 0)
|
143
|
+
|
144
|
+
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
145
|
+
|
146
|
+
assert (len(data[Frequency.MONTHLY.value]) >= 11 and len(data[Frequency.MONTHLY.value]) <= 13)
|
147
|
+
|
148
|
+
assert (len(data[Frequency.YEARLY.value]) >= 1)
|
149
|
+
|
150
|
+
# ------------------------------------------------------
|
151
|
+
def test_excelweb(self):
|
152
|
+
|
153
|
+
dataSource = ExcelWebDataSource(self.__username, self.__password, self.__tmp_directory)
|
154
|
+
|
155
|
+
endDate = date.today()
|
156
|
+
startDate = endDate + timedelta(days=-365)
|
157
|
+
|
158
|
+
data = dataSource.load(self.__pceIdentifier, startDate, endDate, [Frequency.DAILY, Frequency.WEEKLY, Frequency.MONTHLY, Frequency.YEARLY])
|
159
|
+
|
160
|
+
assert (len(data[Frequency.DAILY.value]) > 0)
|
161
|
+
|
162
|
+
assert (len(data[Frequency.WEEKLY.value]) >= 51 and len(data[Frequency.WEEKLY.value]) <= 54)
|
163
|
+
|
164
|
+
assert (len(data[Frequency.MONTHLY.value]) >= 12 and len(data[Frequency.MONTHLY.value]) <= 13)
|
165
|
+
|
166
|
+
assert (len(data[Frequency.YEARLY.value]) >= 1)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|