-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_platform_utils.py
More file actions
90 lines (77 loc) · 2.97 KB
/
test_platform_utils.py
File metadata and controls
90 lines (77 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Tests for platform utilities."""
import pytest
import platform
from pathlib import Path
from unittest.mock import patch
from thothctl.utils.platform_utils import (
is_windows,
is_linux,
is_macos,
get_executable_name,
get_config_dir,
get_shell_config_file,
normalize_path,
run_command
)
class TestPlatformUtils:
"""Test platform utility functions."""
def test_platform_detection(self):
"""Test platform detection functions."""
current_system = platform.system()
if current_system == "Windows":
assert is_windows() is True
assert is_linux() is False
assert is_macos() is False
elif current_system == "Linux":
assert is_windows() is False
assert is_linux() is True
assert is_macos() is False
elif current_system == "Darwin":
assert is_windows() is False
assert is_linux() is False
assert is_macos() is True
@patch('platform.system')
def test_get_executable_name_windows(self, mock_system):
"""Test executable name on Windows."""
mock_system.return_value = "Windows"
assert get_executable_name("terraform") == "terraform.exe"
assert get_executable_name("checkov") == "checkov.exe"
@patch('platform.system')
def test_get_executable_name_unix(self, mock_system):
"""Test executable name on Unix systems."""
mock_system.return_value = "Linux"
assert get_executable_name("terraform") == "terraform"
assert get_executable_name("checkov") == "checkov"
@patch('platform.system')
def test_get_config_dir_windows(self, mock_system):
"""Test config directory on Windows."""
mock_system.return_value = "Windows"
config_dir = get_config_dir()
assert "AppData" in str(config_dir)
assert "thothctl" in str(config_dir)
@patch('platform.system')
def test_get_config_dir_unix(self, mock_system):
"""Test config directory on Unix systems."""
mock_system.return_value = "Linux"
config_dir = get_config_dir()
assert ".thothcf" in str(config_dir)
def test_normalize_path(self):
"""Test path normalization."""
test_path = "test/path"
normalized = normalize_path(test_path)
assert isinstance(normalized, Path)
assert normalized.is_absolute()
@patch('platform.system')
def test_run_command_windows(self, mock_system):
"""Test command execution on Windows."""
mock_system.return_value = "Windows"
# This would use shell=True on Windows
# We can't easily test subprocess.run without mocking it
pass
@patch('platform.system')
def test_run_command_unix(self, mock_system):
"""Test command execution on Unix systems."""
mock_system.return_value = "Linux"
# This would not use shell=True on Unix
# We can't easily test subprocess.run without mocking it
pass