-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_base.py
468 lines (391 loc) · 23.9 KB
/
test_base.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
import dask
import json
import numpy as np
import os
from unittest.mock import patch, MagicMock
import pandas as pd
import pytest
from pyarrow import parquet
import tempfile
import yaml
import shutil
import glob
from buildstockbatch.base import BuildStockBatchBase
from buildstockbatch.postprocessing import write_dataframe_as_parquet
dask.config.set(scheduler='synchronous')
here = os.path.dirname(os.path.abspath(__file__))
OUTPUT_FOLDER_NAME = 'output'
def test_missing_simulation_output_report_applicable(basic_residential_project_file):
project_filename, results_dir = basic_residential_project_file()
# Modify the results to remove the simulation output report from all of one upgrade.
simout_dir = os.path.join(results_dir, 'simulation_output')
for upgrade_dir in os.listdir(simout_dir):
full_upgrade_dir = os.path.join(simout_dir, upgrade_dir)
if not os.path.isdir(full_upgrade_dir):
continue
for bldg_dir in os.listdir(full_upgrade_dir):
datapoint_out_filename = os.path.join(simout_dir, upgrade_dir, bldg_dir, 'run', 'data_point_out.json')
if upgrade_dir.endswith('up01') and os.path.isfile(datapoint_out_filename):
with open(datapoint_out_filename, 'r') as f:
dpout = json.load(f)
del dpout['SimulationOutputReport']
with open(datapoint_out_filename, 'w') as f:
json.dump(dpout, f)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
up01_parquet = os.path.join(results_dir, 'parquet', 'upgrades', 'upgrade=1', 'results_up01.parquet')
assert(os.path.exists(up01_parquet))
df = pd.read_parquet(up01_parquet, engine='pyarrow')
assert(not df['simulation_output_report.applicable'].any())
def test_combine_files_flexible(basic_residential_project_file):
# Allows addition/removable/rename of columns. For columns that remain unchanged, verifies that the data matches
# with stored test_results. If this test passes but test_combine_files fails, then test_results/parquet and
# test_results/results_csvs need to be updated with new data *if* columns were indeed supposed to be added/
# removed/renamed.
post_process_config = {
'postprocessing': {
'aggregate_timeseries': True
}
}
project_filename, results_dir = basic_residential_project_file(post_process_config)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
def simplify_columns(colname):
return colname.lower().replace('_', '')
# test results.csv files
reference_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_results', 'results_csvs')
test_path = os.path.join(results_dir, 'results_csvs')
test_csv = pd.read_csv(os.path.join(test_path, 'results_up00.csv.gz')).rename(columns=simplify_columns).\
sort_values('buildingid').reset_index().drop(columns=['index'])
reference_csv = pd.read_csv(os.path.join(reference_path, 'results_up00.csv.gz')).rename(columns=simplify_columns).\
sort_values('buildingid').reset_index().drop(columns=['index'])
mutul_cols = list(set(test_csv.columns).intersection(set(reference_csv)))
pd.testing.assert_frame_equal(test_csv[mutul_cols], reference_csv[mutul_cols])
test_csv = pd.read_csv(os.path.join(test_path, 'results_up01.csv.gz')).rename(columns=simplify_columns).\
sort_values('buildingid').reset_index().drop(columns=['index'])
reference_csv = pd.read_csv(os.path.join(reference_path, 'results_up01.csv.gz')).rename(columns=simplify_columns).\
sort_values('buildingid').reset_index().drop(columns=['index'])
mutul_cols = list(set(test_csv.columns).intersection(set(reference_csv)))
pd.testing.assert_frame_equal(test_csv[mutul_cols], reference_csv[mutul_cols])
# test parquet files
reference_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_results', 'parquet')
test_path = os.path.join(results_dir, 'parquet')
# results parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'baseline', 'results_up00.parquet')).\
rename(columns=simplify_columns).sort_values('buildingid').reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'baseline', 'results_up00.parquet')).\
rename(columns=simplify_columns).sort_values('buildingid').reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
test_pq = pd.read_parquet(os.path.join(test_path, 'upgrades', 'upgrade=1', 'results_up01.parquet')).\
rename(columns=simplify_columns).sort_values('buildingid').reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'upgrades', 'upgrade=1', 'results_up01.parquet')).\
rename(columns=simplify_columns).sort_values('buildingid').reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
# aggregated_timeseries parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'aggregated_timeseries',
'upgrade=0', 'aggregated_ts_up00.parquet')).\
rename(columns=simplify_columns).sort_values(['time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'aggregated_timeseries',
'upgrade=0', 'aggregated_ts_up00.parquet')).\
rename(columns=simplify_columns).sort_values(['time']).reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
test_pq = pd.read_parquet(os.path.join(test_path, 'aggregated_timeseries',
'upgrade=1', 'aggregated_ts_up01.parquet')).\
rename(columns=simplify_columns).sort_values(['time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'aggregated_timeseries',
'upgrade=1', 'aggregated_ts_up01.parquet')).\
rename(columns=simplify_columns).sort_values(['time']).reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
# timeseries parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'timeseries', 'upgrade=0', 'Group0.parquet')).\
rename(columns=simplify_columns).sort_values(['buildingid', 'time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'timeseries', 'upgrade=0', 'Group0.parquet')).\
rename(columns=simplify_columns).sort_values(['buildingid', 'time']).reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
test_pq = pd.read_parquet(os.path.join(test_path, 'timeseries', 'upgrade=1', 'Group0.parquet')).\
rename(columns=simplify_columns).sort_values(['buildingid', 'time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'timeseries', 'upgrade=1', 'Group0.parquet')).\
rename(columns=simplify_columns).sort_values(['buildingid', 'time']).reset_index().drop(columns=['index'])
mutul_cols = list(set(test_pq.columns).intersection(set(reference_pq)))
pd.testing.assert_frame_equal(test_pq[mutul_cols], reference_pq[mutul_cols])
def test_provide_buildstock_csv(basic_residential_project_file):
with tempfile.TemporaryDirectory() as buildstock_csv_dir:
buildstock_csv = os.path.join(buildstock_csv_dir, 'buildstock.csv')
df = pd.read_csv(os.path.join(here, 'buildstock.csv'))
df2 = df[df['Vintage'] == '<1950']
df2.to_csv(buildstock_csv, index=False)
project_filename, results_dir = basic_residential_project_file({
'baseline': {
'n_buildings_represented': 80000000,
'buildstock_csv': buildstock_csv
}
})
sampler = MagicMock()
copied_csv = os.path.join(buildstock_csv_dir, 'buildstock_out.csv')
sampler.csv_path = copied_csv
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.sampler = sampler
sampling_output_csv = bsb.run_sampling()
assert(sampling_output_csv == copied_csv)
df3 = pd.read_csv(sampling_output_csv)
assert(df3.shape == df2.shape)
assert((df3['Vintage'] == '<1950').all())
# Test n_datapoints do not match
with open(project_filename, 'r') as f:
cfg = yaml.safe_load(f)
cfg['baseline']['n_datapoints'] = 100
with open(project_filename, 'w') as f:
yaml.dump(cfg, f)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
with pytest.raises(RuntimeError) as ex:
bsb = BuildStockBatchBase(project_filename)
assert('n_datapoints for sampling should not be provided' in str(ex.value))
# Test file missing
with open(project_filename, 'r') as f:
cfg = yaml.safe_load(f)
del cfg['baseline']['n_datapoints']
cfg['baseline']['buildstock_csv'] = os.path.join(buildstock_csv_dir, 'non_existant_file.csv')
with open(project_filename, 'w') as f:
yaml.dump(cfg, f)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
with pytest.raises(FileNotFoundError) as ex:
bsb = BuildStockBatchBase(project_filename)
# Test downselect mutually exclusive
with open(project_filename, 'r') as f:
cfg = yaml.safe_load(f)
cfg['baseline']['buildstock_csv'] = buildstock_csv
cfg['downselect'] = {'resample': True, 'logic': []}
with open(project_filename, 'w') as f:
yaml.dump(cfg, f)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
with pytest.raises(RuntimeError) as ex:
bsb = BuildStockBatchBase(project_filename)
assert('Remove or comment out the downselect key' in str(ex.value))
def test_combine_files(basic_residential_project_file):
post_process_config = {
'postprocessing': {
'aggregate_timeseries': True
}
}
project_filename, results_dir = basic_residential_project_file(post_process_config)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
# test results.csv files
reference_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_results', 'results_csvs')
test_path = os.path.join(results_dir, 'results_csvs')
test_csv = pd.read_csv(os.path.join(test_path, 'results_up00.csv.gz')).sort_values('building_id').reset_index()\
.drop(columns=['index'])
reference_csv = pd.read_csv(os.path.join(reference_path, 'results_up00.csv.gz')).sort_values('building_id')\
.reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_csv, reference_csv)
test_csv = pd.read_csv(os.path.join(test_path, 'results_up01.csv.gz')).sort_values('building_id').reset_index()\
.drop(columns=['index'])
reference_csv = pd.read_csv(os.path.join(reference_path, 'results_up01.csv.gz')).sort_values('building_id')\
.reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_csv, reference_csv)
# test parquet files
reference_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_results', 'parquet')
test_path = os.path.join(results_dir, 'parquet')
# results parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'baseline', 'results_up00.parquet')).sort_values('building_id')\
.reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'baseline', 'results_up00.parquet'))\
.sort_values('building_id').reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
test_pq = pd.read_parquet(os.path.join(test_path, 'upgrades', 'upgrade=1', 'results_up01.parquet'))\
.sort_values('building_id').reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'upgrades', 'upgrade=1', 'results_up01.parquet'))\
.sort_values('building_id').reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
# aggregated_timeseries parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'aggregated_timeseries',
'upgrade=0', 'aggregated_ts_up00.parquet')).\
sort_values(['Time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'aggregated_timeseries',
'upgrade=0', 'aggregated_ts_up00.parquet')).\
sort_values(['Time']).reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
test_pq = pd.read_parquet(os.path.join(test_path, 'aggregated_timeseries',
'upgrade=1', 'aggregated_ts_up01.parquet')).\
sort_values(['Time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'aggregated_timeseries',
'upgrade=1', 'aggregated_ts_up01.parquet')).\
sort_values(['Time']).reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
# timeseries parquet
test_pq = pd.read_parquet(os.path.join(test_path, 'timeseries', 'upgrade=0', 'Group0.parquet')).\
sort_values(['building_id', 'time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'timeseries', 'upgrade=0', 'Group0.parquet'))\
.sort_values(['building_id', 'time']).reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
test_pq = pd.read_parquet(os.path.join(test_path, 'timeseries', 'upgrade=1', 'Group0.parquet'))\
.sort_values(['building_id', 'time']).reset_index().drop(columns=['index'])
reference_pq = pd.read_parquet(os.path.join(reference_path, 'timeseries', 'upgrade=1', 'Group0.parquet'))\
.sort_values(['building_id', 'time']).reset_index().drop(columns=['index'])
pd.testing.assert_frame_equal(test_pq, reference_pq)
@patch('buildstockbatch.postprocessing.boto3')
def test_upload_files(mocked_s3, basic_residential_project_file):
s3_bucket = 'test_bucket'
s3_prefix = 'test_prefix'
db_name = 'test_db_name'
role = 'test_role'
region = 'test_region'
upload_config = {
'postprocessing': {
'aws': {
'region_name': region,
's3': {
'bucket': s3_bucket,
'prefix': s3_prefix,
},
'athena': {
'glue_service_role': role,
'database_name': db_name,
'max_crawling_time': 250
}
}
}
}
mocked_glueclient = MagicMock()
mocked_glueclient.get_crawler = MagicMock(return_value={'Crawler': {'State': 'READY'}})
mocked_s3.client = MagicMock(return_value=mocked_glueclient)
project_filename, results_dir = basic_residential_project_file(upload_config)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'output_dir', results_dir), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
files_uploaded = []
crawler_created = False
crawler_started = False
for call in mocked_s3.mock_calls + mocked_s3.client().mock_calls:
call_function = call[0].split('.')[-1] # 0 is for the function name
if call_function == 'resource':
assert call[1][0] in ['s3'] # call[1] is for the positional arguments
if call_function == 'Bucket':
assert call[1][0] == s3_bucket
if call_function == 'upload_file':
source_file_path = call[1][0]
destination_path = call[1][1]
files_uploaded.append((source_file_path, destination_path))
if call_function == 'create_crawler':
crawler_para = call[2] # 2 is for the keyboard arguments
crawler_created = True
assert crawler_para['DatabaseName'] == upload_config['postprocessing']['aws']['athena']['database_name']
assert crawler_para['Role'] == upload_config['postprocessing']['aws']['athena']['glue_service_role']
assert crawler_para['TablePrefix'] == OUTPUT_FOLDER_NAME + '_'
assert crawler_para['Name'] == db_name + '_' + OUTPUT_FOLDER_NAME
assert crawler_para['Targets']['S3Targets'][0]['Path'] == 's3://' + s3_bucket + '/' + s3_prefix + '/' + \
OUTPUT_FOLDER_NAME + '/'
if call_function == 'start_crawler':
assert crawler_created, "crawler attempted to start before creating"
crawler_started = True
crawler_para = call[2] # 2 is for keyboard arguments.
assert crawler_para['Name'] == db_name + '_' + OUTPUT_FOLDER_NAME
assert crawler_started, "Crawler never started"
# check if all the files are properly uploaded
source_path = os.path.join(results_dir, 'parquet')
s3_path = s3_prefix + '/' + OUTPUT_FOLDER_NAME + '/'
s3_file_path = s3_path + 'baseline/results_up00.parquet'
source_file_path = os.path.join(source_path, 'baseline', 'results_up00.parquet')
assert (source_file_path, s3_file_path) in files_uploaded
files_uploaded.remove((source_file_path, s3_file_path))
s3_file_path = s3_path + 'upgrades/upgrade=1/results_up01.parquet'
source_file_path = os.path.join(source_path, 'upgrades', 'upgrade=1', 'results_up01.parquet')
assert (source_file_path, s3_file_path) in files_uploaded
files_uploaded.remove((source_file_path, s3_file_path))
s3_file_path = s3_path + 'timeseries/upgrade=0/Group0.parquet'
source_file_path = os.path.join(source_path, 'timeseries', 'upgrade=0', 'Group0.parquet')
assert (source_file_path, s3_file_path) in files_uploaded
files_uploaded.remove((source_file_path, s3_file_path))
s3_file_path = s3_path + 'timeseries/upgrade=1/Group0.parquet'
source_file_path = os.path.join(source_path, 'timeseries', 'upgrade=1', 'Group0.parquet')
assert (source_file_path, s3_file_path) in files_uploaded
files_uploaded.remove((source_file_path, s3_file_path))
assert len(files_uploaded) == 0, f"These files shouldn't have been uploaded: {files_uploaded}"
def test_write_parquet_no_index():
df = pd.DataFrame(np.random.randn(6, 4), columns=list('abcd'), index=np.arange(6))
with tempfile.TemporaryDirectory() as tmpdir:
filename = 'df.parquet'
write_dataframe_as_parquet(df, tmpdir, filename)
schema = parquet.read_schema(os.path.join(tmpdir, filename))
assert '__index_level_0__' not in schema.names
assert df.columns.values.tolist() == schema.names
def test_skipping_baseline(basic_residential_project_file):
project_filename, results_dir = basic_residential_project_file({
'baseline': {
'skip_sims': True
}
})
sim_output_path = os.path.join(results_dir, 'simulation_output')
assert 'up00' in os.listdir(sim_output_path)
baseline_path = os.path.join(sim_output_path, 'up00')
shutil.rmtree(baseline_path)
assert 'up00' not in os.listdir(sim_output_path)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
up00_parquet = os.path.join(results_dir, 'parquet', 'upgrades', 'upgrade=0', 'results_up00.parquet')
assert(not os.path.exists(up00_parquet))
up01_parquet = os.path.join(results_dir, 'parquet', 'upgrades', 'upgrade=1', 'results_up01.parquet')
assert(os.path.exists(up01_parquet))
up00_csv_gz = os.path.join(results_dir, 'results_csvs', 'results_up00.csv.gz')
assert(not os.path.exists(up00_csv_gz))
up01_csv_gz = os.path.join(results_dir, 'results_csvs', 'results_up01.csv.gz')
assert(os.path.exists(up01_csv_gz))
def test_report_additional_results_csv_columns(basic_residential_project_file):
project_filename, results_dir = basic_residential_project_file({
'reporting_measures': [
'ReportingMeasure1',
'ReportingMeasure2'
]
})
for filename in glob.glob(os.path.join(results_dir, 'simulation_output', 'up*', 'bldg*', 'run',
'data_point_out.json')):
with open(filename, 'r') as f:
dpout = json.load(f)
dpout['ReportingMeasure1'] = {'column_1': 1, 'column_2': 2}
dpout['ReportingMeasure2'] = {'column_3': 3, 'column_4': 4}
with open(filename, 'w') as f:
json.dump(dpout, f)
with patch.object(BuildStockBatchBase, 'weather_dir', None), \
patch.object(BuildStockBatchBase, 'get_dask_client') as get_dask_client_mock, \
patch.object(BuildStockBatchBase, 'results_dir', results_dir):
bsb = BuildStockBatchBase(project_filename)
bsb.process_results()
get_dask_client_mock.assert_called_once()
up00_results_csv_path = os.path.join(results_dir, 'results_csvs', 'results_up00.csv.gz')
up00 = pd.read_csv(up00_results_csv_path)
assert 'reporting_measure1' in [col.split('.')[0] for col in up00.columns]
assert 'reporting_measure2' in [col.split('.')[0] for col in up00.columns]
up01_results_csv_path = os.path.join(results_dir, 'results_csvs', 'results_up01.csv.gz')
up01 = pd.read_csv(up01_results_csv_path)
assert 'reporting_measure1' in [col.split('.')[0] for col in up01.columns]
assert 'reporting_measure2' in [col.split('.')[0] for col in up01.columns]