Skip to content

Commit cd6875a

Browse files
committed
fix example test
1 parent c9ea523 commit cd6875a

1 file changed

Lines changed: 54 additions & 59 deletions

File tree

tests/h2integrate/test_all_examples.py

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_steel_example(subtests):
2525
with subtests.test("Check LCOH"):
2626
assert (
2727
pytest.approx(
28-
model.prob.get_val("financials_subgroup_hydrogen.LCOH_delivered")[0], rel=1e-3
28+
model.prob.get_val("finance_subgroup_hydrogen.LCOH_delivered")[0], rel=1e-3
2929
)
3030
== 7.47944016
3131
)
@@ -36,15 +36,15 @@ def test_steel_example(subtests):
3636
with subtests.test("Check total adjusted CapEx"):
3737
assert (
3838
pytest.approx(
39-
model.prob.get_val("financials_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
39+
model.prob.get_val("finance_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
4040
)
4141
== 5.10869916e09
4242
)
4343

4444
with subtests.test("Check total adjusted OpEx"):
4545
assert (
4646
pytest.approx(
47-
model.prob.get_val("financials_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
47+
model.prob.get_val("finance_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
4848
)
4949
== 96349901.77625626
5050
)
@@ -102,29 +102,29 @@ def test_simple_ammonia_example(subtests):
102102
with subtests.test("Check total adjusted CapEx"):
103103
assert (
104104
pytest.approx(
105-
model.prob.get_val("financials_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
105+
model.prob.get_val("finance_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
106106
)
107107
== 2678403968.6
108108
)
109109

110110
with subtests.test("Check total adjusted OpEx"):
111111
assert (
112112
pytest.approx(
113-
model.prob.get_val("financials_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
113+
model.prob.get_val("finance_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
114114
)
115115
== 64338137.8
116116
)
117117

118118
# Currently underestimated compared to the Reference Design Doc
119119
with subtests.test("Check LCOH"):
120120
assert (
121-
pytest.approx(model.prob.get_val("financials_subgroup_hydrogen.LCOH")[0], rel=1e-3)
121+
pytest.approx(model.prob.get_val("finance_subgroup_hydrogen.LCOH")[0], rel=1e-3)
122122
== 4.233055
123123
)
124124
# Currently underestimated compared to the Reference Design Doc
125125
with subtests.test("Check LCOA"):
126126
assert (
127-
pytest.approx(model.prob.get_val("financials_subgroup_ammonia.LCOA")[0], rel=1e-3)
127+
pytest.approx(model.prob.get_val("finance_subgroup_ammonia.LCOA")[0], rel=1e-3)
128128
== 1.02470046
129129
)
130130

@@ -187,28 +187,28 @@ def test_ammonia_synloop_example(subtests):
187187
with subtests.test("Check total adjusted CapEx"):
188188
assert (
189189
pytest.approx(
190-
model.prob.get_val("financials_subgroup_nh3.total_capex_adjusted")[0], rel=1e-6
190+
model.prob.get_val("finance_subgroup_nh3.total_capex_adjusted")[0], rel=1e-6
191191
)
192192
== 3.7289e09
193193
)
194194

195195
with subtests.test("Check total adjusted OpEx"):
196196
assert (
197197
pytest.approx(
198-
model.prob.get_val("financials_subgroup_nh3.total_opex_adjusted")[0], rel=1e-6
198+
model.prob.get_val("finance_subgroup_nh3.total_opex_adjusted")[0], rel=1e-6
199199
)
200200
== 78480154.4
201201
)
202202

203203
with subtests.test("Check LCOH"):
204204
assert (
205-
pytest.approx(model.prob.get_val("financials_subgroup_h2.LCOH")[0], rel=1e-6)
205+
pytest.approx(model.prob.get_val("finance_subgroup_h2.LCOH")[0], rel=1e-6)
206206
== 5.659321302703965
207207
)
208208

209209
with subtests.test("Check LCOA"):
210210
assert (
211-
pytest.approx(model.prob.get_val("financials_subgroup_nh3.LCOA")[0], rel=1e-6)
211+
pytest.approx(model.prob.get_val("finance_subgroup_nh3.LCOA")[0], rel=1e-6)
212212
== 1.067030996544544
213213
)
214214

@@ -274,7 +274,7 @@ def test_wind_h2_opt_example(subtests):
274274

275275
with subtests.test("Check LCOE"):
276276
assert (
277-
pytest.approx(model.prob.get_val("financials_subgroup_electricity.LCOE")[0], rel=1e-3)
277+
pytest.approx(model.prob.get_val("finance_subgroup_electricity.LCOE")[0], rel=1e-3)
278278
== 0.151189
279279
)
280280

@@ -302,23 +302,23 @@ def test_wind_h2_opt_example(subtests):
302302
assert len(cases) > 1, "Not enough cases recorded in SQL file."
303303

304304
# Get initial and final LCOH values
305-
initial_lcoh = cases[0].outputs["financials_subgroup_hydrogen.LCOH"][0]
306-
final_lcoh = cases[-1].outputs["financials_subgroup_hydrogen.LCOH"][0]
305+
initial_lcoh = cases[0].outputs["finance_subgroup_hydrogen.LCOH"][0]
306+
final_lcoh = cases[-1].outputs["finance_subgroup_hydrogen.LCOH"][0]
307307

308308
with subtests.test("Check LCOH changed"):
309309
assert final_lcoh != initial_lcoh
310310

311311
with subtests.test("Check total adjusted CapEx"):
312312
assert (
313313
pytest.approx(
314-
model.prob.get_val("financials_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
314+
model.prob.get_val("finance_subgroup_hydrogen.total_capex_adjusted")[0], rel=1e-3
315315
)
316316
== 2783126102
317317
)
318318
with subtests.test("Check total adjusted OpEx"):
319319
assert (
320320
pytest.approx(
321-
model.prob.get_val("financials_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
321+
model.prob.get_val("finance_subgroup_hydrogen.total_opex_adjusted")[0], rel=1e-3
322322
)
323323
== 75543899
324324
)
@@ -347,12 +347,7 @@ def test_paper_example(subtests):
347347

348348
# Subtests for checking specific values
349349
with subtests.test("Check LCOP"):
350-
assert (
351-
pytest.approx(
352-
model.prob.get_val("plant.paper_mill.paper_mill_financial.LCOP"), rel=1e-3
353-
)
354-
== 51.91476681
355-
)
350+
assert pytest.approx(model.prob.get_val("paper_mill.LCOP"), rel=1e-3) == 51.91476681
356351

357352

358353
@unittest.skipUnless(importlib.util.find_spec("mcm") is not None, "mcm is not installed")
@@ -371,13 +366,13 @@ def test_wind_wave_doc_example(subtests):
371366
# Subtests for checking specific values
372367
with subtests.test("Check LCOC"):
373368
assert (
374-
pytest.approx(model.prob.get_val("financials_subgroup_co2.LCOC")[0], rel=1e-3)
369+
pytest.approx(model.prob.get_val("finance_subgroup_co2.LCOC")[0], rel=1e-3)
375370
== 2.26955589
376371
)
377372

378373
with subtests.test("Check LCOE"):
379374
assert (
380-
pytest.approx(model.prob.get_val("financials_subgroup_electricity.LCOE")[0], rel=1e-3)
375+
pytest.approx(model.prob.get_val("finance_subgroup_electricity.LCOE")[0], rel=1e-3)
381376
== 1.05281478
382377
)
383378

@@ -398,19 +393,19 @@ def test_splitter_wind_doc_h2_example(subtests):
398393
# Subtests for checking specific values
399394
with subtests.test("Check LCOH"):
400395
assert (
401-
pytest.approx(model.prob.get_val("financials_subgroup_hydrogen.LCOH")[0], rel=1e-3)
396+
pytest.approx(model.prob.get_val("finance_subgroup_hydrogen.LCOH")[0], rel=1e-3)
402397
== 10.25515911
403398
)
404399

405400
with subtests.test("Check LCOC"):
406401
assert (
407-
pytest.approx(model.prob.get_val("financials_subgroup_co2.LCOC")[0], rel=1e-3)
402+
pytest.approx(model.prob.get_val("finance_subgroup_co2.LCOC")[0], rel=1e-3)
408403
== 14.19802243
409404
)
410405

411406
with subtests.test("Check LCOE"):
412407
assert (
413-
pytest.approx(model.prob.get_val("financials_subgroup_electricity.LCOE")[0], rel=1e-3)
408+
pytest.approx(model.prob.get_val("finance_subgroup_electricity.LCOE")[0], rel=1e-3)
414409
== 0.1385128
415410
)
416411

@@ -427,12 +422,12 @@ def test_hydro_example(subtests):
427422

428423
model.post_process()
429424

430-
print(model.prob.get_val("financials_subgroup_default.LCOE"))
425+
print(model.prob.get_val("finance_subgroup_default.LCOE"))
431426

432427
# Subtests for checking specific values
433428
with subtests.test("Check LCOE"):
434429
assert (
435-
pytest.approx(model.prob.get_val("financials_subgroup_default.LCOE"), rel=1e-3)
430+
pytest.approx(model.prob.get_val("finance_subgroup_default.LCOE"), rel=1e-3)
436431
== 0.17653979
437432
)
438433

@@ -451,7 +446,7 @@ def test_hybrid_energy_plant_example(subtests):
451446

452447
# Subtests for checking specific values
453448
with subtests.test("Check LCOE"):
454-
assert model.prob.get_val("financials_subgroup_default.LCOE", units="USD/MW/h")[0] < 83.2123
449+
assert model.prob.get_val("finance_subgroup_default.LCOE", units="USD/MW/h")[0] < 83.2123
455450

456451

457452
def test_asu_example(subtests):
@@ -470,7 +465,7 @@ def test_asu_example(subtests):
470465
with subtests.test("Check LCON"):
471466
assert (
472467
pytest.approx(
473-
model.prob.get_val("financials_subgroup_default.LCON", units="USD/kg")[0],
468+
model.prob.get_val("finance_subgroup_default.LCON", units="USD/kg")[0],
474469
abs=1e-4,
475470
)
476471
== 0.309041977334972
@@ -491,7 +486,7 @@ def test_hydrogen_dispatch_example(subtests):
491486
with subtests.test("Check LCOE"):
492487
assert (
493488
pytest.approx(
494-
model.prob.get_val("financials_subgroup_elec.LCOE", units="USD/MW/h")[0],
489+
model.prob.get_val("finance_subgroup_elec.LCOE", units="USD/MW/h")[0],
495490
rel=1e-5,
496491
)
497492
== 106.13987
@@ -500,7 +495,7 @@ def test_hydrogen_dispatch_example(subtests):
500495
with subtests.test("Check LCOH"):
501496
assert (
502497
pytest.approx(
503-
model.prob.get_val("financials_subgroup_h2.LCOH", units="USD/kg")[0],
498+
model.prob.get_val("finance_subgroup_h2.LCOH", units="USD/kg")[0],
504499
rel=1e-5,
505500
)
506501
== 5.68452215
@@ -524,17 +519,17 @@ def test_wind_wave_oae_example(subtests):
524519
# Note: These are placeholder values. Update with actual values after running the test
525520
# when MCM package is properly installed and configured
526521
with subtests.test("Check LCOC"):
527-
assert pytest.approx(model.prob.get_val("financials_subgroup_co2.LCOC"), rel=1e-3) == 37.82
522+
assert pytest.approx(model.prob.get_val("finance_subgroup_co2.LCOC"), rel=1e-3) == 37.82
528523

529524
with subtests.test("Check LCOE"):
530525
assert (
531-
pytest.approx(model.prob.get_val("financials_subgroup_electricity.LCOE"), rel=1e-3)
526+
pytest.approx(model.prob.get_val("finance_subgroup_electricity.LCOE"), rel=1e-3)
532527
== 0.36956
533528
)
534529

535530

536531
@unittest.skipUnless(importlib.util.find_spec("mcm") is not None, "mcm is not installed")
537-
def test_wind_wave_oae_example_with_financials(subtests):
532+
def test_wind_wave_oae_example_with_finance(subtests):
538533
# Change the current working directory to the example's directory
539534
os.chdir(EXAMPLE_DIR / "09_co2/ocean_alkalinity_enhancement_financials")
540535

@@ -551,7 +546,7 @@ def test_wind_wave_oae_example_with_financials(subtests):
551546
# when MCM package is properly installed and configured
552547
with subtests.test("Check LCOE"):
553548
assert (
554-
pytest.approx(model.prob.get_val("financials_subgroup_electricity.LCOE"), rel=1e-3)
549+
pytest.approx(model.prob.get_val("finance_subgroup_electricity.LCOE"), rel=1e-3)
555550
== 0.09180
556551
)
557552

@@ -584,38 +579,38 @@ def test_natural_gas_example(subtests):
584579

585580
with subtests.test("Check total electricity produced"):
586581
total_electricity = model.prob.get_val(
587-
"financials_subgroup_default.electricity_sum.total_electricity_produced"
582+
"finance_subgroup_default.electricity_sum.total_electricity_produced"
588583
)[0]
589584
assert pytest.approx(total_electricity, rel=1e-6) == 1.168e8
590585

591586
with subtests.test("Check opex adjusted ng_feedstock"):
592587
opex_ng_feedstock = model.prob.get_val(
593-
"financials_subgroup_default.opex_adjusted_ng_feedstock"
588+
"finance_subgroup_default.opex_adjusted_ng_feedstock"
594589
)[0]
595590
assert pytest.approx(opex_ng_feedstock, rel=1e-6) == 3589463.41463415
596591

597592
with subtests.test("Check capex adjusted natural_gas_plant"):
598593
capex_ng_plant = model.prob.get_val(
599-
"financials_subgroup_default.capex_adjusted_natural_gas_plant"
594+
"finance_subgroup_default.capex_adjusted_natural_gas_plant"
600595
)[0]
601596
assert pytest.approx(capex_ng_plant, rel=1e-6) == 97560975.60975611
602597

603598
with subtests.test("Check opex adjusted natural_gas_plant"):
604599
opex_ng_plant = model.prob.get_val(
605-
"financials_subgroup_default.opex_adjusted_natural_gas_plant"
600+
"finance_subgroup_default.opex_adjusted_natural_gas_plant"
606601
)[0]
607602
assert pytest.approx(opex_ng_plant, rel=1e-6) == 1260487.80487805
608603

609604
with subtests.test("Check total adjusted CapEx"):
610-
total_capex = model.prob.get_val("financials_subgroup_default.total_capex_adjusted")[0]
605+
total_capex = model.prob.get_val("finance_subgroup_default.total_capex_adjusted")[0]
611606
assert pytest.approx(total_capex, rel=1e-6) == 97658536.58536586
612607

613608
with subtests.test("Check total adjusted OpEx"):
614-
total_opex = model.prob.get_val("financials_subgroup_default.total_opex_adjusted")[0]
609+
total_opex = model.prob.get_val("finance_subgroup_default.total_opex_adjusted")[0]
615610
assert pytest.approx(total_opex, rel=1e-6) == 4849951.2195122
616611

617612
with subtests.test("Check LCOE"):
618-
lcoe = model.prob.get_val("financials_subgroup_default.LCOE")[0]
613+
lcoe = model.prob.get_val("finance_subgroup_default.LCOE")[0]
619614
assert pytest.approx(lcoe, rel=1e-6) == 0.12959097
620615

621616
# Test feedstock-specific values
@@ -656,7 +651,7 @@ def test_wind_solar_electrolyzer_example(subtests):
656651
with subtests.test("Check LCOE"):
657652
assert (
658653
pytest.approx(
659-
model.prob.get_val("financials_subgroup_electricity.LCOE", units="USD/MW/h")[0],
654+
model.prob.get_val("finance_subgroup_electricity.LCOE", units="USD/MW/h")[0],
660655
rel=1e-5,
661656
)
662657
== 54.12889
@@ -665,7 +660,7 @@ def test_wind_solar_electrolyzer_example(subtests):
665660
with subtests.test("Check LCOH"):
666661
assert (
667662
pytest.approx(
668-
model.prob.get_val("financials_subgroup_hydrogen.LCOH", units="USD/kg")[0],
663+
model.prob.get_val("finance_subgroup_hydrogen.LCOH", units="USD/kg")[0],
669664
rel=1e-5,
670665
)
671666
== 5.33209234
@@ -693,19 +688,19 @@ def test_electrolyzer_om_example(subtests):
693688

694689
model.run()
695690

696-
lcoe = model.prob.get_val("financials_subgroup_electricity.LCOE", units="USD/MW/h")[0]
697-
lcoh_with_lcoh_financials = model.prob.get_val(
698-
"financials_subgroup_hydrogen.LCOH_lcoh_financials", units="USD/kg"
691+
lcoe = model.prob.get_val("finance_subgroup_electricity.LCOE", units="USD/MW/h")[0]
692+
lcoh_with_lcoh_finance = model.prob.get_val(
693+
"finance_subgroup_hydrogen.LCOH_lcoh_financials", units="USD/kg"
699694
)[0]
700-
lcoh_with_lcoe_financials = model.prob.get_val(
701-
"financials_subgroup_hydrogen.LCOH_lcoe_financials", units="USD/kg"
695+
lcoh_with_lcoe_finance = model.prob.get_val(
696+
"finance_subgroup_hydrogen.LCOH_lcoe_financials", units="USD/kg"
702697
)[0]
703698
with subtests.test("Check LCOE"):
704699
assert pytest.approx(lcoe, rel=1e-5) == 40.12819
705-
with subtests.test("Check LCOH with lcoh_financials"):
706-
assert pytest.approx(lcoh_with_lcoh_financials, rel=1e-5) == 13.18328175
707-
with subtests.test("Check LCOH with lcoe_financials"):
708-
assert pytest.approx(lcoh_with_lcoe_financials, rel=1e-5) == 8.05688467
700+
with subtests.test("Check LCOH with lcoh_finance"):
701+
assert pytest.approx(lcoh_with_lcoh_finance, rel=1e-5) == 13.18328175
702+
with subtests.test("Check LCOH with lcoe_finance"):
703+
assert pytest.approx(lcoh_with_lcoe_finance, rel=1e-5) == 8.05688467
709704

710705

711706
def test_wombat_electrolyzer_example(subtests):
@@ -718,17 +713,17 @@ def test_wombat_electrolyzer_example(subtests):
718713
model.run()
719714

720715
lcoe_with_profast_model = model.prob.get_val(
721-
"financials_subgroup_electricity_profast.LCOE", units="USD/MW/h"
716+
"finance_subgroup_electricity_profast.LCOE", units="USD/MW/h"
722717
)[0]
723718
lcoe_with_custom_model = model.prob.get_val(
724-
"financials_subgroup_electricity_custom.LCOE", units="USD/MW/h"
719+
"finance_subgroup_electricity_custom.LCOE", units="USD/MW/h"
725720
)[0]
726721

727722
lcoh_with_custom_model = model.prob.get_val(
728-
"financials_subgroup_hydrogen.LCOH_produced_custom_model", units="USD/kg"
723+
"finance_subgroup_hydrogen.LCOH_produced_custom_model", units="USD/kg"
729724
)[0]
730725
lcoh_with_profast_model = model.prob.get_val(
731-
"financials_subgroup_hydrogen.LCOH_produced_profast_model", units="USD/kg"
726+
"finance_subgroup_hydrogen.LCOH_produced_profast_model", units="USD/kg"
732727
)[0]
733728

734729
with subtests.test("Check LCOH from custom model"):

0 commit comments

Comments
 (0)