Skip to content

Commit

Permalink
Small updates to tests (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineechen committed Mar 21, 2024
1 parent a0b6c70 commit 0cf1e88
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
1 change: 0 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ tqdm

# packages for local and unit tests
boto3
skypilot[docker]
docker
s3fs
pandas
Expand Down
20 changes: 15 additions & 5 deletions tests/test_resources/test_clusters/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import tests.test_resources.test_resource
from tests.conftest import init_args
from tests.utils import get_random_str
from tests.utils import get_random_str, remove_config_keys

""" TODO:
1) In subclasses, test factory methods create same type as parent
Expand Down Expand Up @@ -160,7 +160,7 @@ def test_cluster_endpoint(self, cluster):
headers=rh.globals.rns_client.request_headers(),
)
assert r.status_code == 200
assert r.json()["resource_subtype"] == "Cluster"
assert r.json()["resource_type"] == "cluster"

@pytest.mark.level("local")
def test_cluster_objects(self, cluster):
Expand Down Expand Up @@ -292,14 +292,24 @@ def test_rh_status_stopped(self, cluster):
def test_condensed_config_for_cluster(self, cluster):
import ast

return_codes = cluster.run_python(["import runhouse as rh", "print(rh.here)"])
return_codes = cluster.run_python(
["import runhouse as rh", "print(rh.here)"], stream_logs=False
)
assert return_codes[0][0] == 0

on_cluster_config = ast.literal_eval(return_codes[0][1])
cluster_config = cluster.config()

on_cluster_config.pop("creds", None)
cluster_config.pop("creds", None)
keys_to_skip = ["creds", "client_port", "server_host"]
on_cluster_config = remove_config_keys(on_cluster_config, keys_to_skip)
cluster_config = remove_config_keys(cluster_config, keys_to_skip)

if cluster_config.get("stable_internal_external_ips", False):
cluster_ips = cluster_config.pop("stable_internal_external_ips", None)[0]
on_cluster_ips = on_cluster_config.pop(
"stable_internal_external_ips", None
)[0]
assert tuple(cluster_ips) == tuple(on_cluster_ips)

assert on_cluster_config == cluster_config

Expand Down
14 changes: 11 additions & 3 deletions tests/test_resources/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import runhouse as rh

from tests.conftest import init_args
from tests.utils import friend_account
from tests.utils import friend_account, remove_config_keys


def load_shared_resource_config(resource_class_name, address):
Expand Down Expand Up @@ -74,10 +74,18 @@ def test_from_config(self, resource):
def test_save_and_load(self, saved_resource):
# Test loading from name
loaded_resource = saved_resource.__class__.from_name(saved_resource.rns_address)
assert loaded_resource.config() == saved_resource.config()
# Changing the name doesn't work for OnDemandCluster, because the name won't match the local sky db

if isinstance(saved_resource, rh.OnDemandCluster):
loaded_resource_config = remove_config_keys(
loaded_resource.config(), ["stable_internal_external_ips"]
)
saved_resource_config = remove_config_keys(
saved_resource.config(), ["stable_internal_external_ips"]
)
assert loaded_resource_config == saved_resource_config
# Changing the name doesn't work for OnDemandCluster, because the name won't match the local sky db
return
assert loaded_resource.config() == saved_resource.config()

# Do everything inside a try/finally so we don't leave resources behind if the test fails
try:
Expand Down
6 changes: 6 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ def test_env(logged_in=False):
else False,
name="base_env",
)


def remove_config_keys(config, keys_to_skip):
for key in keys_to_skip:
config.pop(key, None)
return config

0 comments on commit 0cf1e88

Please sign in to comment.