forked from trynthink/scout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htcl_totals_test.py
534 lines (514 loc) · 26.6 KB
/
htcl_totals_test.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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
#!/usr/bin/env python3
""" Tests for running the htcl_totals.py routine """
# Import code to be tested
import htcl_totals
# Import needed packages
import unittest
import itertools
class CommonMethods(object):
"""Define common methods for use in all tests below."""
def dict_check(self, dict1, dict2):
"""Check the equality of two dicts.
Args:
dict1 (dict): First dictionary to be compared
dict2 (dict): Second dictionary to be compared
Raises:
AssertionError: If dictionaries are not equal.
"""
# zip() and zip_longest() produce tuples for the items
# identified, where in the case of a dict, the first item
# in the tuple is the key and the second item is the value;
# in the case where the dicts are not of identical size,
# zip_longest() will use the fill value created below as a
# substitute in the dict that has missing content; this
# value is given as a tuple to be of comparable structure
# to the normal output from zip_longest()
fill_val = ('substituted entry', 5.2)
# In this structure, k and k2 are the keys that correspond to
# the dicts or unitary values that are found in i and i1,
# respectively, at the current level of the recursive
# exploration of dict1 and dict1, respectively
for (k, i), (k2, i2) in itertools.zip_longest(sorted(dict1.items()),
sorted(dict2.items()),
fillvalue=fill_val):
# Confirm that at the current location in the dict structure,
# the keys are equal; this should fail if one of the dicts
# is empty, is missing section(s), or has different key names
self.assertEqual(k, k2)
# If the recursion has not yet reached the terminal/leaf node
if isinstance(i, dict):
# Test that the dicts from the current keys are equal
self.assertCountEqual(i, i2)
# Continue to recursively traverse the dict
self.dict_check(i, i2)
else:
# At the terminal/leaf node, formatted as a point value
self.assertAlmostEqual(i, i2, places=2)
class SumHtClEnergyTest(unittest.TestCase, CommonMethods):
"""Test operation of 'sum_htcl_energy' function.
Verify that function properly sums all heating and cooling energy for
a given climate zone, building type, and structure type combination,
converting from site to source energy in the process.
Attributes:
aeo_years (list): Modeling time horizon.
ss_conv (dict): Site-source conversion factors.
ok_msegs_in (dict): Sample stock/energy data to use in developing sums.
ok_out (dict): Sum totals that should be yielded by function given
valid sample inputs.
"""
@classmethod
def setUpClass(cls):
"""Define objects/variables for use across all class functions."""
cls.aeo_years = ["2009", "2010"]
cls.ss_conv = {
"electricity": {"2009": 3, "2010": 4},
"natural gas": {"2009": 1, "2010": 1},
"distillate": {"2009": 1, "2010": 1},
"other fuel": {"2009": 1, "2010": 1}}
cls.ok_msegs_in = {
"AIA_CZ1": {
"single family home": {
"new homes": {"2009": 1, "2010": 1},
"total homes": {"2009": 10, "2010": 10},
"total square footage": {"2009": 100, "2010": 100},
"electricity": {
"lighting": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"secondary heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"cooling": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"natural gas": {
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"secondary heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}}},
"assembly": {
"new square footage": {"2009": 1, "2010": 1},
"total square footage": {"2009": 5, "2010": 5},
"electricity": {
"lighting": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"cooling": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"refrigeration": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}
},
"distillate": {
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}}}},
"AIA_CZ2": {
"single family home": {
"new homes": {"2009": 1, "2010": 1},
"total homes": {"2009": 100, "2010": 100},
"total square footage": {"2009": 1000, "2010": 1000},
"electricity": {
"lighting": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"secondary heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"cooling": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"natural gas": {
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"secondary heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}}},
"assembly": {
"new square footage": {"2009": 1, "2010": 1},
"total square footage": {"2009": 10, "2010": 10},
"electricity": {
"lighting": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"cooling": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"refrigeration": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}
},
"distillate": {
"heating": {
"supply": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}},
"demand": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}},
"water heating": {
"tech 1": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}},
"tech 2": {
"stock": {"2009": 1, "2010": 1},
"energy": {"2009": 1, "2010": 1}}}}}}}
cls.ok_out = {
"AIA_CZ1": {
"single family home": {
"new": {
"electricity": {
"heating": {"2009": 0.6, "2010": 1.6},
"cooling": {"2009": 0.6, "2010": 1.6},
"secondary heating": {"2009": 0.6, "2010": 1.6}},
"natural gas": {
"heating": {"2009": 0.2, "2010": 0.4},
"secondary heating": {"2009": 0.2, "2010": 0.4}}
},
"existing": {
"electricity": {
"heating": {"2009": 5.4, "2010": 6.4},
"cooling": {"2009": 5.4, "2010": 6.4},
"secondary heating": {"2009": 5.4, "2010": 6.4}},
"natural gas": {
"heating": {"2009": 1.8, "2010": 1.6},
"secondary heating": {"2009": 1.8, "2010": 1.6}}
}
},
"assembly": {
"new": {
"electricity": {
"heating": {"2009": 1.2, "2010": 3.2},
"cooling": {"2009": 1.2, "2010": 3.2}
},
"distillate": {
"heating": {"2009": 0.4, "2010": 0.8}
}
},
"existing": {
"electricity": {
"heating": {"2009": 4.8, "2010": 4.8},
"cooling": {"2009": 4.8, "2010": 4.8}
},
"distillate": {
"heating": {"2009": 1.6, "2010": 1.2}
}
}
}},
"AIA_CZ2": {
"single family home": {
"new": {
"electricity": {
"heating": {"2009": 0.06, "2010": 0.16},
"cooling": {"2009": 0.06, "2010": 0.16},
"secondary heating": {"2009": 0.06, "2010": 0.16}},
"natural gas": {
"heating": {"2009": 0.02, "2010": 0.04},
"secondary heating": {"2009": 0.02, "2010": 0.04}}
},
"existing": {
"electricity": {
"heating": {"2009": 5.94, "2010": 7.84},
"cooling": {"2009": 5.94, "2010": 7.84},
"secondary heating": {"2009": 5.94, "2010": 7.84}},
"natural gas": {
"heating": {"2009": 1.98, "2010": 1.96},
"secondary heating": {"2009": 1.98, "2010": 1.96}}
}
},
"assembly": {
"new": {
"electricity": {
"heating": {"2009": 0.6, "2010": 1.6},
"cooling": {"2009": 0.6, "2010": 1.6}
},
"distillate": {
"heating": {"2009": 0.2, "2010": 0.4}
}
},
"existing": {
"electricity": {
"heating": {"2009": 5.4, "2010": 6.4},
"cooling": {"2009": 5.4, "2010": 6.4}
},
"distillate": {
"heating": {"2009": 1.8, "2010": 1.6}
}
}
}}}
def test_ok(self):
"""Test for correct function output given valid inputs."""
self.dict_check(
htcl_totals.sum_htcl_energy(
self.ok_msegs_in, self.aeo_years, self.ss_conv),
self.ok_out)
# Offer external code execution (include all lines below this point in all
# test files)
def main():
"""Trigger default behavior of running all test fixtures in the file."""
unittest.main()
if __name__ == "__main__":
main()