Sitelet https://github.com/stfc/cloud-image-builders/commit/766a3e8dbb208a234a8397655f521b6c1eaa1364
Skip to content

Commit 766a3e8

Browse files
committed
MAINT: Add black to pre-commit and reformat
Adds black to the list of available pre-commit runners and reformat the existing files
1 parent 585b172 commit 766a3e8

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 24.2.0
4+
hooks:
5+
- id: black

‎scripts/test/test_upload_all.py‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
import pytest
88

9-
from upload_all import glob_output_files, Args, parse_args, upload_images_to_openstack, upload_single_image, main, \
10-
get_upload_name
9+
from upload_all import (
10+
glob_output_files,
11+
Args,
12+
parse_args,
13+
upload_images_to_openstack,
14+
upload_single_image,
15+
main,
16+
get_upload_name,
17+
)
1118

1219

1320
def test_glob_output_files(tmp_path):
@@ -92,7 +99,8 @@ def _expected_args_helper(file: Path, visibility: str) -> Dict:
9299
"disk_format": "qcow2",
93100
"container_format": "bare",
94101
"wait": True,
95-
"visibility": visibility}
102+
"visibility": visibility,
103+
}
96104

97105

98106
def test_upload_images_to_openstack_real_run():
@@ -107,9 +115,10 @@ def test_upload_images_to_openstack_real_run():
107115
upload_images_to_openstack(expected_files, args)
108116

109117
assert mocked_upload_single_image.call_count == 2
110-
expected = [call(
111-
args.os_cloud,
112-
_expected_args_helper(file, "public")) for file in expected_files]
118+
expected = [
119+
call(args.os_cloud, _expected_args_helper(file, "public"))
120+
for file in expected_files
121+
]
113122
assert mocked_upload_single_image.call_args_list == expected
114123

115124

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

125134
assert mocked_upload_single_image.call_count == 1
126-
expected = [call(
127-
args.os_cloud,
128-
_expected_args_helper(Path("file1"), "private"))]
135+
expected = [call(args.os_cloud, _expected_args_helper(Path("file1"), "private"))]
129136
assert mocked_upload_single_image.call_args_list == expected
130137

131138

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

141148
mocked_openstack_connect.assert_called_once_with(cloud="fake_cloud")
142-
mocked_openstack_connect.return_value.create_image.assert_called_once_with(**fake_args)
149+
mocked_openstack_connect.return_value.create_image.assert_called_once_with(
150+
**fake_args
151+
)
143152

144153

145154
def test_get_upload_name():

‎scripts/upload_all.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Args:
1515
"""
1616
Holds user arguments for the script
1717
"""
18+
1819
dry_run: bool
1920
public: bool
2021
os_cloud: str
@@ -26,7 +27,7 @@ def glob_output_files() -> List[Path]:
2627
Globs the output files from the CAPI image builder
2728
:return: A list of files to upload
2829
"""
29-
repo = git.Repo('.', search_parent_directories=True)
30+
repo = git.Repo(".", search_parent_directories=True)
3031
root_dir = Path(repo.working_tree_dir)
3132

3233
# Append the full path to the CAPI output directory
@@ -43,9 +44,13 @@ def parse_args(args) -> Args:
4344
:return: Parsed arguments as a dataclass
4445
"""
4546
parser = argparse.ArgumentParser(description="Upload CAPI images to OpenStack")
46-
parser.add_argument("--dry-run", action="store_true", help="Do not actually upload the images")
47+
parser.add_argument(
48+
"--dry-run", action="store_true", help="Do not actually upload the images"
49+
)
4750
parser.add_argument("--public", action="store_true", help="Make the images public")
48-
parser.add_argument("os_cloud", default="default", help="The OpenStack cloud to use")
51+
parser.add_argument(
52+
"os_cloud", default="default", help="The OpenStack cloud to use"
53+
)
4954
parsed = parser.parse_args(args)
5055
return Args(**vars(parsed))
5156

0 commit comments

Comments
 (0)