From 35b3643e0838b398fc00df14750c5f54b727f4f5 Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Mon, 19 Feb 2024 11:22:13 -0500 Subject: [PATCH] Fix black format issues Signed-off-by: Urvashi Mohnani --- podman/domain/containers_create.py | 42 ++++++++------- podman/domain/images_manager.py | 10 ++-- podman/domain/ipam.py | 26 +++++---- .../integration/test_container_create.py | 22 ++++---- podman/tests/integration/utils.py | 14 ++--- podman/tests/unit/test_container.py | 54 ++++++++++--------- podman/tests/unit/test_events.py | 30 ++++++----- podman/tests/unit/test_image.py | 18 ++++--- podman/tests/unit/test_imagesmanager.py | 20 ++++--- podman/tests/unit/test_network.py | 18 ++++--- podman/tests/unit/test_networksmanager.py | 36 +++++++------ podman/tests/unit/test_podsmanager.py | 52 +++++++++--------- 12 files changed, 191 insertions(+), 151 deletions(-) diff --git a/podman/domain/containers_create.py b/podman/domain/containers_create.py index 029a6873..7a6a536b 100644 --- a/podman/domain/containers_create.py +++ b/podman/domain/containers_create.py @@ -385,20 +385,22 @@ def _render_payload(kwargs: MutableMapping[str, Any]) -> Dict[str, Any]: del args[key] # These keywords are not supported for various reasons. - unsupported_keys = set(args.keys()).intersection(( - "blkio_weight", - "blkio_weight_device", # FIXME In addition to device Major/Minor include path - "device_cgroup_rules", # FIXME Where to map for Podman API? - "device_read_bps", # FIXME In addition to device Major/Minor include path - "device_read_iops", # FIXME In addition to device Major/Minor include path - "device_requests", # FIXME In addition to device Major/Minor include path - "device_write_bps", # FIXME In addition to device Major/Minor include path - "device_write_iops", # FIXME In addition to device Major/Minor include path - "domainname", - "network_disabled", # FIXME Where to map for Podman API? - "storage_opt", # FIXME Where to map for Podman API? - "tmpfs", # FIXME Where to map for Podman API? - )) + unsupported_keys = set(args.keys()).intersection( + ( + "blkio_weight", + "blkio_weight_device", # FIXME In addition to device Major/Minor include path + "device_cgroup_rules", # FIXME Where to map for Podman API? + "device_read_bps", # FIXME In addition to device Major/Minor include path + "device_read_iops", # FIXME In addition to device Major/Minor include path + "device_requests", # FIXME In addition to device Major/Minor include path + "device_write_bps", # FIXME In addition to device Major/Minor include path + "device_write_iops", # FIXME In addition to device Major/Minor include path + "domainname", + "network_disabled", # FIXME Where to map for Podman API? + "storage_opt", # FIXME Where to map for Podman API? + "tmpfs", # FIXME Where to map for Podman API? + ) + ) if len(unsupported_keys) > 0: raise TypeError( f"""Keyword(s) '{" ,".join(unsupported_keys)}' are""" @@ -657,11 +659,13 @@ def parse_host_port(_container_port, _protocol, _host): } for item in args.pop("ulimits", []): - params["r_limits"].append({ - "type": item["Name"], - "hard": item["Hard"], - "soft": item["Soft"], - }) + params["r_limits"].append( + { + "type": item["Name"], + "hard": item["Hard"], + "soft": item["Soft"], + } + ) for item in args.pop("volumes", {}).items(): key, value = item diff --git a/podman/domain/images_manager.py b/podman/domain/images_manager.py index 3f94791c..df4e6f39 100644 --- a/podman/domain/images_manager.py +++ b/podman/domain/images_manager.py @@ -163,10 +163,12 @@ def prune( error.append(element["Err"]) else: reclaimed += element["Size"] - deleted.append({ - "Deleted": element["Id"], - "Untagged": "", - }) + deleted.append( + { + "Deleted": element["Id"], + "Untagged": "", + } + ) if len(error) > 0: raise APIError(response.url, response=response, explanation="; ".join(error)) diff --git a/podman/domain/ipam.py b/podman/domain/ipam.py index 79a4b2c5..98a78350 100644 --- a/podman/domain/ipam.py +++ b/podman/domain/ipam.py @@ -25,12 +25,14 @@ def __init__( aux_addresses: Ignored. """ super().__init__() - self.update({ - "AuxiliaryAddresses": aux_addresses, - "Gateway": gateway, - "IPRange": iprange, - "Subnet": subnet, - }) + self.update( + { + "AuxiliaryAddresses": aux_addresses, + "Gateway": gateway, + "IPRange": iprange, + "Subnet": subnet, + } + ) class IPAMConfig(dict): @@ -50,8 +52,10 @@ def __init__( options: Options to provide to the Network driver. """ super().__init__() - self.update({ - "Config": pool_configs or [], - "Driver": driver, - "Options": options or {}, - }) + self.update( + { + "Config": pool_configs or [], + "Driver": driver, + "Options": options or {}, + } + ) diff --git a/podman/tests/integration/test_container_create.py b/podman/tests/integration/test_container_create.py index f05a29ed..fdd98c77 100644 --- a/podman/tests/integration/test_container_create.py +++ b/podman/tests/integration/test_container_create.py @@ -149,10 +149,12 @@ def test_container_ports(self): self.containers.append(container) self.assertTrue( - all([ - x in port_test['expected_output'] - for x in container.attrs.get('HostConfig', {}).get('PortBindings') - ]) + all( + [ + x in port_test['expected_output'] + for x in container.attrs.get('HostConfig', {}).get('PortBindings') + ] + ) ) def test_container_healthchecks(self): @@ -241,11 +243,13 @@ def test_container_devices(self): for device in devices: path_on_host, path_in_container = device.split(':', 1) self.assertTrue( - any([ - c.get('PathOnHost') == path_on_host - and c.get('PathInContainer') == path_in_container - for c in container_devices - ]) + any( + [ + c.get('PathOnHost') == path_on_host + and c.get('PathInContainer') == path_in_container + for c in container_devices + ] + ) ) with self.subTest("Check devices in running container object"): diff --git a/podman/tests/integration/utils.py b/podman/tests/integration/utils.py index 0f1720cd..78aea63a 100644 --- a/podman/tests/integration/utils.py +++ b/podman/tests/integration/utils.py @@ -66,12 +66,14 @@ def __init__( if os.environ.get("container") == "oci": self.cmd.append("--storage-driver=vfs") - self.cmd.extend([ - "system", - "service", - f"--time={timeout}", - socket_uri, - ]) + self.cmd.extend( + [ + "system", + "service", + f"--time={timeout}", + socket_uri, + ] + ) process = subprocess.run( [podman_exe, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT diff --git a/podman/tests/unit/test_container.py b/podman/tests/unit/test_container.py index 4ed04cc0..5d0023e0 100644 --- a/podman/tests/unit/test_container.py +++ b/podman/tests/unit/test_container.py @@ -103,14 +103,18 @@ def test_start(self, mock): @requests_mock.Mocker() def test_stats(self, mock): - stream = [{ - "Error": None, - "Stats": [{ - "ContainerId": "87e1325c82424e49a00abdd4de08009eb76c7de8d228426a9b8af9318ced5ecd", - "Name": "evil_ptolemy", - "CPU": 1000.0, - }], - }] + stream = [ + { + "Error": None, + "Stats": [ + { + "ContainerId": "87e1325c82424e49a00abdd4de08009eb76c7de8d228426a9b8af9318ced5ecd", + "Name": "evil_ptolemy", + "CPU": 1000.0, + } + ], + } + ] buffer = io.StringIO() for entry in stream: buffer.write(json.JSONEncoder().encode(entry)) @@ -395,23 +399,25 @@ def test_top(self, mock): @requests_mock.Mocker() def test_top_with_streaming(self, mock): - stream = [{ - "Processes": [ - [ - 'jhonce', - '2417', - '2274', - '0', - 'Mar01', - '?', - '00:00:01', - '/usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/gnome-session"', + stream = [ + { + "Processes": [ + [ + 'jhonce', + '2417', + '2274', + '0', + 'Mar01', + '?', + '00:00:01', + '/usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/gnome-session"', + ], + ['jhonce', '5544', '3522', '0', 'Mar01', 'pts/1', '00:00:02', '-bash'], + ['jhonce', '6140', '3522', '0', 'Mar01', 'pts/2', '00:00:00', '-bash'], ], - ['jhonce', '5544', '3522', '0', 'Mar01', 'pts/1', '00:00:02', '-bash'], - ['jhonce', '6140', '3522', '0', 'Mar01', 'pts/2', '00:00:00', '-bash'], - ], - "Titles": ["UID", "PID", "PPID", "C", "STIME", "TTY", "TIME CMD"], - }] + "Titles": ["UID", "PID", "PPID", "C", "STIME", "TTY", "TIME CMD"], + } + ] buffer = io.StringIO() for entry in stream: diff --git a/podman/tests/unit/test_events.py b/podman/tests/unit/test_events.py index bbf391d8..2ac3a9a7 100644 --- a/podman/tests/unit/test_events.py +++ b/podman/tests/unit/test_events.py @@ -22,21 +22,23 @@ def tearDown(self) -> None: @requests_mock.Mocker() def test_list(self, mock): - stream = [{ - "Type": "pod", - "Action": "create", - "Actor": { - "ID": "", - "Attributes": { - "image": "", - "name": "", - "containerExitCode": 0, + stream = [ + { + "Type": "pod", + "Action": "create", + "Actor": { + "ID": "", + "Attributes": { + "image": "", + "name": "", + "containerExitCode": 0, + }, }, - }, - "Scope": "local", - "Time": 1615845480, - "TimeNano": 1615845480, - }] + "Scope": "local", + "Time": 1615845480, + "TimeNano": 1615845480, + } + ] buffer = io.StringIO() for item in stream: buffer.write(json.JSONEncoder().encode(item)) diff --git a/podman/tests/unit/test_image.py b/podman/tests/unit/test_image.py index f7daaabd..b5107abf 100644 --- a/podman/tests/unit/test_image.py +++ b/podman/tests/unit/test_image.py @@ -51,14 +51,16 @@ def test_history(self, mock): adapter = mock.get( tests.LIBPOD_URL + "/images/326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab/history", - json=[{ - "Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab", - "Comment": "", - "Created": 1614208404, - "CreatedBy": "2021-02-24T23:13:24+00:00", - "Tags": ["latest"], - "Size": 1024, - }], + json=[ + { + "Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab", + "Comment": "", + "Created": 1614208404, + "CreatedBy": "2021-02-24T23:13:24+00:00", + "Tags": ["latest"], + "Size": 1024, + } + ], ) image = Image(attrs=FIRST_IMAGE, client=self.client.api) diff --git a/podman/tests/unit/test_imagesmanager.py b/podman/tests/unit/test_imagesmanager.py index 1403af27..6de8910f 100644 --- a/podman/tests/unit/test_imagesmanager.py +++ b/podman/tests/unit/test_imagesmanager.py @@ -156,11 +156,13 @@ def test_prune(self, mock): """Unit test Images prune().""" mock.post( tests.LIBPOD_URL + "/images/prune", - json=[{ - "Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab", - "Err": None, - "Size": 1024, - }], + json=[ + { + "Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab", + "Err": None, + "Size": 1024, + } + ], ) results = self.client.images.prune() @@ -210,9 +212,11 @@ def test_prune_failure(self, mock): """Unit test to report error carried in response body.""" mock.post( tests.LIBPOD_URL + "/images/prune", - json=[{ - "Err": "Test prune failure in response body.", - }], + json=[ + { + "Err": "Test prune failure in response body.", + } + ], ) with self.assertRaises(APIError) as e: diff --git a/podman/tests/unit/test_network.py b/podman/tests/unit/test_network.py index dd8e1601..b5dfb06b 100644 --- a/podman/tests/unit/test_network.py +++ b/podman/tests/unit/test_network.py @@ -34,14 +34,16 @@ "driver": "bridge", "network_interface": "libpod_veth0", "created": "2022-01-28T09:18:37.491308364-07:00", - "subnets": [{ - "subnet": "10.11.12.0/24", - "gateway": "10.11.12.1", - "lease_range": { - "start_ip": "10.11.12.1", - "end_ip": "10.11.12.63", - }, - }], + "subnets": [ + { + "subnet": "10.11.12.0/24", + "gateway": "10.11.12.1", + "lease_range": { + "start_ip": "10.11.12.1", + "end_ip": "10.11.12.63", + }, + } + ], "ipv6_enabled": False, "internal": False, "dns_enabled": False, diff --git a/podman/tests/unit/test_networksmanager.py b/podman/tests/unit/test_networksmanager.py index 57ed1f20..1219bb54 100644 --- a/podman/tests/unit/test_networksmanager.py +++ b/podman/tests/unit/test_networksmanager.py @@ -56,14 +56,16 @@ "driver": "bridge", "network_interface": "libpod_veth0", "created": "2022-01-28T09:18:37.491308364-07:00", - "subnets": [{ - "subnet": "10.11.12.0/24", - "gateway": "10.11.12.1", - "lease_range": { - "start_ip": "10.11.12.1", - "end_ip": "10.11.12.63", - }, - }], + "subnets": [ + { + "subnet": "10.11.12.0/24", + "gateway": "10.11.12.1", + "lease_range": { + "start_ip": "10.11.12.1", + "end_ip": "10.11.12.63", + }, + } + ], "ipv6_enabled": False, "internal": False, "dns_enabled": False, @@ -78,14 +80,16 @@ "created": "2021-03-01T09:18:37.491308364-07:00", "driver": "bridge", "network_interface": "libpod_veth1", - "subnets": [{ - "subnet": "10.11.12.0/24", - "gateway": "10.11.12.1", - "lease_range": { - "start_ip": "10.11.12.1", - "end_ip": "10.11.12.63", - }, - }], + "subnets": [ + { + "subnet": "10.11.12.0/24", + "gateway": "10.11.12.1", + "lease_range": { + "start_ip": "10.11.12.1", + "end_ip": "10.11.12.63", + }, + } + ], "ipv6_enabled": False, "internal": False, "dns_enabled": False, diff --git a/podman/tests/unit/test_podsmanager.py b/podman/tests/unit/test_podsmanager.py index 73886cb3..4512f8e6 100644 --- a/podman/tests/unit/test_podsmanager.py +++ b/podman/tests/unit/test_podsmanager.py @@ -192,30 +192,34 @@ def test_stats_without_decode(self, mock): @requests_mock.Mocker() def test_top_with_streaming(self, mock): stream = [ - [{ - 'CPU': '2.53%', - 'MemUsage': '49.15kB / 16.71GB', - 'MemUsageBytes': '48KiB / 15.57GiB', - 'Mem': '0.00%', - 'NetIO': '7.638kB / 430B', - 'BlockIO': '-- / --', - 'PIDS': '1', - 'Pod': '1c948ab42339', - 'CID': 'd999c49a7b6c', - 'Name': '1c948ab42339-infra', - }], - [{ - 'CPU': '1.46%', - 'MemUsage': '57.23B / 16.71GB', - 'MemUsageBytes': '48KiB / 15.57GiB', - 'Mem': '0.00%', - 'NetIO': '7.638kB / 430B', - 'BlockIO': '-- / --', - 'PIDS': '1', - 'Pod': '1c948ab42339', - 'CID': 'd999c49a7b6c', - 'Name': '1c948ab42339-infra', - }], + [ + { + 'CPU': '2.53%', + 'MemUsage': '49.15kB / 16.71GB', + 'MemUsageBytes': '48KiB / 15.57GiB', + 'Mem': '0.00%', + 'NetIO': '7.638kB / 430B', + 'BlockIO': '-- / --', + 'PIDS': '1', + 'Pod': '1c948ab42339', + 'CID': 'd999c49a7b6c', + 'Name': '1c948ab42339-infra', + } + ], + [ + { + 'CPU': '1.46%', + 'MemUsage': '57.23B / 16.71GB', + 'MemUsageBytes': '48KiB / 15.57GiB', + 'Mem': '0.00%', + 'NetIO': '7.638kB / 430B', + 'BlockIO': '-- / --', + 'PIDS': '1', + 'Pod': '1c948ab42339', + 'CID': 'd999c49a7b6c', + 'Name': '1c948ab42339-infra', + } + ], ] buffer = io.StringIO()