-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle resources allocation with scientific notation better (#361)
- Loading branch information
1 parent
94d0063
commit 3d7c9a1
Showing
3 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -133,3 +133,4 @@ dmypy.json | |
.DS_Store | ||
robusta_lib | ||
.idea | ||
.vscode |
This file contains 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 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,36 @@ | ||
from typing import Union | ||
|
||
import pytest | ||
|
||
from robusta_krr.core.models.allocations import ResourceAllocations, ResourceType | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"cpu", | ||
[ | ||
{"request": "5m", "limit": None}, | ||
{"request": 0.005, "limit": None}, | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"memory", | ||
[ | ||
{"request": 128974848, "limit": 128974848}, | ||
{"request": 128.974848e6, "limit": 128.974848e6}, | ||
{"request": "128.9748480M", "limit": "128.9748480M"}, | ||
{"request": "128974848000m", "limit": "128974848000m"}, | ||
{"request": "123Mi", "limit": "123Mi"}, | ||
{"request": "128974848e0", "limit": "128974848e0"}, | ||
], | ||
) | ||
def test_resource_allocation_supported_formats( | ||
cpu: dict[str, Union[str, int, float, None]], memory: dict[str, Union[str, int, float, None]] | ||
): | ||
allocations = ResourceAllocations( | ||
requests={ResourceType.CPU: cpu["request"], ResourceType.Memory: memory["request"]}, | ||
limits={ResourceType.CPU: cpu["limit"], ResourceType.Memory: memory["limit"]}, | ||
) | ||
assert allocations.requests[ResourceType.CPU] == 0.005 | ||
assert allocations.limits[ResourceType.CPU] == None | ||
assert (allocations.requests[ResourceType.Memory] // 1) == 128974848.0 | ||
assert (allocations.limits[ResourceType.Memory] // 1) == 128974848.0 |