mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
Add type validation for ray.autoscaler.sdk.request_resources()(#26626)
Adds type validation to ray.autoscaler.sdk.request_resources().
This commit is contained in:
parent
081bbfbff1
commit
5bd8d121b2
2 changed files with 31 additions and 0 deletions
|
@ -240,6 +240,22 @@ def request_resources(
|
|||
>>> request_resources( # doctest: +SKIP
|
||||
... bundles=[{"CPU": 1}, {"CPU": 1}, {"CPU": 1}])
|
||||
"""
|
||||
if num_cpus is not None and not isinstance(num_cpus, int):
|
||||
raise TypeError("num_cpus should be of type int.")
|
||||
if bundles is not None:
|
||||
if isinstance(bundles, List):
|
||||
for bundle in bundles:
|
||||
if isinstance(bundle, Dict):
|
||||
for key in bundle.keys():
|
||||
if not (isinstance(key, str) and isinstance(bundle[key], int)):
|
||||
raise TypeError(
|
||||
"each bundle key should be str and value as int."
|
||||
)
|
||||
else:
|
||||
raise TypeError("each bundle should be a Dict.")
|
||||
else:
|
||||
raise TypeError("bundles should be of type List")
|
||||
|
||||
return commands.request_resources(num_cpus, bundles)
|
||||
|
||||
|
||||
|
|
|
@ -3561,6 +3561,21 @@ MemAvailable: 33000000 kB
|
|||
monitor.run()
|
||||
mock_publish.assert_called_once()
|
||||
|
||||
def testInitializeSDKArguments(self):
|
||||
# https://github.com/ray-project/ray/issues/23166
|
||||
from ray.autoscaler.sdk import request_resources
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
request_resources(num_cpus="bar")
|
||||
with self.assertRaises(TypeError):
|
||||
request_resources(bundles="bar")
|
||||
with self.assertRaises(TypeError):
|
||||
request_resources(bundles=["foo"])
|
||||
with self.assertRaises(TypeError):
|
||||
request_resources(bundles=[{"foo": "bar"}])
|
||||
with self.assertRaises(TypeError):
|
||||
request_resources(bundles=[{"foo": 1}, {"bar": "baz"}])
|
||||
|
||||
|
||||
def test_import():
|
||||
"""This test ensures that all the autoscaler imports work as expected to
|
||||
|
|
Loading…
Add table
Reference in a new issue