diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..2112d5b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/psf/black + rev: 24.2.0 + hooks: + - id: black diff --git a/scripts/test/test_upload_all.py b/scripts/test/test_upload_all.py index 8ec8321..b315e1d 100644 --- a/scripts/test/test_upload_all.py +++ b/scripts/test/test_upload_all.py @@ -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): @@ -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(): @@ -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 @@ -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 @@ -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(): diff --git a/scripts/upload_all.py b/scripts/upload_all.py index 15efc52..495b367 100755 --- a/scripts/upload_all.py +++ b/scripts/upload_all.py @@ -15,6 +15,7 @@ class Args: """ Holds user arguments for the script """ + dry_run: bool public: bool os_cloud: str @@ -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 @@ -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))