Skip to content

Commit 2f214fc

Browse files
committed
#142 Tests have realistic/explainable expections of hours.
The unit tests in test_nvenergy.py now how explainable expections regarding the number of hours in a dataframe. For example, tomorrow's forecast has 24 hours. Today's dataframe has the number of local hours which have passed.
1 parent 0bf2f63 commit 2f214fc

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tests/unit/test_nvenergy.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def setUp(self):
2222
self.today = datetime(2017, 12, 24, 12, 34)
2323
self.tomorrow = datetime(2017, 12, 25, 12, 34)
2424
self.last_month = datetime(2017, 11, 24, 12, 34)
25+
26+
self.offset_hours = (pytz.timezone('US/Pacific').localize(self.today) - pytz.utc.localize(self.today)).total_seconds() / 3600;
2527
self.now = pytz.utc.localize(datetime.utcnow())
2628

2729
def test_idx2ts(self):
@@ -83,6 +85,8 @@ def test_fetch_df_bad(self):
8385
self.assertEqual(mode, 'error')
8486

8587
def test_parse_load_today(self):
88+
local_hour = self.today.hour + self.offset_hours
89+
8690
with mock.patch.object(self.c, 'request') as mocker:
8791
mocker.return_value = mock.Mock(status_code=200, content=self.one_day_response)
8892
df, mode = self.c.fetch_df(self.today, url='http://mockurl')
@@ -92,12 +96,13 @@ def test_parse_load_today(self):
9296
data = self.c.parse_load(df, self.today)
9397

9498
# test
95-
self.assertEqual(len(data), 18)
96-
for idp, dp in enumerate(data):
97-
self.assertEqual(dp['market'], 'RTHR')
98-
self.assertEqual(dp['freq'], '1hr')
99-
self.assertEqual(dp['ba_name'], 'NEVP')
100-
self.assertEqual(dp['load_MW'], df.ix['Actual System Load', idp+1])
99+
self.assertEqual(len(data), local_hour)
100+
101+
for idp, dp in enumerate(data):
102+
self.assertEqual(dp['market'], 'RTHR')
103+
self.assertEqual(dp['freq'], '1hr')
104+
self.assertEqual(dp['ba_name'], 'NEVP')
105+
self.assertEqual(dp['load_MW'], df.ix['Actual System Load', idp+1])
101106

102107
def test_parse_load_tomorrow(self):
103108
with mock.patch.object(self.c, 'request') as mocker:
@@ -127,14 +132,16 @@ def test_parse_load_last_month(self):
127132
data = self.c.parse_load(df, self.last_month)
128133

129134
# test
130-
self.assertEqual(len(data), 18)
135+
self.assertEqual(len(data), 24)
131136
for idp, dp in enumerate(data):
132137
self.assertEqual(dp['market'], 'RTHR')
133138
self.assertEqual(dp['freq'], '1hr')
134139
self.assertEqual(dp['ba_name'], 'NEVP')
135140
self.assertEqual(dp['load_MW'], df.ix['Actual System Load', idp+1])
136141

137142
def test_parse_trade_today(self):
143+
local_hour = self.today.hour + self.offset_hours
144+
138145
with mock.patch.object(self.c, 'request') as mocker:
139146
mocker.return_value = mock.Mock(status_code=200, content=self.one_day_response)
140147
df, mode = self.c.fetch_df(self.today, url='http://mockurl')
@@ -144,14 +151,14 @@ def test_parse_trade_today(self):
144151
data = self.c.parse_trade(df, self.today)
145152

146153
# test
147-
self.assertEqual(len(data), 18*len(self.c.TRADE_BAS))
154+
self.assertEqual(len(data), local_hour * len(self.c.TRADE_BAS))
148155
for idp, dp in enumerate(data):
149156
self.assertEqual(dp['market'], 'RTHR')
150157
self.assertEqual(dp['freq'], '1hr')
151158
self.assertIn(dp['dest_ba_name'], self.c.TRADE_BAS.values())
152159

153160
dest = [k for k, v in self.c.TRADE_BAS.items() if v == dp['dest_ba_name']][0]
154-
idx = idp % 18 + 1
161+
idx = idp % local_hour + 1
155162
self.assertEqual(dp['export_MW'], df.ix[dest, idx])
156163

157164
def test_parse_trade_tomorrow(self):
@@ -175,14 +182,14 @@ def test_parse_trade_last_month(self):
175182
data = self.c.parse_trade(df, self.last_month)
176183

177184
# test
178-
self.assertEqual(len(data), 18*len(self.c.TRADE_BAS))
185+
self.assertEqual(len(data), 24*len(self.c.TRADE_BAS))
179186
for idp, dp in enumerate(data):
180187
self.assertEqual(dp['market'], 'RTHR')
181188
self.assertEqual(dp['freq'], '1hr')
182189
self.assertIn(dp['dest_ba_name'], self.c.TRADE_BAS.values())
183190

184191
dest = [k for k, v in self.c.TRADE_BAS.items() if v == dp['dest_ba_name']][0]
185-
idx = idp % 18 + 1
192+
idx = idp % 24 + 1
186193
self.assertEqual(dp['export_MW'], df.ix[dest, idx])
187194

188195
def test_time_subset_latest(self):

0 commit comments

Comments
 (0)