forked from astral-sh/python-build-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_distribution.py
187 lines (146 loc) · 5.29 KB
/
verify_distribution.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import os
import sys
import unittest
TERMINFO_DIRS = [
"/etc/terminfo",
"/lib/terminfo",
"/usr/share/terminfo",
]
TCL_PATHS = [
# POSIX
("lib", "tcl", "tcl"),
# Windows.
("tcl",),
]
HERE = os.path.dirname(sys.executable)
INSTALL_ROOT = os.path.dirname(HERE)
# Need to set TCL_LIBRARY so local tcl/tk files get picked up.
for parts in TCL_PATHS:
candidate = os.path.join(INSTALL_ROOT, *parts)
if os.path.exists(candidate):
os.environ["TCL_LIBRARY"] = candidate
break
# Need to set TERMINFO_DIRS so terminfo database can be located.
if "TERMINFO_DIRS" not in os.environ:
terminfo_dirs = [p for p in TERMINFO_DIRS if os.path.exists(p)]
if terminfo_dirs:
os.environ["TERMINFO_DIRS"] = ":".join(terminfo_dirs)
class TestPythonInterpreter(unittest.TestCase):
def test_compression(self):
import bz2
import lzma
import zlib
self.assertTrue(lzma.is_check_supported(lzma.CHECK_CRC64))
self.assertTrue(lzma.is_check_supported(lzma.CHECK_SHA256))
bz2.compress(b"test")
zlib.compress(b"test")
def test_ctypes(self):
import ctypes
# pythonapi will be None on statically linked binaries.
if os.environ["TARGET_TRIPLE"].endswith("-unknown-linux-musl"):
self.assertIsNone(ctypes.pythonapi)
else:
self.assertIsNotNone(ctypes.pythonapi)
# https://bugs.python.org/issue42688
@ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p)
def error_handler(fif, message):
pass
@unittest.skipIf(os.name == "nt", "curses not available on Windows")
def test_curses_import(self):
import curses
assert curses is not None
@unittest.skipIf(os.name == "nt", "curses not available on Windows")
@unittest.skipIf("TERM" not in os.environ, "TERM not set")
def test_curses_interactive(self):
import curses
curses.initscr()
curses.endwin()
def test_hashlib(self):
import hashlib
wanted_hashes = {
"blake2b",
"blake2s",
"md5",
"md5-sha1",
"ripemd160",
"sha1",
"sha224",
"sha256",
"sha384",
"sha3_224",
"sha3_256",
"sha3_384",
"sha3_512",
"sha512",
"sha512_224",
"sha512_256",
"shake_128",
"shake_256",
"sm3",
}
# Legacy algorithms only present on OpenSSL 1.1.
if os.name == "nt" and sys.version_info[0:2] < (3, 11):
wanted_hashes.add("md4")
wanted_hashes.add("whirlpool")
for hash in wanted_hashes:
self.assertIn(hash, hashlib.algorithms_available)
def test_sqlite(self):
import sqlite3
self.assertEqual(sqlite3.sqlite_version_info, (3, 47, 1))
# Optional SQLite3 features are enabled.
conn = sqlite3.connect(":memory:")
# Extension loading enabled.
self.assertTrue(hasattr(conn, "enable_load_extension"))
# Backup feature requires modern SQLite, which we always have.
self.assertTrue(hasattr(conn, "backup"))
def test_ssl(self):
import ssl
self.assertTrue(ssl.HAS_TLSv1)
self.assertTrue(ssl.HAS_TLSv1_1)
self.assertTrue(ssl.HAS_TLSv1_2)
self.assertTrue(ssl.HAS_TLSv1_3)
# OpenSSL 1.1 on older CPython versions on Windows. 3.0 everywhere
# else.
if os.name == "nt" and sys.version_info[0:2] < (3, 11):
wanted_version = (1, 1, 1, 23, 15)
else:
wanted_version = (3, 0, 0, 15, 0)
self.assertEqual(ssl.OPENSSL_VERSION_INFO, wanted_version)
ssl.create_default_context()
@unittest.skipIf(
sys.version_info[:2] < (3, 13),
"Free-threaded builds are only available in 3.13+",
)
def test_gil_disabled(self):
import sysconfig
if "freethreaded" in os.environ.get("BUILD_OPTIONS", "").split("+"):
wanted = 1
else:
wanted = 0
self.assertEqual(sysconfig.get_config_var("Py_GIL_DISABLED"), wanted)
@unittest.skipIf("TCL_LIBRARY" not in os.environ, "TCL_LIBRARY not set")
@unittest.skipIf("DISPLAY" not in os.environ, "DISPLAY not set")
def test_tkinter(self):
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello World\n(click me)"
self.hi_there["command"] = self.say_hi
self.hi_there.pack(side="top")
self.quit = tk.Button(
self, text="QUIT", fg="red", command=self.master.destroy
)
self.quit.pack(side="bottom")
def say_hi(self):
print("hi there, everyone!")
root = tk.Tk()
Application(master=root)
if __name__ == "__main__":
unittest.main()