Skip to content

Commit

Permalink
UPDATE carbon_footprint.py - add exempted_emissions_description attri…
Browse files Browse the repository at this point in the history
…bute to CarbonFootprint
  • Loading branch information
JohnVonNeumann committed Jul 16, 2024
1 parent e558aeb commit 8106c90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pathfinder_framework/carbon_footprint/carbon_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CarbonFootprint:
ipcc_characterization_factors_sources (list[str]): The characterization factors from one or more IPCC Assessment Reports used in the calculation of the PCF.
cross_sectoral_standards_used (list[CrossSectoralStandard]): The cross-sectoral standards applied for calculating or allocating GHG emissions.
exempted_emissions_percent (float): The Percentage of emissions excluded from PCF, expressed as a decimal number between 0.0 and 5 including.
exempted_emissions_description (str): Rationale behind exclusion of specific PCF emissions, can be the empty string if no emissions were excluded.
reference_period (ReferencePeriod): The period over which the data was recorded for the Carbon Footprint_
packaging_emissions_included (bool): A boolean flag indicating whether packaging emissions are included in the PCF (pCfExcludingBiogenic, pCfIncludingBiogenic).
geographical_scope (CarbonFootprintGeographicalScope): The geographical scope of the carbon footprint.
Expand Down Expand Up @@ -66,6 +67,7 @@ def __init__(
cross_sectoral_standards_used,
boundary_processes_description,
exempted_emissions_percent,
exempted_emissions_description,
reference_period,
packaging_emissions_included,
geographical_scope,
Expand Down Expand Up @@ -120,6 +122,8 @@ def __init__(
raise ValueError("boundary_processes_description must not be empty")
if not 0.0 <= exempted_emissions_percent <= 5.0:
raise ValueError("exempted_emissions_percent must be between 0.0 and 5.0")
if not isinstance(exempted_emissions_description, str):
raise ValueError("exempted_emissions_description must be a string")
if not isinstance(reference_period, ReferencePeriod):
raise ValueError("reference_period must be an instance of ReferencePeriod")
if not isinstance(packaging_emissions_included, bool):
Expand Down Expand Up @@ -214,6 +218,7 @@ def __init__(
self.cross_sectoral_standards_used = cross_sectoral_standards_used
self.boundary_processes_description = boundary_processes_description
self.exempted_emissions_percent = exempted_emissions_percent
self.exempted_emissions_description = exempted_emissions_description
self.reference_period = reference_period
self.packaging_emissions_included = packaging_emissions_included
self.geographical_scope = geographical_scope
Expand Down
13 changes: 13 additions & 0 deletions tests/carbon_footprint/test_carbon_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def valid_carbon_footprint_data():
"cross_sectoral_standards_used": [CrossSectoralStandard.GHG_PROTOCOL],
"boundary_processes_description": "boundary processes description",
"exempted_emissions_percent": 1.0,
"exempted_emissions_description": "Rationale for exclusion",
"reference_period": ReferencePeriod(start=DateTime.now(), end=DateTime.now()),
"packaging_emissions_included": True,
"geographical_scope": CarbonFootprintGeographicalScope(
Expand Down Expand Up @@ -141,6 +142,10 @@ def test_carbon_footprint_attributes(valid_carbon_footprint_data):
carbon_footprint.exempted_emissions_percent
== valid_carbon_footprint_data["exempted_emissions_percent"]
)
assert (
carbon_footprint.exempted_emissions_description
== valid_carbon_footprint_data["exempted_emissions_description"]
)
assert isinstance(carbon_footprint.reference_period, ReferencePeriod)
assert (
carbon_footprint.packaging_emissions_included
Expand Down Expand Up @@ -310,6 +315,14 @@ def test_carbon_footprint_invalid_exempted_emissions_percent(
)


def test_carbon_footprint_invalid_exempted_emissions_description(valid_carbon_footprint_data):
invalid_data = valid_carbon_footprint_data.copy()
invalid_data["exempted_emissions_description"] = 123 # Invalid type
with pytest.raises(ValueError) as excinfo:
CarbonFootprint(**invalid_data)
assert str(excinfo.value) == "exempted_emissions_description must be a string"


def test_carbon_footprint_invalid_reference_period(valid_carbon_footprint_data):
invalid_data = valid_carbon_footprint_data.copy()
invalid_data["reference_period"] = "invalid reference period"
Expand Down
1 change: 1 addition & 0 deletions tests/product_footprint/test_product_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def valid_carbon_footprint_data():
"cross_sectoral_standards_used": [CrossSectoralStandard.GHG_PROTOCOL],
"boundary_processes_description": "boundary processes description",
"exempted_emissions_percent": 1.0,
"exempted_emissions_description": "Rationale for exclusion",
"reference_period": ReferencePeriod(start=DateTime.now(), end=DateTime.now()),
"packaging_emissions_included": True,
"geographical_scope": CarbonFootprintGeographicalScope(
Expand Down

0 comments on commit 8106c90

Please sign in to comment.