35 lines
1.8 KiB
Python
35 lines
1.8 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
from samsara.core.detection import detect_local_os, check_profile, PROFILES
|
|
|
|
class DetectionTests(unittest.TestCase):
|
|
@patch('samsara.core.detection.platform.system', return_value='Linux')
|
|
def test_rhel_and_compatible_release(self, system):
|
|
for release in ['ID=rhel\nVERSION_ID="9.4"\nPRETTY_NAME="Red Hat Enterprise Linux 9.4"',
|
|
'ID=rocky\nID_LIKE="rhel centos fedora"\nVERSION_ID=9.4']:
|
|
with patch('samsara.core.detection.Path.read_text', return_value=release):
|
|
info = detect_local_os()
|
|
self.assertEqual(info['family'], 'rhel')
|
|
self.assertEqual(info['version'], '9')
|
|
check_profile(info, 'rhel:9')
|
|
check_profile(info, 'rhel:any')
|
|
with self.assertRaises(ValueError):
|
|
check_profile(info, 'rhel:8')
|
|
|
|
@patch('samsara.core.detection.platform.system', return_value='Linux')
|
|
@patch('samsara.core.detection.Path.read_text', return_value='ID=linuxmint\nID_LIKE="ubuntu debian"\nVERSION_ID=22\nPRETTY_NAME="Linux Mint"')
|
|
def test_generic_linux_not_misidentified_as_rhel(self, release, system):
|
|
info = detect_local_os()
|
|
self.assertEqual(info['family'], 'linux')
|
|
check_profile(info, 'auto')
|
|
with self.assertRaises(ValueError):
|
|
check_profile(info, 'rhel:any')
|
|
|
|
@patch('samsara.core.detection.platform.system', return_value='Windows')
|
|
@patch('samsara.core.detection.platform.win32_ver', return_value=('11', '', '', ''))
|
|
def test_windows_desktop_not_invented_as_server(self, version, system):
|
|
info = detect_local_os()
|
|
self.assertEqual(info['platform'], 'windows')
|
|
self.assertEqual(info['version'], '')
|
|
self.assertIn(('Windows Server 2025', 'windows:2025'), PROFILES)
|