dashboard sync app
This commit is contained in:
400
tests/test_platform.py
Normal file
400
tests/test_platform.py
Normal file
@@ -0,0 +1,400 @@
|
||||
"""Tests for platform compatibility utilities."""
|
||||
|
||||
import pytest
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from src.utils.platform import (
|
||||
get_platform_info,
|
||||
is_supported_platform,
|
||||
get_default_config_dir,
|
||||
get_default_data_dir,
|
||||
get_default_log_dir,
|
||||
get_default_maildir_path,
|
||||
check_dependencies,
|
||||
get_shell_info,
|
||||
get_shell_config_file,
|
||||
get_platform_specific_commands,
|
||||
check_terminal_compatibility,
|
||||
check_textual_support,
|
||||
get_platform_recommendations,
|
||||
validate_environment,
|
||||
)
|
||||
|
||||
|
||||
class TestGetPlatformInfo:
|
||||
"""Tests for get_platform_info function."""
|
||||
|
||||
def test_returns_dict(self):
|
||||
"""Test that get_platform_info returns a dictionary."""
|
||||
info = get_platform_info()
|
||||
assert isinstance(info, dict)
|
||||
|
||||
def test_contains_required_keys(self):
|
||||
"""Test that info contains all required keys."""
|
||||
info = get_platform_info()
|
||||
|
||||
required_keys = [
|
||||
"system",
|
||||
"release",
|
||||
"version",
|
||||
"machine",
|
||||
"processor",
|
||||
"python_version",
|
||||
"python_implementation",
|
||||
]
|
||||
|
||||
for key in required_keys:
|
||||
assert key in info
|
||||
|
||||
def test_values_are_strings(self):
|
||||
"""Test that all values are strings."""
|
||||
info = get_platform_info()
|
||||
|
||||
for value in info.values():
|
||||
assert isinstance(value, str)
|
||||
|
||||
|
||||
class TestIsSupportedPlatform:
|
||||
"""Tests for is_supported_platform function."""
|
||||
|
||||
def test_current_platform_supported(self):
|
||||
"""Test that current platform is supported (if Python 3.12+)."""
|
||||
python_version = tuple(map(int, platform.python_version().split(".")))
|
||||
|
||||
if python_version >= (3, 12):
|
||||
assert is_supported_platform() is True
|
||||
|
||||
@patch("src.utils.platform.platform.python_version")
|
||||
def test_old_python_not_supported(self, mock_version):
|
||||
"""Test that old Python versions are not supported."""
|
||||
mock_version.return_value = "3.10.0"
|
||||
|
||||
assert is_supported_platform() is False
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
@patch("src.utils.platform.platform.python_version")
|
||||
def test_supported_systems(self, mock_version, mock_system):
|
||||
"""Test that Darwin, Linux, Windows are supported."""
|
||||
mock_version.return_value = "3.12.0"
|
||||
|
||||
for system in ["Darwin", "Linux", "Windows"]:
|
||||
mock_system.return_value = system
|
||||
assert is_supported_platform() is True
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
@patch("src.utils.platform.platform.python_version")
|
||||
def test_unsupported_system(self, mock_version, mock_system):
|
||||
"""Test that unknown systems are not supported."""
|
||||
mock_version.return_value = "3.12.0"
|
||||
mock_system.return_value = "Unknown"
|
||||
|
||||
assert is_supported_platform() is False
|
||||
|
||||
|
||||
class TestGetDefaultDirectories:
|
||||
"""Tests for default directory functions."""
|
||||
|
||||
def test_config_dir_returns_path(self):
|
||||
"""Test that get_default_config_dir returns a Path."""
|
||||
result = get_default_config_dir()
|
||||
assert isinstance(result, Path)
|
||||
|
||||
def test_data_dir_returns_path(self):
|
||||
"""Test that get_default_data_dir returns a Path."""
|
||||
result = get_default_data_dir()
|
||||
assert isinstance(result, Path)
|
||||
|
||||
def test_log_dir_returns_path(self):
|
||||
"""Test that get_default_log_dir returns a Path."""
|
||||
result = get_default_log_dir()
|
||||
assert isinstance(result, Path)
|
||||
|
||||
def test_maildir_path_returns_path(self):
|
||||
"""Test that get_default_maildir_path returns a Path."""
|
||||
result = get_default_maildir_path()
|
||||
assert isinstance(result, Path)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_macos_config_dir(self, mock_system):
|
||||
"""Test macOS config directory."""
|
||||
mock_system.return_value = "Darwin"
|
||||
|
||||
result = get_default_config_dir()
|
||||
|
||||
assert "Library" in str(result)
|
||||
assert "Application Support" in str(result)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_linux_config_dir_default(self, mock_system):
|
||||
"""Test Linux config directory (default)."""
|
||||
mock_system.return_value = "Linux"
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
result = get_default_config_dir()
|
||||
|
||||
assert ".config" in str(result)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_linux_config_dir_xdg(self, mock_system):
|
||||
"""Test Linux config directory with XDG_CONFIG_HOME."""
|
||||
mock_system.return_value = "Linux"
|
||||
|
||||
with patch.dict(os.environ, {"XDG_CONFIG_HOME": "/custom/config"}):
|
||||
result = get_default_config_dir()
|
||||
|
||||
assert "/custom/config" in str(result)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_windows_config_dir(self, mock_system):
|
||||
"""Test Windows config directory."""
|
||||
mock_system.return_value = "Windows"
|
||||
|
||||
with patch.dict(os.environ, {"APPDATA": "C:\\Users\\test\\AppData\\Roaming"}):
|
||||
result = get_default_config_dir()
|
||||
|
||||
assert "luk" in str(result)
|
||||
|
||||
|
||||
class TestCheckDependencies:
|
||||
"""Tests for check_dependencies function."""
|
||||
|
||||
def test_returns_dict(self):
|
||||
"""Test that check_dependencies returns a dictionary."""
|
||||
result = check_dependencies()
|
||||
assert isinstance(result, dict)
|
||||
|
||||
def test_python_always_available(self):
|
||||
"""Test that Python is always marked as available."""
|
||||
result = check_dependencies()
|
||||
assert result["python"] is True
|
||||
|
||||
def test_contains_expected_keys(self):
|
||||
"""Test that result contains expected dependency keys."""
|
||||
result = check_dependencies()
|
||||
|
||||
expected_keys = ["python", "pip", "git", "curl", "wget"]
|
||||
for key in expected_keys:
|
||||
assert key in result
|
||||
|
||||
def test_values_are_bool(self):
|
||||
"""Test that all values are boolean."""
|
||||
result = check_dependencies()
|
||||
|
||||
for value in result.values():
|
||||
assert isinstance(value, bool)
|
||||
|
||||
|
||||
class TestGetShellInfo:
|
||||
"""Tests for shell info functions."""
|
||||
|
||||
def test_get_shell_info_returns_dict(self):
|
||||
"""Test that get_shell_info returns a dictionary."""
|
||||
result = get_shell_info()
|
||||
assert isinstance(result, dict)
|
||||
|
||||
def test_get_shell_info_keys(self):
|
||||
"""Test that result has expected keys."""
|
||||
result = get_shell_info()
|
||||
|
||||
assert "shell_path" in result
|
||||
assert "shell_name" in result
|
||||
assert "config_file" in result
|
||||
|
||||
def test_get_shell_config_file_bash(self):
|
||||
"""Test shell config file for bash."""
|
||||
result = get_shell_config_file("bash")
|
||||
assert result == "~/.bashrc"
|
||||
|
||||
def test_get_shell_config_file_zsh(self):
|
||||
"""Test shell config file for zsh."""
|
||||
result = get_shell_config_file("zsh")
|
||||
assert result == "~/.zshrc"
|
||||
|
||||
def test_get_shell_config_file_fish(self):
|
||||
"""Test shell config file for fish."""
|
||||
result = get_shell_config_file("fish")
|
||||
assert result == "~/.config/fish/config.fish"
|
||||
|
||||
def test_get_shell_config_file_unknown(self):
|
||||
"""Test shell config file for unknown shell."""
|
||||
result = get_shell_config_file("unknown")
|
||||
assert result == "~/.profile"
|
||||
|
||||
|
||||
class TestGetPlatformSpecificCommands:
|
||||
"""Tests for get_platform_specific_commands function."""
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_macos_commands(self, mock_system):
|
||||
"""Test macOS-specific commands."""
|
||||
mock_system.return_value = "Darwin"
|
||||
|
||||
result = get_platform_specific_commands()
|
||||
|
||||
assert result["open"] == "open"
|
||||
assert result["copy"] == "pbcopy"
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_linux_commands(self, mock_system):
|
||||
"""Test Linux-specific commands."""
|
||||
mock_system.return_value = "Linux"
|
||||
|
||||
result = get_platform_specific_commands()
|
||||
|
||||
assert result["open"] == "xdg-open"
|
||||
assert "xclip" in result["copy"]
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_windows_commands(self, mock_system):
|
||||
"""Test Windows-specific commands."""
|
||||
mock_system.return_value = "Windows"
|
||||
|
||||
result = get_platform_specific_commands()
|
||||
|
||||
assert result["open"] == "start"
|
||||
assert result["copy"] == "clip"
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_unknown_system_commands(self, mock_system):
|
||||
"""Test unknown system returns empty dict."""
|
||||
mock_system.return_value = "Unknown"
|
||||
|
||||
result = get_platform_specific_commands()
|
||||
|
||||
assert result == {}
|
||||
|
||||
|
||||
class TestCheckTerminalCompatibility:
|
||||
"""Tests for terminal compatibility functions."""
|
||||
|
||||
def test_returns_dict(self):
|
||||
"""Test that check_terminal_compatibility returns a dictionary."""
|
||||
result = check_terminal_compatibility()
|
||||
assert isinstance(result, dict)
|
||||
|
||||
def test_contains_expected_keys(self):
|
||||
"""Test that result contains expected keys."""
|
||||
result = check_terminal_compatibility()
|
||||
|
||||
expected_keys = [
|
||||
"color_support",
|
||||
"unicode_support",
|
||||
"mouse_support",
|
||||
"textual_support",
|
||||
]
|
||||
for key in expected_keys:
|
||||
assert key in result
|
||||
|
||||
def test_values_are_bool(self):
|
||||
"""Test that all values are boolean."""
|
||||
result = check_terminal_compatibility()
|
||||
|
||||
for value in result.values():
|
||||
assert isinstance(value, bool)
|
||||
|
||||
def test_check_textual_support(self):
|
||||
"""Test check_textual_support."""
|
||||
# Textual should be available in our test environment
|
||||
result = check_textual_support()
|
||||
assert isinstance(result, bool)
|
||||
|
||||
|
||||
class TestGetPlatformRecommendations:
|
||||
"""Tests for get_platform_recommendations function."""
|
||||
|
||||
def test_returns_list(self):
|
||||
"""Test that get_platform_recommendations returns a list."""
|
||||
result = get_platform_recommendations()
|
||||
assert isinstance(result, list)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_macos_recommendations(self, mock_system):
|
||||
"""Test macOS recommendations."""
|
||||
mock_system.return_value = "Darwin"
|
||||
|
||||
result = get_platform_recommendations()
|
||||
|
||||
assert len(result) > 0
|
||||
# Check for macOS-specific content
|
||||
assert any("iTerm2" in r or "Terminal.app" in r for r in result)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_linux_recommendations(self, mock_system):
|
||||
"""Test Linux recommendations."""
|
||||
mock_system.return_value = "Linux"
|
||||
|
||||
result = get_platform_recommendations()
|
||||
|
||||
assert len(result) > 0
|
||||
# Check for Linux-specific content
|
||||
assert any("UTF-8" in r or "GNOME" in r for r in result)
|
||||
|
||||
@patch("src.utils.platform.platform.system")
|
||||
def test_windows_recommendations(self, mock_system):
|
||||
"""Test Windows recommendations."""
|
||||
mock_system.return_value = "Windows"
|
||||
|
||||
result = get_platform_recommendations()
|
||||
|
||||
assert len(result) > 0
|
||||
# Check for Windows-specific content
|
||||
assert any("Windows Terminal" in r or "WSL" in r for r in result)
|
||||
|
||||
|
||||
class TestValidateEnvironment:
|
||||
"""Tests for validate_environment function."""
|
||||
|
||||
def test_returns_dict(self):
|
||||
"""Test that validate_environment returns a dictionary."""
|
||||
result = validate_environment()
|
||||
assert isinstance(result, dict)
|
||||
|
||||
def test_contains_required_keys(self):
|
||||
"""Test that result contains required keys."""
|
||||
result = validate_environment()
|
||||
|
||||
required_keys = [
|
||||
"platform_supported",
|
||||
"platform_info",
|
||||
"dependencies",
|
||||
"terminal_compatibility",
|
||||
"recommendations",
|
||||
"config_dir",
|
||||
"data_dir",
|
||||
"log_dir",
|
||||
]
|
||||
|
||||
for key in required_keys:
|
||||
assert key in result
|
||||
|
||||
def test_platform_supported_is_bool(self):
|
||||
"""Test that platform_supported is boolean."""
|
||||
result = validate_environment()
|
||||
assert isinstance(result["platform_supported"], bool)
|
||||
|
||||
def test_platform_info_is_dict(self):
|
||||
"""Test that platform_info is a dictionary."""
|
||||
result = validate_environment()
|
||||
assert isinstance(result["platform_info"], dict)
|
||||
|
||||
def test_dependencies_is_dict(self):
|
||||
"""Test that dependencies is a dictionary."""
|
||||
result = validate_environment()
|
||||
assert isinstance(result["dependencies"], dict)
|
||||
|
||||
def test_recommendations_is_list(self):
|
||||
"""Test that recommendations is a list."""
|
||||
result = validate_environment()
|
||||
assert isinstance(result["recommendations"], list)
|
||||
|
||||
def test_directory_paths_are_strings(self):
|
||||
"""Test that directory paths are strings."""
|
||||
result = validate_environment()
|
||||
|
||||
assert isinstance(result["config_dir"], str)
|
||||
assert isinstance(result["data_dir"], str)
|
||||
assert isinstance(result["log_dir"], str)
|
||||
Reference in New Issue
Block a user