From 5066f68e2d8c792045d69c10b7778773da2c13c7 Mon Sep 17 00:00:00 2001 From: Daniel Hou Date: Fri, 4 Oct 2024 15:27:42 -0400 Subject: [PATCH] Hi Mom --- tests/test_carbon.py | 4 ++-- zeus/carbon.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/test_carbon.py b/tests/test_carbon.py index adfad10c..b5d0bda7 100644 --- a/tests/test_carbon.py +++ b/tests/test_carbon.py @@ -9,7 +9,7 @@ from zeus.carbon import ( ElectrictyMapsClient, get_ip_lat_long, - CarbonIntensityNotFoundError, + ZeusCarbonIntensityNotFoundError, ) @@ -100,5 +100,5 @@ def test_get_current_carbon_intensity_no_response(mock_requests): assert latlong == (pytest.approx(42.2776), pytest.approx(-83.7409)) provider = ElectrictyMapsClient(latlong) - with pytest.raises(CarbonIntensityNotFoundError): + with pytest.raises(ZeusCarbonIntensityNotFoundError): provider.get_current_carbon_intensity() diff --git a/zeus/carbon.py b/zeus/carbon.py index 000d9bc9..7b5cbeff 100644 --- a/zeus/carbon.py +++ b/zeus/carbon.py @@ -28,7 +28,7 @@ def get_ip_lat_long() -> tuple[float, float]: raise -class CarbonIntensityNotFoundError(ZeusBaseError): +class ZeusCarbonIntensityNotFoundError(ZeusBaseError): """Exception when carbon intensity measurement could not be retrieved.""" def __init__(self, message: str) -> None: @@ -51,9 +51,7 @@ class ElectrictyMapsClient(CarbonIntensityProvider): Reference: 1. [ElectricityMaps](https://www.electricitymaps.com/) - 2. [ElectricityMaps API](https://static.electricitymaps.com/api/docs/index.html) - 3. [ElectricityMaps GitHub](https://github.com/electricitymaps/electricitymaps-contrib) """ @@ -80,6 +78,7 @@ def get_current_carbon_intensity(self) -> float: !!! Note In some locations, there is no recent carbon intensity data. `self.estimate` can be used to approximate the carbon intensity in such cases. """ + resp = None try: url = ( f"https://api.electricitymap.org/v3/carbon-intensity/latest?lat={self.lat}&lon={self.long}" @@ -90,9 +89,10 @@ def get_current_carbon_intensity(self) -> float: return resp.json()["carbonIntensity"] except KeyError as e: # Raise exception when carbonIntensity does not exist in response - raise CarbonIntensityNotFoundError( + raise ZeusCarbonIntensityNotFoundError( f"Recent carbon intensity measurement not found at `({self.lat}, {self.long})` " - f"with estimate set to `{self.estimate}` and emission_factor_type set to `{self.emission_factor_type}`" + f"with estimate set to `{self.estimate}` and emission_factor_type set to `{self.emission_factor_type}`\n" + f"JSON Response: {resp.text}" ) from e except requests.exceptions.RequestException as e: logger.exception(