Add comprehensive test suite achieving 99% code coverage

Added 35 test files with 502 tests covering all Python modules including
API routes, ORM models, splendor game logic/TUI, heater controller,
weather service, NixOS installer, ZFS dataset management, and utilities.
Coverage improved from 11% to 99% (2540/2564 statements covered).

https://claude.ai/code/session_01SVzgLDUS1Cdc4eh1ijETTh
This commit is contained in:
Claude
2026-03-09 03:55:38 +00:00
parent 66acc010ca
commit b3199dfc31
35 changed files with 6850 additions and 0 deletions

191
tests/test_installer.py Normal file
View File

@@ -0,0 +1,191 @@
"""Tests for python/installer modules."""
from __future__ import annotations
import curses
from unittest.mock import MagicMock, patch
import pytest
from python.installer.tui import (
Cursor,
State,
calculate_device_menu_padding,
get_device,
)
# --- Cursor tests ---
def test_cursor_init() -> None:
"""Test Cursor initialization."""
c = Cursor()
assert c.get_x() == 0
assert c.get_y() == 0
assert c.height == 0
assert c.width == 0
def test_cursor_set_height_width() -> None:
"""Test Cursor set_height and set_width."""
c = Cursor()
c.set_height(100)
c.set_width(200)
assert c.height == 100
assert c.width == 200
def test_cursor_bounce_check() -> None:
"""Test Cursor bounce checks."""
c = Cursor()
c.set_height(10)
c.set_width(20)
assert c.x_bounce_check(-1) == 0
assert c.x_bounce_check(25) == 19
assert c.x_bounce_check(5) == 5
assert c.y_bounce_check(-1) == 0
assert c.y_bounce_check(15) == 9
assert c.y_bounce_check(5) == 5
def test_cursor_set_x_y() -> None:
"""Test Cursor set_x and set_y."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(5)
c.set_y(3)
assert c.get_x() == 5
assert c.get_y() == 3
def test_cursor_set_x_y_bounds() -> None:
"""Test Cursor set_x and set_y with bounds."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(-5)
assert c.get_x() == 0
c.set_y(100)
assert c.get_y() == 9
def test_cursor_move_up() -> None:
"""Test Cursor move_up."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_y(5)
c.move_up()
assert c.get_y() == 4
def test_cursor_move_down() -> None:
"""Test Cursor move_down."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_y(5)
c.move_down()
assert c.get_y() == 6
def test_cursor_move_left() -> None:
"""Test Cursor move_left."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(5)
c.move_left()
assert c.get_x() == 4
def test_cursor_move_right() -> None:
"""Test Cursor move_right."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(5)
c.move_right()
assert c.get_x() == 6
def test_cursor_navigation() -> None:
"""Test Cursor navigation with arrow keys."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(5)
c.set_y(5)
c.navigation(curses.KEY_UP)
assert c.get_y() == 4
c.navigation(curses.KEY_DOWN)
assert c.get_y() == 5
c.navigation(curses.KEY_LEFT)
assert c.get_x() == 4
c.navigation(curses.KEY_RIGHT)
assert c.get_x() == 5
def test_cursor_navigation_unknown_key() -> None:
"""Test Cursor navigation with unknown key (no-op)."""
c = Cursor()
c.set_height(10)
c.set_width(20)
c.set_x(5)
c.set_y(5)
c.navigation(999) # Unknown key
assert c.get_x() == 5
assert c.get_y() == 5
# --- State tests ---
def test_state_init() -> None:
"""Test State initialization."""
s = State()
assert s.key == 0
assert s.swap_size == 0
assert s.reserve_size == 0
assert s.selected_device_ids == set()
assert s.show_swap_input is False
assert s.show_reserve_input is False
def test_state_get_selected_devices() -> None:
"""Test State.get_selected_devices."""
s = State()
s.selected_device_ids = {"/dev/sda", "/dev/sdb"}
result = s.get_selected_devices()
assert isinstance(result, tuple)
assert set(result) == {"/dev/sda", "/dev/sdb"}
# --- get_device tests ---
def test_get_device() -> None:
"""Test get_device parses device string."""
raw = 'NAME="/dev/sda" SIZE="100G" TYPE="disk" MOUNTPOINTS=""'
device = get_device(raw)
assert device["name"] == "/dev/sda"
assert device["size"] == "100G"
assert device["type"] == "disk"
# --- calculate_device_menu_padding ---
def test_calculate_device_menu_padding() -> None:
"""Test calculate_device_menu_padding."""
devices = [
{"name": "/dev/sda", "size": "100G"},
{"name": "/dev/nvme0n1", "size": "500G"},
]
padding = calculate_device_menu_padding(devices, "name", 2)
assert padding == len("/dev/nvme0n1") + 2