Skip to content

Commit

Permalink
Internal linking LCIA tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Jul 6, 2024
1 parent 6476d3d commit 44ad985
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/fixtures/internal_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"input": ("internal", "🐶"),
"amount": 40,
"properties": {
"price": 7,
"price": 2.5,
"mass": 6,
},
},
Expand All @@ -72,9 +72,9 @@
"name": "second product - 1",
"desired_code": "second - generated",
"unit": "megajoule",
"amount": 60,
"amount": 50,
"properties": {
"price": 12,
"price": 2,
"mass": 4,
},
},
Expand Down
28 changes: 28 additions & 0 deletions tests/test_internal_linking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,31 @@ def test_internal_linking_results_unchanged(internal):

def test_internal_linking_results_mf_process_1(internal):
p = bd.get_node(type="multifunctional", name="process - 1")
assert p["location"] == "first"
assert not p.get("unit")
assert not p.get("reference product")

assert len(list(p.exchanges())) == 3
assert len(list(p.production())) == 2
assert {exc["input"] for exc in p.production()} == {
("internal", "first - generated"),
("internal", "😼"),
}


def test_internal_linking_results_mf_process_2(internal):
p = bd.get_node(type="multifunctional", name="process - 2")
assert p["location"] == "second"
assert not p.get("unit")
assert not p.get("reference product")

assert len(list(p.exchanges())) == 4
assert len(list(p.production())) == 2
assert {exc["input"] for exc in p.production()} == {
("internal", "second - generated"),
("internal", "🐶"),
}


def test_internal_linking_allocated_dog(internal):
pass
19 changes: 19 additions & 0 deletions tests/test_lcia.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ def test_lcia_scores(basic):
lca.lci()
lca.lcia()
assert math.isclose(lca.score, 6 * 12 / (4 * 7 + 6 * 12) * 10 * 5 / 6, rel_tol=1e-5)


def test_internal_linking_lcia_scores(internal):
flow = bd.get_node(code="a")
m = bd.Method(("foo",))
m.register()
m.write([(flow.id, 1)])

fu, objs, _ = bd.prepare_lca_inputs(demand={bd.get_node(code="😼"): 1}, method=("foo",))
lca = bc.LCA(fu, data_objs=objs)
lca.lci()
lca.lcia()
assert math.isclose(lca.score, 0.28 * 2.5, rel_tol=1e-5)

fu, objs, _ = bd.prepare_lca_inputs(demand={bd.get_node(code="🐶"): 1}, method=("foo",))
lca = bc.LCA(fu, data_objs=objs)
lca.lci()
lca.lcia()
assert math.isclose(lca.score, (0.28 * 2.5 * 50 + 0.72 * 10 / 6 * 5) / 40, rel_tol=1e-5)

0 comments on commit 44ad985

Please sign in to comment.