|
| 1 | +# This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | + |
| 6 | +def verify(): |
| 7 | + """Verifies that a built Python distribution behaves as expected.""" |
| 8 | + import sys |
| 9 | + |
| 10 | + sys.dont_write_bytecode = True |
| 11 | + |
| 12 | + import os |
| 13 | + |
| 14 | + here = os.path.dirname(sys.executable) |
| 15 | + install_root = os.path.dirname(here) |
| 16 | + |
| 17 | + # Need to set TCL_LIBRARY so local tcl/tk files get picked up. |
| 18 | + os.environ["TCL_LIBRARY"] = os.path.join(install_root, "lib", "tcl", "tcl") |
| 19 | + |
| 20 | + verify_compression() |
| 21 | + verify_ctypes() |
| 22 | + verify_curses() |
| 23 | + verify_hashlib() |
| 24 | + verify_sqlite() |
| 25 | + verify_ssl() |
| 26 | + verify_tkinter() |
| 27 | + |
| 28 | + print("distribution verified!") |
| 29 | + |
| 30 | + |
| 31 | +def verify_compression(): |
| 32 | + import bz2, lzma, zlib |
| 33 | + |
| 34 | + assert lzma.is_check_supported(lzma.CHECK_CRC64) |
| 35 | + assert lzma.is_check_supported(lzma.CHECK_SHA256) |
| 36 | + |
| 37 | + |
| 38 | +def verify_ctypes(): |
| 39 | + import ctypes |
| 40 | + |
| 41 | + assert ctypes.pythonapi is not None |
| 42 | + |
| 43 | + |
| 44 | +def verify_curses(): |
| 45 | + import curses |
| 46 | + |
| 47 | + curses.initscr() |
| 48 | + curses.endwin() |
| 49 | + |
| 50 | + |
| 51 | +def verify_hashlib(): |
| 52 | + import hashlib |
| 53 | + |
| 54 | + assert hashlib.algorithms_available == { |
| 55 | + "blake2b", |
| 56 | + "blake2b512", |
| 57 | + "blake2s", |
| 58 | + "blake2s256", |
| 59 | + "md4", |
| 60 | + "md5", |
| 61 | + "md5-sha1", |
| 62 | + "mdc2", |
| 63 | + "ripemd160", |
| 64 | + "sha1", |
| 65 | + "sha224", |
| 66 | + "sha256", |
| 67 | + "sha3-224", |
| 68 | + "sha3-256", |
| 69 | + "sha3-384", |
| 70 | + "sha3-512", |
| 71 | + "sha384", |
| 72 | + "sha3_224", |
| 73 | + "sha3_256", |
| 74 | + "sha3_384", |
| 75 | + "sha3_512", |
| 76 | + "sha512", |
| 77 | + "sha512-224", |
| 78 | + "sha512-256", |
| 79 | + "shake128", |
| 80 | + "shake256", |
| 81 | + "shake_128", |
| 82 | + "shake_256", |
| 83 | + "sm3", |
| 84 | + "whirlpool", |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | +def verify_sqlite(): |
| 89 | + import sqlite3 |
| 90 | + |
| 91 | + assert sqlite3.sqlite_version_info == (3, 29, 0) |
| 92 | + |
| 93 | + |
| 94 | +def verify_ssl(): |
| 95 | + import ssl |
| 96 | + |
| 97 | + assert ssl.HAS_TLSv1 |
| 98 | + assert ssl.HAS_TLSv1_1 |
| 99 | + assert ssl.HAS_TLSv1_2 |
| 100 | + assert ssl.HAS_TLSv1_3 |
| 101 | + |
| 102 | + assert ssl.OPENSSL_VERSION_INFO == (1, 1, 1, 3, 15) |
| 103 | + |
| 104 | + context = ssl.create_default_context() |
| 105 | + |
| 106 | + |
| 107 | +def verify_tkinter(): |
| 108 | + import tkinter as tk |
| 109 | + |
| 110 | + class Application(tk.Frame): |
| 111 | + def __init__(self, master=None): |
| 112 | + super().__init__(master) |
| 113 | + self.master = master |
| 114 | + self.pack() |
| 115 | + |
| 116 | + self.hi_there = tk.Button(self) |
| 117 | + self.hi_there["text"] = "Hello World\n(click me)" |
| 118 | + self.hi_there["command"] = self.say_hi |
| 119 | + self.hi_there.pack(side="top") |
| 120 | + |
| 121 | + self.quit = tk.Button( |
| 122 | + self, text="QUIT", fg="red", command=self.master.destroy |
| 123 | + ) |
| 124 | + self.quit.pack(side="bottom") |
| 125 | + |
| 126 | + def say_hi(self): |
| 127 | + print("hi there, everyone!") |
| 128 | + |
| 129 | + root = tk.Tk() |
| 130 | + Application(master=root) |
| 131 | + |
| 132 | + |
| 133 | +if __name__ == "__main__": |
| 134 | + verify() |
0 commit comments