-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_installer.py
More file actions
130 lines (94 loc) · 4.92 KB
/
Copy pathtest_installer.py
File metadata and controls
130 lines (94 loc) · 4.92 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""Tests for TechScript Python installer package."""
import os
import sys
import unittest
from unittest.mock import patch, MagicMock
# Ensure the package is importable
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from techscript.platform_detect import (
detect, OS, Arch, PlatformInfo, _detect_os, _detect_arch, _detect_termux
)
from techscript.downloader import build_download_url, FALLBACK_TAG
class TestPlatformDetection(unittest.TestCase):
def test_detect_returns_platform_info(self):
info = detect()
self.assertIsInstance(info, PlatformInfo)
self.assertIn(info.os, list(OS))
self.assertIn(info.arch, list(Arch))
self.assertIsInstance(info.is_termux, bool)
def test_windows_x64_asset(self):
info = PlatformInfo(OS.WINDOWS, Arch.X64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-windows-x64.zip")
def test_windows_arm64_asset(self):
info = PlatformInfo(OS.WINDOWS, Arch.ARM64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-windows-arm64.zip")
def test_linux_x64_asset(self):
info = PlatformInfo(OS.LINUX, Arch.X64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-linux-x64.tar.gz")
def test_linux_arm64_asset(self):
info = PlatformInfo(OS.LINUX, Arch.ARM64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-linux-arm64.tar.gz")
def test_macos_x64_asset(self):
info = PlatformInfo(OS.MACOS, Arch.X64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-macos-x64.tar.gz")
def test_macos_arm64_asset(self):
info = PlatformInfo(OS.MACOS, Arch.ARM64, False, None, (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-macos-arm64.tar.gz")
def test_termux_arm64_asset(self):
info = PlatformInfo(OS.LINUX, Arch.ARM64, True, "/data/data/com.termux/files/usr", (3, 11, 0))
self.assertEqual(info.asset_name, "techscript-linux-arm64.tar.gz")
def test_unknown_platform_unsupported(self):
info = PlatformInfo(OS.UNKNOWN, Arch.UNKNOWN, False, None, (3, 11, 0))
self.assertFalse(info.is_supported)
def test_display_name_windows(self):
info = PlatformInfo(OS.WINDOWS, Arch.X64, False, None, (3, 11, 0))
self.assertIn("Windows", info.display_name)
self.assertIn("x64", info.display_name)
def test_display_name_termux(self):
info = PlatformInfo(OS.LINUX, Arch.ARM64, True, "/prefix", (3, 11, 0))
self.assertIn("Termux", info.display_name)
class TestInstallDir(unittest.TestCase):
def test_windows_install_dir(self):
with patch.dict(os.environ, {"LOCALAPPDATA": "C:\\Users\\Test\\AppData\\Local"}):
info = PlatformInfo(OS.WINDOWS, Arch.X64, False, None, (3, 11, 0))
self.assertIn("TechScript", info.install_dir)
self.assertIn("bin", info.install_dir)
def test_linux_install_dir(self):
info = PlatformInfo(OS.LINUX, Arch.X64, False, None, (3, 11, 0))
self.assertIn(".local/bin", info.install_dir)
def test_termux_install_dir(self):
prefix = "/data/data/com.termux/files/usr"
info = PlatformInfo(OS.LINUX, Arch.ARM64, True, prefix, (3, 11, 0))
self.assertEqual(info.install_dir, f"{prefix}/bin")
class TestBinaryName(unittest.TestCase):
def test_windows_binary_name(self):
info = PlatformInfo(OS.WINDOWS, Arch.X64, False, None, (3, 11, 0))
self.assertEqual(info.binary_name, "tsc.exe")
def test_linux_binary_name(self):
info = PlatformInfo(OS.LINUX, Arch.X64, False, None, (3, 11, 0))
self.assertEqual(info.binary_name, "tsc")
def test_macos_binary_name(self):
info = PlatformInfo(OS.MACOS, Arch.ARM64, False, None, (3, 11, 0))
self.assertEqual(info.binary_name, "tsc")
class TestDownloadURL(unittest.TestCase):
def test_build_url_linux(self):
url = build_download_url("release-2.0.0", "techscript-linux-x64.tar.gz")
self.assertIn("release-2.0.0", url)
self.assertIn("techscript-linux-x64.tar.gz", url)
self.assertIn("github.com", url)
def test_fallback_tag_format(self):
self.assertTrue(FALLBACK_TAG.startswith("release-") or FALLBACK_TAG.startswith("v"))
class TestTermuxDetection(unittest.TestCase):
def test_no_termux(self):
with patch.dict(os.environ, {"PREFIX": ""}, clear=False):
is_termux, prefix = _detect_termux()
# Can't guarantee False in all CI environments, just check types
self.assertIsInstance(is_termux, bool)
def test_termux_prefix_env(self):
fake_prefix = "/data/data/com.termux/files/usr"
with patch.dict(os.environ, {"PREFIX": fake_prefix}):
is_termux, prefix = _detect_termux()
self.assertTrue(is_termux)
self.assertEqual(prefix, fake_prefix)
if __name__ == "__main__":
unittest.main()