Skip to content

Commit

Permalink
removed iterator for python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
fernando79513 committed Feb 12, 2025
1 parent 53409d9 commit 25f884b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions providers/base/bin/kernel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ def check_flag(flag, min_version):
kernel_config_path = get_kernel_config_path()
with open(kernel_config_path) as config:
# Check the header and ignore arm architecture configurations
for line in config:
lines = config.readlines()
header = lines[:4]
values = lines[4:]

for line in header:
if "Kernel Configuration" in line:
if "arm" in line:
print("Skipping: arm architecture detected.")
return
break

# Look for the flag in the configuration
for line in config:
for line in values:
line = line.strip()
if line.startswith("#"):
continue # Ignore commented lines
Expand Down
12 changes: 11 additions & 1 deletion providers/base/tests/test_kernel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def test_check_flag_lower_version(self, print_mock, uname_mock):
def test_check_flag_present(self, print_mock, uname_mock):
uname_mock.return_value = MagicMock(release="6.8.0-45-generic")
data = (
"#\n"
"# Automatically generated file; DO NOT EDIT.\n"
"# Linux/x86 6.8.12 Kernel Configuration\n"
"#\n"
"CONFIG_INTEL_IOMMU=y\n"
"CONFIG_INTEL_IOMMU_DEFAULT_ON=y\n"
)
Expand All @@ -123,8 +125,10 @@ def test_check_flag_present(self, print_mock, uname_mock):
def test_check_flag_not_present(self, uname_mock):
uname_mock.return_value = MagicMock(release="6.8.0-45-generic")
data = (
"#\n"
"# Automatically generated file; DO NOT EDIT.\n"
"# Linux/x86 6.8.12 Kernel Configuration\n"
"#\n"
"CONFIG_INTEL_IOMMU=y\n"
)
with patch("builtins.open", mock_open(read_data=data)):
Expand All @@ -140,8 +144,10 @@ def test_check_flag_not_present(self, uname_mock):
def test_check_flag_commented(self, uname_mock):
uname_mock.return_value = MagicMock(release="6.8.0-45-generic")
data = (
"#\n"
"# Automatically generated file; DO NOT EDIT.\n"
"# Linux/x86 6.8.12 Kernel Configuration\n"
"#\n"
"# CONFIG_INTEL_IOMMU_DEFAULT_ON=y\n"
)
with patch("builtins.open", mock_open(read_data=data)):
Expand All @@ -157,12 +163,16 @@ def test_check_flag_commented(self, uname_mock):
def test_check_flag_arm(self, print_mock, uname_mock):
uname_mock.return_value = MagicMock(release="6.8.0-45-generic")
data = (
"#\n"
"# Automatically generated file; DO NOT EDIT.\n"
"# Linux/arm64 6.8.12 Kernel Configuration\n"
"#\n"
)
with patch("builtins.open", mock_open(read_data=data)):
check_flag("CONFIG_INTEL_IOMMU_DEFAULT_ON", "6.8.0-20")
print_mock.assert_called_once_with("Skipping: arm architecture detected.")
print_mock.assert_called_once_with(
"Skipping: arm architecture detected."
)

@patch("kernel_config.argparse.ArgumentParser.parse_args")
def test_parse_args(self, parse_args_mock):
Expand Down

0 comments on commit 25f884b

Please sign in to comment.