Skip to content

Conversation

@PhFariaa
Copy link

Issue

Description

This PR adds a new automated test file for the REE parser (electricitymap/contrib/capacity_parsers/REE.py) implementing Modified Condition/Decision Coverage (MC/DC) test cases for the fetch_production_capacity method.

The tests cover all internal logical decisions of the function:

C1 → r.status_code == 200

C2 → item["type"] in MODE_MAPPING

C3 → mode in capacity

Four specific test cases (CT1–CT4) were created to ensure independent evaluation of each condition:

CT1 – Valid request, two items of the same type → values are aggregated (C1=T, C2=T, C3=T)

CT2 – Valid request, first occurrence of a mode → initializes new value (C1=T, C2=T, C3=F)

CT3 – Unmapped type → item ignored (C1=T, C2=F)

CT4 – Non-200 HTTP response → request not processed (C1=F)

These tests ensure full MC/DC coverage of the decision logic inside fetch_production_capacity.

Preview

New file added:
electricitymap/contrib/capacity_parsers/tests/test_REE.py

Double check

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

@PhFariaa PhFariaa requested a review from a team as a code owner October 31, 2025 21:04
@github-actions github-actions bot added python Pull requests that update Python code capacity parser labels Oct 31, 2025
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test but please make sure that we don't duplicate mock functionality from the library itself and that all comments are in english.

Comment on lines +6 to +22
class FakeResponse:
def __init__(self, status_code: int, payload: dict):
self.status_code = status_code
self._payload = payload

def json(self):
return self._payload


class FakeSession:
def __init__(self, response: FakeResponse):
self._response = response
self.last_call = None

def get(self, url, params=None):
self.last_call = (url, params)
return self._response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be faked. There is already mock versions in the request library that should be used for testing.

Comment on lines +25 to +41
def _patch_minimal_mappings(monkeypatch):
"""
Para tornar o teste independente do conteúdo real de REE.py,
reduzimos os dicionários a um caso mínimo estável.
"""
monkeypatch.setattr(REE, "ZONE_KEY_TO_GEO_LIMIT", {"ES": "system"}, raising=False)
monkeypatch.setattr(REE, "GEO_LIMIT_TO_GEO_IDS", {"system": "es"}, raising=False)
# Mapeamento mínimo de tipos → modes
monkeypatch.setattr(
REE,
"MODE_MAPPING",
{
"solar": "solar",
"hydro": "hydro",
},
raising=False,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this mocked?

Also please use english so other community members and our employees can understand the comments (including me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capacity parser python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants