Skip to content

Commit 59926c5

Browse files
committed
rust: refactor interpreter verification tests to use unittest
This seems strictly better than using assert. This way we'll get reported of multiple test failures.
1 parent 8ec34e8 commit 59926c5

File tree

2 files changed

+125
-146
lines changed

2 files changed

+125
-146
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ fn verify_distribution_behavior(dist_path: &Path) -> Result<Vec<String>> {
857857
let test_file = temp_dir.path().join("verify.py");
858858
std::fs::write(&test_file, PYTHON_VERIFICATIONS.as_bytes())?;
859859

860-
eprintln!(" running interpreter tests (output may follow)");
860+
eprintln!(" running interpreter tests (output should follow)");
861861
let output = duct::cmd(&python_exe, &[test_file.display().to_string()])
862862
.stdout_to_stderr()
863863
.unchecked()

src/verify_distribution.py

Lines changed: 124 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -2,157 +2,136 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
import os
6+
import sys
7+
import unittest
8+
9+
510
TERMINFO_DIRS = [
611
"/etc/terminfo",
712
"/lib/terminfo",
813
"/usr/share/terminfo",
914
]
1015

11-
12-
def verify():
13-
"""Verifies that a built Python distribution behaves as expected."""
14-
import sys
15-
16-
sys.dont_write_bytecode = True
17-
18-
import os
19-
20-
here = os.path.dirname(sys.executable)
21-
install_root = os.path.dirname(here)
22-
23-
# Need to set TCL_LIBRARY so local tcl/tk files get picked up.
24-
os.environ["TCL_LIBRARY"] = os.path.join(install_root, "lib", "tcl", "tcl")
25-
26-
# Need to set TERMINFO_DIRS so terminfo database can be located.
27-
if "TERMINFO_DIRS" not in os.environ:
28-
terminfo_dirs = [p for p in TERMINFO_DIRS if os.path.exists(p)]
29-
if terminfo_dirs:
30-
os.environ["TERMINFO_DIRS"] = ":".join(terminfo_dirs)
31-
32-
verify_compression()
33-
verify_ctypes()
34-
verify_curses()
35-
verify_hashlib()
36-
verify_sqlite()
37-
verify_ssl()
38-
verify_tkinter()
39-
40-
41-
def verify_compression():
42-
import bz2, lzma, zlib
43-
44-
assert lzma.is_check_supported(lzma.CHECK_CRC64)
45-
assert lzma.is_check_supported(lzma.CHECK_SHA256)
46-
47-
48-
def verify_ctypes():
49-
import ctypes
50-
51-
assert ctypes.pythonapi is not None
52-
53-
# https://bugs.python.org/issue42688
54-
@ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p)
55-
def error_handler(fif, message):
56-
pass
57-
58-
59-
def verify_curses():
60-
import curses, os
61-
62-
if "TERM" not in os.environ:
63-
return
64-
65-
curses.initscr()
66-
curses.endwin()
67-
68-
69-
def verify_hashlib():
70-
import hashlib
71-
72-
wanted_hashes = {
73-
"blake2b",
74-
"blake2s",
75-
"md4",
76-
"md5",
77-
"md5-sha1",
78-
"mdc2",
79-
"ripemd160",
80-
"sha1",
81-
"sha224",
82-
"sha256",
83-
"sha3_224",
84-
"sha3_256",
85-
"sha3_384",
86-
"sha3_512",
87-
"sha384",
88-
"sha3_224",
89-
"sha3_256",
90-
"sha3_384",
91-
"sha3_512",
92-
"sha512",
93-
"sha512_224",
94-
"sha512_256",
95-
"shake_128",
96-
"shake_256",
97-
"shake_128",
98-
"shake_256",
99-
"sm3",
100-
"whirlpool",
101-
}
102-
103-
missing_hashes = wanted_hashes - hashlib.algorithms_available
104-
105-
assert not missing_hashes, "missing hashes: %s" % missing_hashes
106-
107-
108-
def verify_sqlite():
109-
import sqlite3
110-
111-
assert sqlite3.sqlite_version_info == (3, 35, 4), "got %r" % (
112-
sqlite3.sqlite_version_info,
113-
)
114-
115-
116-
def verify_ssl():
117-
import ssl
118-
119-
assert ssl.HAS_TLSv1
120-
assert ssl.HAS_TLSv1_1
121-
assert ssl.HAS_TLSv1_2
122-
assert ssl.HAS_TLSv1_3
123-
124-
assert ssl.OPENSSL_VERSION_INFO == (1, 1, 1, 11, 15), "got %r" % (
125-
ssl.OPENSSL_VERSION_INFO,
126-
)
127-
128-
context = ssl.create_default_context()
129-
130-
131-
def verify_tkinter():
132-
import tkinter as tk
133-
134-
class Application(tk.Frame):
135-
def __init__(self, master=None):
136-
super().__init__(master)
137-
self.master = master
138-
self.pack()
139-
140-
self.hi_there = tk.Button(self)
141-
self.hi_there["text"] = "Hello World\n(click me)"
142-
self.hi_there["command"] = self.say_hi
143-
self.hi_there.pack(side="top")
144-
145-
self.quit = tk.Button(
146-
self, text="QUIT", fg="red", command=self.master.destroy
147-
)
148-
self.quit.pack(side="bottom")
149-
150-
def say_hi(self):
151-
print("hi there, everyone!")
152-
153-
root = tk.Tk()
154-
Application(master=root)
16+
HERE = os.path.dirname(sys.executable)
17+
INSTALL_ROOT = os.path.dirname(HERE)
18+
19+
# Need to set TCL_LIBRARY so local tcl/tk files get picked up.
20+
os.environ["TCL_LIBRARY"] = os.path.join(INSTALL_ROOT, "lib", "tcl", "tcl")
21+
22+
# Need to set TERMINFO_DIRS so terminfo database can be located.
23+
if "TERMINFO_DIRS" not in os.environ:
24+
terminfo_dirs = [p for p in TERMINFO_DIRS if os.path.exists(p)]
25+
if terminfo_dirs:
26+
os.environ["TERMINFO_DIRS"] = ":".join(terminfo_dirs)
27+
28+
29+
class TestPythonInterpreter(unittest.TestCase):
30+
def test_compression(self):
31+
import bz2, lzma, zlib
32+
33+
self.assertTrue(lzma.is_check_supported(lzma.CHECK_CRC64))
34+
self.assertTrue(lzma.is_check_supported(lzma.CHECK_SHA256))
35+
36+
def test_ctypes(self):
37+
import ctypes
38+
39+
self.assertIsNotNone(ctypes.pythonapi)
40+
41+
# https://bugs.python.org/issue42688
42+
@ctypes.CFUNCTYPE(None, ctypes.c_int, ctypes.c_char_p)
43+
def error_handler(fif, message):
44+
pass
45+
46+
def test_curses_import(self):
47+
import curses
48+
49+
@unittest.skipIf("TERM" not in os.environ, "TERM not set")
50+
def test_curses_interactive(self):
51+
import curses
52+
53+
curses.initscr()
54+
curses.endwin()
55+
56+
def test_hashlib(self):
57+
import hashlib
58+
59+
wanted_hashes = {
60+
"blake2b",
61+
"blake2s",
62+
"md4",
63+
"md5",
64+
"md5-sha1",
65+
"mdc2",
66+
"ripemd160",
67+
"sha1",
68+
"sha224",
69+
"sha256",
70+
"sha3_224",
71+
"sha3_256",
72+
"sha3_384",
73+
"sha3_512",
74+
"sha384",
75+
"sha3_224",
76+
"sha3_256",
77+
"sha3_384",
78+
"sha3_512",
79+
"sha512",
80+
"sha512_224",
81+
"sha512_256",
82+
"shake_128",
83+
"shake_256",
84+
"shake_128",
85+
"shake_256",
86+
"sm3",
87+
"whirlpool",
88+
}
89+
90+
for hash in wanted_hashes:
91+
self.assertIn(hash, hashlib.algorithms_available)
92+
93+
def test_sqlite(self):
94+
import sqlite3
95+
96+
self.assertEqual(sqlite3.sqlite_version_info, (3, 35, 4))
97+
98+
def test_ssl(self):
99+
import ssl
100+
101+
self.assertTrue(ssl.HAS_TLSv1)
102+
self.assertTrue(ssl.HAS_TLSv1_1)
103+
self.assertTrue(ssl.HAS_TLSv1_2)
104+
self.assertTrue(ssl.HAS_TLSv1_3)
105+
106+
self.assertEqual(ssl.OPENSSL_VERSION_INFO, (1, 1, 1, 11, 15))
107+
108+
ssl.create_default_context()
109+
110+
def test_tkinter(self):
111+
import tkinter as tk
112+
113+
class Application(tk.Frame):
114+
def __init__(self, master=None):
115+
super().__init__(master)
116+
self.master = master
117+
self.pack()
118+
119+
self.hi_there = tk.Button(self)
120+
self.hi_there["text"] = "Hello World\n(click me)"
121+
self.hi_there["command"] = self.say_hi
122+
self.hi_there.pack(side="top")
123+
124+
self.quit = tk.Button(
125+
self, text="QUIT", fg="red", command=self.master.destroy
126+
)
127+
self.quit.pack(side="bottom")
128+
129+
def say_hi(self):
130+
print("hi there, everyone!")
131+
132+
root = tk.Tk()
133+
Application(master=root)
155134

156135

157136
if __name__ == "__main__":
158-
verify()
137+
unittest.main()

0 commit comments

Comments
 (0)