|
4 | 4 | import numpy as np
|
5 | 5 | import pytest
|
6 | 6 |
|
7 |
| -from bw2calc import MultiLCA |
| 7 | +from bw2calc import MethodConfig, MultiLCA |
8 | 8 | from bw2calc.utils import get_datapackage
|
9 | 9 |
|
10 | 10 | # Technosphere
|
@@ -47,6 +47,16 @@ def config():
|
47 | 47 | }
|
48 | 48 |
|
49 | 49 |
|
| 50 | +@pytest.fixture |
| 51 | +def method_config(): |
| 52 | + return MethodConfig( |
| 53 | + impact_categories=[ |
| 54 | + ("first", "category"), |
| 55 | + ("second", "category"), |
| 56 | + ] |
| 57 | + ) |
| 58 | + |
| 59 | + |
50 | 60 | @pytest.fixture
|
51 | 61 | def func_units():
|
52 | 62 | return {
|
@@ -127,6 +137,16 @@ def test_single_demand(dps, config):
|
127 | 137 | assert mlca.scores[(("second", "category"), "γ")] == 3 * 10
|
128 | 138 |
|
129 | 139 |
|
| 140 | +def test_single_demand_method_config(dps, method_config): |
| 141 | + single_func_unit = {"γ": {100: 1}} |
| 142 | + mlca = MultiLCA(demands=single_func_unit, method_config=method_config, data_objs=dps) |
| 143 | + mlca.lci() |
| 144 | + mlca.lcia() |
| 145 | + |
| 146 | + assert mlca.scores[(("first", "category"), "γ")] == 8 + 3 |
| 147 | + assert mlca.scores[(("second", "category"), "γ")] == 3 * 10 |
| 148 | + |
| 149 | + |
130 | 150 | def test_normalization(dps, func_units):
|
131 | 151 | config = {
|
132 | 152 | "impact_categories": [
|
@@ -528,7 +548,7 @@ def test_monte_carlo_multiple_iterations_selective_use_in_list_comprehension(dps
|
528 | 548 | assert np.unique(lst).shape == (10,)
|
529 | 549 |
|
530 | 550 |
|
531 |
| -def test_bug_108(dps, config, func_units): |
| 551 | +def test_bug_108(dps, func_units): |
532 | 552 | # https://github.com/brightway-lca/brightway2-calc/issues/108
|
533 | 553 | config = {
|
534 | 554 | "impact_categories": [
|
@@ -574,3 +594,39 @@ def test_bug_108(dps, config, func_units):
|
574 | 594 | == 3 * (3 * 10 + 1 * 10) * 84
|
575 | 595 | )
|
576 | 596 | assert mlca.scores[(("w", "1"), ("n", "1"), ("first", "category"), "γ")] == 3 * 42
|
| 597 | + |
| 598 | + |
| 599 | +def test_pass_full_methodconfig(dps, func_units): |
| 600 | + method_config = MethodConfig( |
| 601 | + impact_categories=[ |
| 602 | + ("first", "category"), |
| 603 | + ("second", "category"), |
| 604 | + ], |
| 605 | + normalizations={ |
| 606 | + ("n", "1"): [("first", "category")], |
| 607 | + ("n", "2"): [("second", "category")], |
| 608 | + }, |
| 609 | + weightings={ |
| 610 | + ("w", "1"): [("n", "1")], |
| 611 | + ("w", "2"): [("n", "2")], |
| 612 | + }, |
| 613 | + ) |
| 614 | + |
| 615 | + dps.append( |
| 616 | + get_datapackage(fixture_dir / "multi_lca_simple_normalization.zip"), |
| 617 | + ) |
| 618 | + dps.append( |
| 619 | + get_datapackage(fixture_dir / "multi_lca_simple_weighting.zip"), |
| 620 | + ) |
| 621 | + |
| 622 | + mlca = MultiLCA(demands=func_units, method_config=method_config, data_objs=dps) |
| 623 | + mlca.lci() |
| 624 | + mlca.lcia() |
| 625 | + mlca.normalize() |
| 626 | + mlca.weight() |
| 627 | + |
| 628 | + assert ( |
| 629 | + mlca.scores[(("w", "2"), ("n", "2"), ("second", "category"), "ζ")] |
| 630 | + == 3 * (3 * 10 + 1 * 10) * 84 |
| 631 | + ) |
| 632 | + assert mlca.scores[(("w", "1"), ("n", "1"), ("first", "category"), "γ")] == 3 * 42 |
0 commit comments