Skip to content

Commit

Permalink
MAINT: Add black to pre-commit and reformat
Browse files Browse the repository at this point in the history
Adds black to the list of available pre-commit runners and reformat the
existing files
  • Loading branch information
DavidFair committed Feb 13, 2024
1 parent 44ba186 commit fa84703
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
29 changes: 19 additions & 10 deletions scripts/test/test_upload_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

import pytest

from upload_all import glob_output_files, Args, parse_args, upload_images_to_openstack, upload_single_image, main, \
get_upload_name
from upload_all import (
glob_output_files,
Args,
parse_args,
upload_images_to_openstack,
upload_single_image,
main,
get_upload_name,
)


def test_glob_output_files(tmp_path):
Expand Down Expand Up @@ -92,7 +99,8 @@ def _expected_args_helper(file: Path, visibility: str) -> Dict:
"disk_format": "qcow2",
"container_format": "bare",
"wait": True,
"visibility": visibility}
"visibility": visibility,
}


def test_upload_images_to_openstack_real_run():
Expand All @@ -107,9 +115,10 @@ def test_upload_images_to_openstack_real_run():
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]
expected = [
call(args.os_cloud, _expected_args_helper(file, "public"))
for file in expected_files
]
assert mocked_upload_single_image.call_args_list == expected


Expand All @@ -123,9 +132,7 @@ def test_upload_images_with_private_annotation():
upload_images_to_openstack([Path("file1")], args)

assert mocked_upload_single_image.call_count == 1
expected = [call(
args.os_cloud,
_expected_args_helper(Path("file1"), "private"))]
expected = [call(args.os_cloud, _expected_args_helper(Path("file1"), "private"))]
assert mocked_upload_single_image.call_args_list == expected


Expand All @@ -139,7 +146,9 @@ def test_upload_single_image():
upload_single_image("fake_cloud", fake_args)

mocked_openstack_connect.assert_called_once_with(cloud="fake_cloud")
mocked_openstack_connect.return_value.create_image.assert_called_once_with(**fake_args)
mocked_openstack_connect.return_value.create_image.assert_called_once_with(
**fake_args
)


def test_get_upload_name():
Expand Down
11 changes: 8 additions & 3 deletions scripts/upload_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Args:
"""
Holds user arguments for the script
"""

dry_run: bool
public: bool
os_cloud: str
Expand All @@ -26,7 +27,7 @@ def glob_output_files() -> List[Path]:
Globs the output files from the CAPI image builder
:return: A list of files to upload
"""
repo = git.Repo('.', search_parent_directories=True)
repo = git.Repo(".", search_parent_directories=True)
root_dir = Path(repo.working_tree_dir)

# Append the full path to the CAPI output directory
Expand All @@ -43,9 +44,13 @@ def parse_args(args) -> Args:
:return: Parsed arguments as a dataclass
"""
parser = argparse.ArgumentParser(description="Upload CAPI images to OpenStack")
parser.add_argument("--dry-run", action="store_true", help="Do not actually upload the images")
parser.add_argument(
"--dry-run", action="store_true", help="Do not actually upload the images"
)
parser.add_argument("--public", action="store_true", help="Make the images public")
parser.add_argument("os_cloud", default="default", help="The OpenStack cloud to use")
parser.add_argument(
"os_cloud", default="default", help="The OpenStack cloud to use"
)
parsed = parser.parse_args(args)
return Args(**vars(parsed))

Expand Down

0 comments on commit fa84703

Please sign in to comment.