Skip to content

Commit

Permalink
MAINT: Partially address PR comments re: logging
Browse files Browse the repository at this point in the history
Switches to logging instead of print statements
Use assert_* methods instead of manually emulating similar effects by
using call_count and arg_list parameters with assert
  • Loading branch information
DavidFair committed Mar 4, 2024
1 parent 3e8d203 commit 9bea2f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions scripts/test/test_upload_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def test_upload_images_to_openstack_dry_run():

with mock.patch("upload_all.upload_single_image") as mocked_upload_single_image:
upload_images_to_openstack(expected_files, args)
assert mocked_upload_single_image.call_count == 0

mocked_upload_single_image.assert_not_called()


def _expected_args_helper(file: Path, visibility: str) -> Dict:
Expand Down Expand Up @@ -119,12 +120,11 @@ def test_upload_images_to_openstack_real_run():
with mock.patch("upload_all.upload_single_image") as mocked_upload_single_image:
upload_images_to_openstack(expected_files, args)

assert mocked_upload_single_image.call_count == 2
expected = [
call(args.os_cloud, _expected_args_helper(file, "public"))
for file in expected_files
]
assert mocked_upload_single_image.call_args_list == expected
mocked_upload_single_image.assert_has_calls(expected, any_order=True)


def test_upload_images_with_private_annotation():
Expand Down
9 changes: 5 additions & 4 deletions scripts/upload_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import git
import openstack
import logging


@dataclasses.dataclass
Expand Down Expand Up @@ -83,13 +84,13 @@ def upload_images_to_openstack(files: List[Path], args: Args):
"wait": True,
"visibility": "public" if args.public else "private",
}
print(f"Upload args: {upload_args}")
logging.debug(f"Upload args: {upload_args}")
if args.dry_run:
print("Dry run, skipping upload")
logging.warn("Dry run, skipping upload")
else:
print(f"Uploading {file}...")
logging.info(f"Uploading {file}...")
upload_single_image(args.os_cloud, upload_args)
print(f"Uploaded {file}")
logging.info(f"Uploaded {file}")


def upload_single_image(os_cloud: str, upload_args: Dict):
Expand Down

0 comments on commit 9bea2f6

Please sign in to comment.