Skip to content

Commit ee47115

Browse files
committed
fix?
1 parent bc79807 commit ee47115

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

packages/aws-library/src/aws_library/ec2/_models.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,43 @@ def create_as_empty(cls) -> "Resources":
4646
def __ge__(self, other: "Resources") -> bool:
4747
"""operator for >= comparison
4848
if self has greater or equal resources than other, returns True
49+
This will return True only if any of the resources in self is greater or equal to other
50+
4951
Note that generic_resources are compared only if they are numeric
5052
Non-numeric generic resources must be equal in both or only defined in self
5153
to be considered greater or equal
5254
"""
55+
if self == other:
56+
return True
57+
return self > other
58+
59+
def __gt__(self, other: "Resources") -> bool:
60+
"""operator for > comparison
61+
if self has any resources gretaer than other, returns True (even if different resource types are smaller)
5362
54-
if not (self.cpus >= other.cpus and self.ram >= other.ram):
55-
return False
63+
Note that generic_resources are compared only if they are numeric
64+
Non-numeric generic resources must be equal in both or only defined in self
65+
to be considered greater
66+
"""
67+
if (self.cpus > other.cpus) or (self.ram > other.ram):
68+
return True
5669

5770
keys = set(self.generic_resources) | set(other.generic_resources)
5871
for k in keys:
5972
a = self.generic_resources.get(k)
60-
b = other.generic_resources.get(
61-
k, a
62-
) # NOTE: get from other, default to "a" resources so that non-existing keys can be compared as equal
73+
b = other.generic_resources.get(k)
74+
if a is None:
75+
continue
76+
if b is None:
77+
return True
6378
if isinstance(a, int | float) and isinstance(b, int | float):
64-
if a < b:
65-
return False
79+
if a > b:
80+
return True
6681
elif a != b:
6782
assert isinstance(a, str | None) # nosec
6883
assert isinstance(b, int | float | str | None) # nosec
69-
return False
70-
return True
71-
72-
def __gt__(self, other: "Resources") -> bool:
73-
"""operator for > comparison
74-
if self has greater resources than other, returns True
75-
Note that generic_resources are compared only if they are numeric
76-
Non-numeric generic resources must be equal in both or only defined in self
77-
to be considered greater
78-
"""
79-
return self >= other and self != other
84+
return True
85+
return False
8086

8187
def __add__(self, other: "Resources") -> "Resources":
8288
"""operator for adding two Resources

packages/aws-library/tests/test_ec2_models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
(
3737
Resources(cpus=0.05, ram=ByteSize(1)),
3838
Resources(cpus=0.1, ram=ByteSize(0)),
39-
False,
39+
True, # ram is larger
4040
),
4141
(
4242
Resources(cpus=0.1, ram=ByteSize(0)),
@@ -46,7 +46,7 @@
4646
(
4747
Resources(cpus=0.1, ram=ByteSize(0), generic_resources={"GPU": 1}),
4848
Resources(cpus=0.1, ram=ByteSize(1)),
49-
False, # ram is not enough
49+
True, # GPU is larger
5050
),
5151
(
5252
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": 1}),
@@ -71,7 +71,7 @@
7171
(
7272
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": "2"}),
7373
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": 2}),
74-
False,
74+
True, # string resrouces are not comparable so "2" is considered larger
7575
),
7676
(
7777
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"SSE": "yes"}),
@@ -117,7 +117,7 @@ def test_resources_ge_operator(
117117
(
118118
Resources(cpus=0.05, ram=ByteSize(1)),
119119
Resources(cpus=0.1, ram=ByteSize(0)),
120-
False,
120+
True,
121121
),
122122
(
123123
Resources(cpus=0.1, ram=ByteSize(0)),
@@ -127,7 +127,7 @@ def test_resources_ge_operator(
127127
(
128128
Resources(cpus=0.1, ram=ByteSize(0), generic_resources={"GPU": 1}),
129129
Resources(cpus=0.1, ram=ByteSize(1)),
130-
False, # ram is not enough
130+
True, # ram is not enough
131131
),
132132
(
133133
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": 1}),
@@ -152,7 +152,7 @@ def test_resources_ge_operator(
152152
(
153153
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": "2"}),
154154
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"GPU": 2}),
155-
False,
155+
True, # string resources are not comparable, so a > b
156156
),
157157
(
158158
Resources(cpus=0.1, ram=ByteSize(1), generic_resources={"SSE": "yes"}),

services/autoscaling/tests/unit/test_modules_cluster_scaling_computational.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,6 @@ async def test_cluster_does_not_scale_up_if_defined_instance_is_not_fitting_reso
934934
[InstanceTypeType | None, Resources], DaskTaskResources
935935
],
936936
ec2_client: EC2Client,
937-
faker: Faker,
938937
caplog: pytest.LogCaptureFixture,
939938
):
940939
# we have nothing running now

0 commit comments

Comments
 (0)