Skip to content

Commit a8a066f

Browse files
committed
Please enter the commit message for your changes. Lines starting
with '' will be ignored, and an empty message aborts the commit. On branch less-deps-feature-win-tweaks Your branch is up to date with 'origin/less-deps-feature-win-tweaks'. Changes to be committed: modified: .github/workflows/ci.yml modified: src/lufus/drives/get_usb_info.py modified: tests/test_find_usb.py modified: tests/test_flash_usb_and_find_usb_fixes.py modified: tests/test_get_usb_info.py modified: tests/test_get_usb_info_and_detect_windows_fixes.py Untracked files: TODO
1 parent cb60160 commit a8a066f

6 files changed

Lines changed: 21 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install dependencies
3535
run: |
3636
python -m pip install --upgrade pip
37-
pip install psutil pytest
37+
pip install psutil pyudev pytest
3838
3939
- name: Install package (no-deps to avoid GUI reqs)
4040
run: pip install -e . --no-deps

src/lufus/drives/get_usb_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def get_usb_info(usb_path: str) -> USBDeviceInfo | None:
2929
# Using os.stat to get device number as per requirements
3030
st = os.stat(device_node)
3131
device = pyudev.Devices.from_device_number(context, "block", st.st_rdev)
32-
32+
3333
# Size in bytes: udev attributes 'size' is in 512-byte sectors
3434
size_attr = device.attributes.get("size")
3535
usb_size = int(size_attr) * 512 if size_attr else 0
36-
36+
3737
label = device.get("ID_FS_LABEL")
3838

3939
if usb_size > 32 * 1024**3:

tests/test_find_usb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ def test_find_usb_returns_mount_to_label_mapping(monkeypatch) -> None:
4242

4343
# Mock os.stat safely
4444
os_stat_orig = os.stat
45+
4546
def mock_os_stat(p):
4647
if str(p).startswith("/dev/"):
4748
mock_stat = MagicMock()
4849
mock_stat.st_rdev = 1234
4950
return mock_stat
5051
return os_stat_orig(p)
52+
5153
monkeypatch.setattr(find_usb_module.os, "stat", mock_os_stat)
5254

5355
# Mock pyudev
@@ -90,18 +92,22 @@ def test_find_usb_falls_back_to_dir_name_when_pyudev_fails(monkeypatch) -> None:
9092

9193
# Mock os.stat safely
9294
os_stat_orig = os.stat
95+
9396
def mock_os_stat(p):
9497
if str(p).startswith("/dev/"):
9598
mock_stat = MagicMock()
9699
mock_stat.st_rdev = 5678
97100
return mock_stat
98101
return os_stat_orig(p)
102+
99103
monkeypatch.setattr(find_usb_module.os, "stat", mock_os_stat)
100104

101105
# Mock pyudev to fail
102106
mock_context = MagicMock()
103107
monkeypatch.setattr(find_usb_module.pyudev, "Context", lambda: mock_context)
104-
monkeypatch.setattr(find_usb_module.pyudev.Devices, "from_device_number", MagicMock(side_effect=Exception("udev fail")))
108+
monkeypatch.setattr(
109+
find_usb_module.pyudev.Devices, "from_device_number", MagicMock(side_effect=Exception("udev fail"))
110+
)
105111

106112
result = find_usb_module.find_usb()
107113
assert result == {mount_path: "NO_LABEL"}

tests/test_flash_usb_and_find_usb_fixes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,16 @@ def test_find_usb_returns_label_from_udev(self, monkeypatch):
314314

315315
import os as real_os
316316
from unittest.mock import MagicMock
317+
317318
os_stat_orig = find_usb_module.os.stat
319+
318320
def mock_os_stat(p):
319321
if str(p).startswith("/dev/"):
320322
m = MagicMock()
321323
m.st_rdev = 1234
322324
return m
323325
return os_stat_orig(p)
326+
324327
monkeypatch.setattr(find_usb_module.os, "stat", mock_os_stat)
325328

326329
mock_context = MagicMock()

tests/test_get_usb_info.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ def test_get_usb_info_returns_expected_dictionary(monkeypatch) -> None:
3434

3535
# Mock os.stat safely
3636
os_stat_orig = get_usb_info_module.os.stat
37+
3738
def mock_os_stat(p):
3839
if str(p).startswith("/dev/"):
3940
mock_stat = MagicMock()
4041
mock_stat.st_rdev = 1234
4142
return mock_stat
4243
return os_stat_orig(p)
44+
4345
monkeypatch.setattr(get_usb_info_module.os, "stat", mock_os_stat)
4446

4547
# Mock pyudev
@@ -70,12 +72,14 @@ def test_get_usb_info_uses_mount_basename_when_label_is_empty(monkeypatch) -> No
7072

7173
# Mock os.stat safely
7274
os_stat_orig = get_usb_info_module.os.stat
75+
7376
def mock_os_stat(p):
7477
if str(p).startswith("/dev/"):
7578
mock_stat = MagicMock()
7679
mock_stat.st_rdev = 5678
7780
return mock_stat
7881
return os_stat_orig(p)
82+
7983
monkeypatch.setattr(get_usb_info_module.os, "stat", mock_os_stat)
8084

8185
# Mock pyudev
@@ -102,10 +106,12 @@ def test_get_usb_info_returns_empty_when_pyudev_fails(monkeypatch) -> None:
102106

103107
# Mock os.stat safely
104108
os_stat_orig = get_usb_info_module.os.stat
109+
105110
def mock_os_stat(p):
106111
if str(p).startswith("/dev/"):
107112
raise Exception("stat fail")
108113
return os_stat_orig(p)
114+
109115
monkeypatch.setattr(get_usb_info_module.os, "stat", mock_os_stat)
110116

111117
# This should return None because of the catch-all Exception in get_usb_info

tests/test_get_usb_info_and_detect_windows_fixes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ def _fake_partitions(mount, device):
2424
def _mock_os_stat_and_pyudev(monkeypatch, size="1000000000", label="MY_USB"):
2525
# Mock os.stat safely
2626
os_stat_orig = gui_module.os.stat
27+
2728
def mock_os_stat(p):
2829
if str(p).startswith("/dev/"):
2930
m = MagicMock()
3031
m.st_rdev = 1234
3132
return m
3233
return os_stat_orig(p)
34+
3335
monkeypatch.setattr(gui_module.os, "stat", mock_os_stat)
3436

3537
# Mock pyudev

0 commit comments

Comments
 (0)