-
Notifications
You must be signed in to change notification settings - Fork 1k
test: add unit tests for REE.fetch_production_capacity functionality #8463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
test: add unit tests for REE.fetch_production_capacity functionality #8463
Conversation
VIKTORVAV99
left a comment
There was a problem hiding this 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.
| 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 |
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
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).
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
poetry run test_parser "zone_key"pnpx prettier@2 --write .andpoetry run formatin the top level directory to format my changes.