Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
brightpath/data/**/*.json text eol=lf
brightpath/data/export/simapro_categories/*.csv text eol=lf
8 changes: 2 additions & 6 deletions brightpath/background/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,7 @@ def _apply_biosphere_step(
target_biosphere_identities=target_biosphere_identities,
)
_apply_factored_biosphere_replacements(data, factored_replacements, step.direction, report)
_apply_unambiguous_biosphere_compartment_fallback(
data, target_biosphere_identities, report
)
_apply_unambiguous_biosphere_compartment_fallback(data, target_biosphere_identities, report)
return report, losses


Expand Down Expand Up @@ -910,9 +908,7 @@ def _apply_unambiguous_biosphere_compartment_fallback(
)


def _biosphere_compartments_are_related(
source: tuple[str, ...], target: tuple[str, ...]
) -> bool:
def _biosphere_compartments_are_related(source: tuple[str, ...], target: tuple[str, ...]) -> bool:
"""Return whether two category paths differ only by parent/child depth."""
return source == target[: len(source)] or target == source[: len(target)]

Expand Down
18 changes: 4 additions & 14 deletions tests/test_background_migration_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ def test_reverse_biosphere_migration_falls_back_to_unique_child_compartment():

assert result.succeeded, result.report.to_dict()
assert result.value.data[0]["exchanges"][0]["categories"] == list(target_identity[1])
assert "migration.biosphere_parent_compartment_fallback" in {
issue.code for issue in result.report.issues
}
assert "migration.biosphere_parent_compartment_fallback" in {issue.code for issue in result.report.issues}


def test_reverse_preference_resolves_polystyrene_fae_without_ambiguity():
Expand Down Expand Up @@ -622,22 +620,14 @@ def test_unrepresentable_biosphere_unit_change_is_removed_with_a_warning():

assert result.succeeded
assert result.value.data[0]["exchanges"] == []
assert "migration.biosphere_exchange_removed_unsafe_unit" in {
issue.code for issue in result.report.issues
}
assert "migration.biosphere_exchange_removed_unsafe_unit" in {
loss.code for loss in result.report.losses
}
assert "migration.biosphere_exchange_removed_unsafe_unit" in {issue.code for issue in result.report.issues}
assert "migration.biosphere_exchange_removed_unsafe_unit" in {loss.code for loss in result.report.losses}


@pytest.mark.parametrize("reverse", [False, True])
def test_standard_cubic_meter_and_sm3_biosphere_units_use_a_factor_of_one(reverse):
resource = load_biosphere_resources()[("3.8", "3.9")]
rule = next(
rule
for rule in resource["replace"]
if rule["source"]["name"] == "Gas, natural, in ground"
)
rule = next(rule for rule in resource["replace"] if rule["source"]["name"] == "Gas, natural, in ground")
source = background("3.9", "3.9") if reverse else background("3.8", "3.8")
target = background("3.8", "3.8") if reverse else background("3.9", "3.9")
source_specification = rule["target"] if reverse else rule["source"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simapro_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def test_write_csv_rejects_wrong_suffix_and_normalizes_non_latin1_text(tmp_path)
with path.open(newline="", encoding="latin-1") as handle:
cells = [cell for row in csv.reader(handle, delimiter=";") for cell in row]
comment = next(cell for cell in cells if "unsupported snowman" in cell)
assert f"25 \N{DEGREE SIGN}C-50 \N{DEGREE SIGN}C" in comment
assert "25 \N{DEGREE SIGN}C-50 \N{DEGREE SIGN}C" in comment
assert "CO2 reuse" in comment
assert 'smart quotes "ok"' in comment
assert "unsupported snowman: ?" in comment
Expand Down
Loading