Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
Some files have not been formatted and were part of PRs that have landed
after the black formatting one. Fixing this.

Command used:

black  --line-length 79 --extend-exclude '/vendor/' .
  • Loading branch information
pieqq committed Apr 12, 2024
1 parent 803cfe4 commit 4ab9394
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,6 @@ def test_VRAID_machine(self):
"""
devices = self.parse("With_VRAID", with_partitions=True)


def verify_devices(self, devices, expected_device_list):
"""
Verify we have the expected quantity of each device given in the list,
Expand Down
2 changes: 1 addition & 1 deletion checkbox-support/checkbox_support/parsers/udevadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def bus(self):
else:
return "usb"
else:
if len(self._stack)>=2:
if len(self._stack) >= 2:
return self._stack[-2]._environment.get("SUBSYSTEM")
else:
return self._stack[0]._environment.get("SUBSYSTEM")
Expand Down
10 changes: 6 additions & 4 deletions providers/base/bin/get_firmware_info_fwupd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def get_fwupdmgr_services_versions():
list: fwupd client and daemon versions
"""
fwupd_vers = subprocess.run(
shlex.split("fwupdmgr --version --json"),
capture_output=True)
shlex.split("fwupdmgr --version --json"), capture_output=True
)
fwupd_vers = json.loads(fwupd_vers.stdout).get("Versions", [])

return fwupd_vers
Expand All @@ -49,8 +49,10 @@ def get_fwupd_runtime_version():
runtime_ver = ()

for ver in get_fwupdmgr_services_versions():
if (ver.get("Type") == "runtime" and
ver.get("AppstreamId") == "org.freedesktop.fwupd"):
if (
ver.get("Type") == "runtime"
and ver.get("AppstreamId") == "org.freedesktop.fwupd"
):
runtime_ver = tuple(map(int, ver.get("Version").split(".")))

return runtime_ver
Expand Down
75 changes: 42 additions & 33 deletions providers/base/tests/test_get_firmware_info_fwupd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,62 @@ def test_get_deb_fwupd_version_success(self, mock_subporcess, mock_json):
{
"Type": "runtime",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.9.14"
"Version": "1.9.14",
},
{
"Type": "compile",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
}
"Version": "1.7.9",
},
]
}
json_resp = json.dumps(dict_resp)
mock_subporcess.return_value = subprocess.CompletedProcess(
returncode=0,
stdout=json_resp,
args=["fwupdmgr", "--version", "--json"]
)
returncode=0,
stdout=json_resp,
args=["fwupdmgr", "--version", "--json"],
)
mock_json.return_value = dict_resp

fwupd_vers = get_firmware_info_fwupd.get_fwupdmgr_services_versions()
mock_subporcess.assert_called_with(
['fwupdmgr', '--version', '--json'],
capture_output=True)
["fwupdmgr", "--version", "--json"], capture_output=True
)
mock_json.assert_called_with(json_resp)
self.assertListEqual(dict_resp["Versions"], fwupd_vers)

@patch("json.loads")
@patch("subprocess.run")
def test_get_deb_fwupd_version_key_not_match(
self, mock_subporcess, mock_json):
self, mock_subporcess, mock_json
):

dict_resp = {
"Services": [
{
"Type": "runtime",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.9.14"
"Version": "1.9.14",
},
{
"Type": "compile",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
}
"Version": "1.7.9",
},
]
}
json_resp = json.dumps(dict_resp)
mock_subporcess.return_value = subprocess.CompletedProcess(
returncode=0,
stdout=json_resp,
args=["fwupdmgr", "--version", "--json"]
)
returncode=0,
stdout=json_resp,
args=["fwupdmgr", "--version", "--json"],
)
mock_json.return_value = dict_resp

fwupd_vers = get_firmware_info_fwupd.get_fwupdmgr_services_versions()
mock_subporcess.assert_called_with(
['fwupdmgr', '--version', '--json'], capture_output=True)
["fwupdmgr", "--version", "--json"], capture_output=True
)
mock_json.assert_called_with(json_resp)
self.assertListEqual([], fwupd_vers)

Expand All @@ -82,13 +84,13 @@ def test_get_deb_fwupd_runtime_version_success(self, mock_fwupd_vers):
{
"Type": "runtime",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
"Version": "1.7.9",
},
{
"Type": "compile",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
}
"Version": "1.7.9",
},
]

mock_fwupd_vers.return_value = fwupd_vers_resp
Expand All @@ -102,7 +104,7 @@ def test_get_deb_fwupd_runtime_version_failed(self, mock_fwupd_vers):
{
"Type": "compile",
"AppstreamId": "org.freedesktop.fwupd",
"Version": "1.7.9"
"Version": "1.7.9",
}
]

Expand All @@ -113,41 +115,45 @@ def test_get_deb_fwupd_runtime_version_failed(self, mock_fwupd_vers):
@patch("subprocess.run")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd_snap(
self, mock_snapd, mock_subporcess):
self, mock_snapd, mock_subporcess
):

mock_snapd.return_value = {
"id": "HpOj37PuyuaMUZY0NQhtwnp7oS5P8u5R",
"title": "fwupd",
"summary": "Firmware updates for Linux"
"summary": "Firmware updates for Linux",
}
get_firmware_info_fwupd.get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
['fwupd.fwupdmgr', 'get-devices', '--json'])
["fwupd.fwupdmgr", "get-devices", "--json"]
)

@patch.dict(os.environ, {"SNAP": "checkbox-snap"})
@patch("subprocess.run")
@patch("get_firmware_info_fwupd.get_fwupd_runtime_version")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd1914_deb_on_checkbox_snap(
self, mock_snapd, mock_fwupd_ver, mock_subporcess):
self, mock_snapd, mock_fwupd_ver, mock_subporcess
):

mock_snapd.return_value = None
mock_fwupd_ver.return_value = (1, 9, 14)

get_firmware_info_fwupd.get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
self.assertEqual(
os.environ.get("SNAP"), "checkbox-snap")
self.assertEqual(os.environ.get("SNAP"), "checkbox-snap")
mock_subporcess.assert_called_with(
['fwupdmgr', 'get-devices', '--json'])
["fwupdmgr", "get-devices", "--json"]
)

@patch.dict(os.environ, {"SNAP": "checkbox-snap"})
@patch("subprocess.run")
@patch("get_firmware_info_fwupd.get_fwupd_runtime_version")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd_deb179_on_checkbox_snap(
self, mock_snapd, mock_fwupd_ver, mock_subporcess):
self, mock_snapd, mock_fwupd_ver, mock_subporcess
):

mock_snapd.return_value = False
mock_fwupd_ver.return_value = (1, 7, 9)
Expand All @@ -159,13 +165,15 @@ def test_get_firmware_data_by_fwupd_deb179_on_checkbox_snap(
# SNAP env is empty after get_firmware_info_fwupd been called
self.assertIsNone(os.environ.get("SNAP"))
mock_subporcess.assert_called_with(
['fwupdmgr', 'get-devices', '--json'])
["fwupdmgr", "get-devices", "--json"]
)

@patch("subprocess.run")
@patch("get_firmware_info_fwupd.get_fwupd_runtime_version")
@patch("checkbox_support.snap_utils.snapd.Snapd.list")
def test_get_firmware_data_by_fwupd_deb_on_checkbox_deb(
self, mock_snapd, mock_fwupd_ver, mock_subporcess):
self, mock_snapd, mock_fwupd_ver, mock_subporcess
):

mock_snapd.return_value = False
mock_fwupd_ver.return_value = (1, 7, 9)
Expand All @@ -175,4 +183,5 @@ def test_get_firmware_data_by_fwupd_deb_on_checkbox_deb(
get_firmware_info_fwupd.get_firmware_info_fwupd()
mock_snapd.assert_called_with("fwupd")
mock_subporcess.assert_called_with(
['fwupdmgr', 'get-devices', '--json'])
["fwupdmgr", "get-devices", "--json"]
)

0 comments on commit 4ab9394

Please sign in to comment.