Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion olive/cli/shared_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ def register_subcommand(parser):
help="Confirm the deletion without prompting for confirmation.",
)
sub_parser.add_argument(
"--account_name",
"--account",
type=str,
required=True,
help="The account name for the shared cache.",
)
sub_parser.add_argument(
"--container_name",
"--container",
type=str,
required=True,
Expand All @@ -53,7 +55,7 @@ def register_subcommand(parser):

@action
def run(self):
container_client_factory = AzureContainerClientFactory(self.args.account, self.args.container)
container_client_factory = AzureContainerClientFactory(self.args.account_name, self.args.container_name)
if self.args.delete:
if self.args.all:
if self.args.yes:
Expand All @@ -63,4 +65,6 @@ def run(self):
if confirm.lower() == "y":
container_client_factory.delete_all()
else:
if not self.args.model_hash:
raise ValueError("--model_hash is required when --delete is used without --all")
container_client_factory.delete_blob(self.args.model_hash)
45 changes: 45 additions & 0 deletions test/cli/test_shared_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from argparse import ArgumentParser

import pytest

from olive.cli.shared_cache import SharedCacheCommand


def _parse_shared_cache_args(*args: str):
parser = ArgumentParser()
subparsers = parser.add_subparsers()
SharedCacheCommand.register_subcommand(subparsers)
return parser.parse_args(["shared-cache", *args])


@pytest.mark.parametrize(
("account_option", "container_option"),
[
("--account_name", "--container_name"),
("--account", "--container"),
],
)
def test_shared_cache_accepts_consistent_and_legacy_option_names(account_option: str, container_option: str):
args = _parse_shared_cache_args(account_option, "account", container_option, "container")

assert args.account_name == "account"
assert args.container_name == "container"


def test_shared_cache_delete_requires_model_hash():
args = _parse_shared_cache_args(
"--delete",
"--account_name",
"account",
"--container_name",
"container",
)
command = object.__new__(SharedCacheCommand)
command.args = args

with pytest.raises(ValueError, match="--model_hash is required"):
command.run()
Loading