Replace the numeric "score N" pill with a Recommended badge on the auto-selected drive plus size/type/health chips. The score itself stays as the sort key, users just never see the raw number. Why: Robert's 2026-04-14 wizard UX direction — less jargon, explain Fachbegriffs, recommend defaults. A bare "score 35" gave users no reason why one drive was picked. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
97 lines
2.5 KiB
Python
97 lines
2.5 KiB
Python
from drives import (
|
|
get_drive_type_label,
|
|
get_drive_type_score,
|
|
get_size_score,
|
|
parse_lsblk_output,
|
|
parse_size_gb,
|
|
score_device,
|
|
)
|
|
|
|
|
|
def test_parse_size_gb_terabytes():
|
|
assert parse_size_gb("1T") == 1024.0
|
|
|
|
|
|
def test_parse_size_gb_gigabytes():
|
|
assert parse_size_gb("500G") == 500.0
|
|
|
|
|
|
def test_parse_size_gb_megabytes():
|
|
assert parse_size_gb("2048M") == 2.0
|
|
|
|
|
|
def test_parse_size_gb_european_comma_decimal():
|
|
assert parse_size_gb("1,5T") == 1.5 * 1024
|
|
|
|
|
|
def test_parse_size_gb_empty_returns_none():
|
|
assert parse_size_gb("") is None
|
|
|
|
|
|
def test_parse_size_gb_unknown_unit_returns_none():
|
|
assert parse_size_gb("500K") is None
|
|
|
|
|
|
def test_drive_type_score_nvme():
|
|
assert get_drive_type_score("/dev/nvme0n1") == 15
|
|
|
|
|
|
def test_drive_type_score_ssd():
|
|
assert get_drive_type_score("/dev/ssd0") == 10
|
|
|
|
|
|
def test_drive_type_score_hdd_fallback():
|
|
assert get_drive_type_score("/dev/sda") == 5
|
|
|
|
|
|
def test_size_score_bands():
|
|
assert get_size_score(None) == 5
|
|
assert get_size_score(64) == 5
|
|
assert get_size_score(256) == 7
|
|
assert get_size_score(1024) == 10
|
|
|
|
|
|
def test_score_device_sums_type_and_size(monkeypatch):
|
|
import drives
|
|
|
|
monkeypatch.setattr(drives, "get_drive_health", lambda _: 10)
|
|
assert score_device("/dev/nvme0n1", 1024) == 15 + 10 + 10
|
|
assert score_device("/dev/sda", 64) == 5 + 10 + 5
|
|
|
|
|
|
def test_parse_lsblk_drops_loop_and_rom(monkeypatch):
|
|
import drives
|
|
|
|
monkeypatch.setattr(drives, "_smart_status", lambda _: "passed")
|
|
output = "loop0 2.5G loop\nsr0 1024M rom\nsda 500G disk\nnvme0n1 1T disk\n"
|
|
devices = parse_lsblk_output(output)
|
|
names = [d["name"] for d in devices]
|
|
assert names == ["/dev/nvme0n1", "/dev/sda"]
|
|
|
|
|
|
def test_parse_lsblk_attaches_human_labels(monkeypatch):
|
|
import drives
|
|
|
|
monkeypatch.setattr(drives, "_smart_status", lambda _: "passed")
|
|
output = "nvme0n1 1T disk\n"
|
|
[dev] = parse_lsblk_output(output)
|
|
assert dev["type_label"] == "NVMe"
|
|
assert dev["health_label"] == "Healthy"
|
|
|
|
|
|
def test_parse_lsblk_surfaces_smart_warning(monkeypatch):
|
|
import drives
|
|
|
|
monkeypatch.setattr(drives, "_smart_status", lambda _: "failed")
|
|
[dev] = parse_lsblk_output("sda 500G disk\n")
|
|
assert dev["health_label"] == "SMART warning"
|
|
|
|
|
|
def test_drive_type_label_nvme_ssd_hdd():
|
|
assert get_drive_type_label("/dev/nvme0n1") == "NVMe"
|
|
assert get_drive_type_label("/dev/ssd0") == "SSD"
|
|
assert get_drive_type_label("/dev/sda") == "HDD"
|
|
|
|
|
|
def test_parse_lsblk_handles_empty_output():
|
|
assert parse_lsblk_output("") == []
|