From 125dcc27a33d758249b939b66a6df169b0ef0c17 Mon Sep 17 00:00:00 2001 From: jneo8 Date: Mon, 26 Feb 2024 16:53:15 +0800 Subject: [PATCH] refactor: Some small change to address the comments on PR --- src/hardware.py | 10 +++++----- src/hw_tools.py | 2 +- tests/unit/test_hardware.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/hardware.py b/src/hardware.py index 912f63d9..241b6b77 100644 --- a/src/hardware.py +++ b/src/hardware.py @@ -82,7 +82,7 @@ def get_bmc_address() -> t.Optional[str]: def _split_at(s: str, c: str, n: int) -> t.Tuple[str, str]: """Split a string 's' at the 'n'th occurrence of delimiter 'c'. - Parameters: + Args: s (str): The string to split. c (str): Delimiter for splitting. n (int): Occurrence of 'c' to split at. @@ -107,17 +107,17 @@ def hwinfo(*args: str) -> t.Dict[str, str]: Args: args: Probe for a particular hardware class. Returns: - hw_info: hardware information dicturary + hw_info: hardware information dictionary """ apt.add_package("hwinfo", update_cache=False) hw_classes = list(args) for idx, hw_item in enumerate(args): hw_classes[idx] = "--" + hw_item - hw_classes.insert(0, "hwinfo") + hw_info_cmd = ["hwinfo"] + hw_classes - output = subprocess.check_output(hw_classes, text=True) + output = subprocess.check_output(hw_info_cmd, text=True) if "start debug info" in output.splitlines()[0]: - output = _split_at(output, "=========== end debug info ============", 1)[1] + output = output.split("=========== end debug info ============")[1] hardwares: t.Dict[str, str] = {} for item in output.split("\n\n"): diff --git a/src/hw_tools.py b/src/hw_tools.py index 291deeea..95ed163d 100644 --- a/src/hw_tools.py +++ b/src/hw_tools.py @@ -349,7 +349,7 @@ def check(self) -> bool: def _raid_hw_verifier_hwinfo() -> Set[HWTool]: - """Verify if the HWTool support RAID card exists on machine with hwinfo.""" + """Verify if a supported RAID card exists on the machine using the hwinfo command.""" hwinfo_output = hwinfo("storage") tools = set() diff --git a/tests/unit/test_hardware.py b/tests/unit/test_hardware.py index eb7ee469..a5973a61 100644 --- a/tests/unit/test_hardware.py +++ b/tests/unit/test_hardware.py @@ -19,7 +19,7 @@ def test_split_at(s, delimiter, num, expect): class TestHwinfo: @pytest.mark.parametrize( - "hw_classes,expect_cmd, hwinfo_output,expect", + "hw_classes,expect_cmd,hwinfo_output,expect", [ ( [],