Repository navigation
chargepoint peaks: fix cp sum in case of error #3585
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| from dataclasses import dataclass | ||
| from typing import List | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| from control import data | ||
| from control.chargepoint.chargepoint import Chargepoint | ||
| from control.chargepoint.chargepoint_all import AllChargepoints | ||
| from helpermodules.constants import NO_ERROR | ||
|
|
||
|
|
||
| @dataclass | ||
| class Params: | ||
| name: str | ||
| cp_values: List[Chargepoint] | ||
| expected_power: float | ||
| expected_imported: float | ||
| expected_exported: float | ||
| expected_fault_state: int | ||
| expected_fault_str: str | ||
|
|
||
|
|
||
| def cp_mock(num: int, imported: float, exported: float, power: float, fault_state: int) -> Mock: | ||
| return Mock(spec=Chargepoint, num=num, data=Mock(get=Mock(imported=imported, | ||
| exported=exported, | ||
| power=power, | ||
| fault_state=fault_state))) | ||
|
|
||
|
|
||
| cases = [ | ||
| Params( | ||
| name="Alle Ladepunkte fehlerfrei", | ||
| cp_values=[ | ||
| cp_mock(1, 1000, 100, 1200, 0), | ||
| cp_mock(2, 2000, 200, 2400, 0), | ||
| ], | ||
| expected_power=3600, | ||
| expected_imported=3000, | ||
| expected_exported=300, | ||
| expected_fault_state=0, | ||
| expected_fault_str=NO_ERROR, | ||
| ), | ||
| Params( | ||
| name="Mindestens ein Ladepunkt mit Fehler", | ||
| cp_values=[ | ||
| cp_mock(1, 1000, 100, 1200, 0), | ||
| cp_mock(2, 2000, 200, 2400, 2), | ||
| ], | ||
| expected_power=3600, | ||
| expected_imported=3000, | ||
| expected_exported=300, | ||
| expected_fault_state=2, | ||
| expected_fault_str=( | ||
| "Bitte die Statusmeldungen der Ladepunkte prüfen. " | ||
| "Es haben nicht alle Ladepunkte aktuelle Zählerstände geliefert." | ||
| ), | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("params", cases, ids=[c.name for c in cases]) | ||
| def test_get_cp_sum(params: Params): | ||
| # setup | ||
| data.data_init(Mock()) | ||
| data.data.cp_data = {f"cp{index}": cp for index, cp in enumerate(params.cp_values)} | ||
| cp_all = AllChargepoints() | ||
|
|
||
| # execution | ||
| cp_all.get_cp_sum() | ||
|
|
||
| # evaluation | ||
| assert cp_all.data.get.power == params.expected_power | ||
| assert cp_all.data.get.imported == params.expected_imported | ||
| assert cp_all.data.get.exported == params.expected_exported | ||
| assert cp_all.data.get.fault_state == params.expected_fault_state | ||
| assert cp_all.data.get.fault_str == params.expected_fault_str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.