From ba05f89279e181a58c7ec09ac153215ef86ad425 Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Wed, 20 Dec 2023 05:39:53 -0500 Subject: [PATCH] Fix lint issues Signed-off-by: Urvashi Mohnani --- podman/domain/containers_create.py | 30 ++++++------ podman/tests/unit/test_container.py | 59 +++++++++-------------- 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 +++++++++----------- 8 files changed, 116 insertions(+), 147 deletions(-) diff --git a/podman/domain/containers_create.py b/podman/domain/containers_create.py index 6f64d59f..837d34ab 100644 --- a/podman/domain/containers_create.py +++ b/podman/domain/containers_create.py @@ -383,22 +383,20 @@ 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""" diff --git a/podman/tests/unit/test_container.py b/podman/tests/unit/test_container.py index 955f48c1..3fe5fb98 100644 --- a/podman/tests/unit/test_container.py +++ b/podman/tests/unit/test_container.py @@ -106,20 +106,14 @@ 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)) @@ -413,28 +407,23 @@ 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"' - ), - ], - ['jhonce', '5544', '3522', '0', 'Mar01', 'pts/1', '00:00:02', '-bash'], - ['jhonce', '6140', '3522', '0', 'Mar01', 'pts/2', '00:00:00', '-bash'], + 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"', ], - "Titles": ["UID", "PID", "PPID", "C", "STIME", "TTY", "TIME CMD"], - } - ] + ['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"], + }] buffer = io.StringIO() for entry in stream: diff --git a/podman/tests/unit/test_events.py b/podman/tests/unit/test_events.py index 2ac3a9a7..bbf391d8 100644 --- a/podman/tests/unit/test_events.py +++ b/podman/tests/unit/test_events.py @@ -22,23 +22,21 @@ 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 b5107abf..f7daaabd 100644 --- a/podman/tests/unit/test_image.py +++ b/podman/tests/unit/test_image.py @@ -51,16 +51,14 @@ 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 705e8ffb..e3828ee7 100644 --- a/podman/tests/unit/test_imagesmanager.py +++ b/podman/tests/unit/test_imagesmanager.py @@ -156,13 +156,11 @@ 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() @@ -212,11 +210,9 @@ 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 b5dfb06b..dd8e1601 100644 --- a/podman/tests/unit/test_network.py +++ b/podman/tests/unit/test_network.py @@ -34,16 +34,14 @@ "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 1219bb54..57ed1f20 100644 --- a/podman/tests/unit/test_networksmanager.py +++ b/podman/tests/unit/test_networksmanager.py @@ -56,16 +56,14 @@ "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, @@ -80,16 +78,14 @@ "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 bce34d44..36b11a7c 100644 --- a/podman/tests/unit/test_podsmanager.py +++ b/podman/tests/unit/test_podsmanager.py @@ -194,34 +194,30 @@ 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()