File size: 4,270 Bytes
aa3e2a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Test_Tkinter.py - device test for tkinter 8.6.14 Android wheels.



IMPORT-LEVEL ONLY (no display needed, no Tk() call): sets up the Android

bootstrap, imports the _tkinter extension, evaluates Tcl, and checks the

vendored data. The GUI test (real Tk window via Termux:X11 DISPLAY) is a

later device phase.



Run on-device via PipManager Scripts folder after installing the matching

tkinter wheel. Pattern: import _tk_android FIRST, then tkinter/_tkinter.

Exit-code contract: exit 0 iff every check PASSes, else exit 1.



Generated by RIMI

"""
import os
import sys

PASS = 0
FAIL = 0


def check(name, cond, detail=""):
    global PASS, FAIL
    if cond:
        PASS += 1
        print("[PASS] %s %s" % (name, detail))
    else:
        FAIL += 1
        print("[FAIL] %s %s" % (name, detail))


print("tkinter device test - python %s" % sys.version.split()[0])

# 1. bootstrap import (env setup + native preload)
try:
    import _tk_android
    check("import _tk_android", True, _tk_android.__file__)
except Exception as e:
    check("import _tk_android", False, repr(e))
    print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
    sys.exit(1)

# 2. env vars point at bundled dirs
try:
    here = os.path.dirname(os.path.abspath(_tk_android.__file__))
    ok = (os.environ.get("TCL_LIBRARY") == os.path.join(here, "tcl8.6")
          and os.environ.get("TK_LIBRARY") == os.path.join(here, "tk8.6")
          and os.environ.get("XLOCALEDIR") == os.path.join(here, "X11", "locale"))
    check("bootstrap env TCL/TK/XLOCALEDIR", ok,
          "TCL=%s" % os.environ.get("TCL_LIBRARY"))
except Exception as e:
    check("bootstrap env TCL/TK/XLOCALEDIR", False, repr(e))

# 3. fonts.conf generated
try:
    fc = os.environ.get("FONTCONFIG_FILE", "")
    check("fonts.conf generated", os.path.isfile(fc), fc)
except Exception as e:
    check("fonts.conf generated", False, repr(e))

# 4. bundled natives present
try:
    libs = [os.path.join(here, n) for n in ("libtcl8.6.so", "libtk8.6.so")]
    ok = all(os.path.isfile(p) and os.path.getsize(p) > 100000 for p in libs)
    check("bundled libtcl/libtk present", ok,
          "tcl=%d tk=%d" % tuple(os.path.getsize(p) if os.path.isfile(p) else -1 for p in libs))
except Exception as e:
    check("bundled libtcl/libtk present", False, repr(e))

# 5. _tkinter extension import (resolves from this wheel; app ships none)
try:
    import _tkinter
    check("import _tkinter", True, _tkinter.__file__)
except Exception as e:
    check("import _tkinter", False, repr(e))
    print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
    sys.exit(1)

# 6. headless Tcl interpreter (wantTk=0 -> no display needed)
try:
    t = _tkinter.create("", "tkintertest", "Tk", 0, 0, 0, 0, None)
    check("headless Tcl interp (wantTk=0)", True, repr(t)[:60])
except Exception as e:
    check("headless Tcl interp (wantTk=0)", False, repr(e))
    print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
    sys.exit(1)

# 7. Tcl patchlevel 8.6.14
try:
    pl = t.call("info", "patchlevel")
    check("Tcl patchlevel 8.6.14", pl == "8.6.14", "got=%s" % pl)
except Exception as e:
    check("Tcl patchlevel 8.6.14", False, repr(e))

# 8. Tcl_Eval arithmetic
try:
    r = t.call("expr", "6*7")
    check("Tcl expr 6*7=42", str(r) == "42", "got=%s" % r)
except Exception as e:
    check("Tcl expr 6*7=42", False, repr(e))

# 9. clock with tzdata (vendored tzdata/ required for -timezone)
try:
    r = t.call("clock", "format", 0, "-format", "%Y-%m-%d",
               "-timezone", ":America/New_York")
    check("clock tzdata America/New_York", str(r) == "1969-12-31", "got=%s" % r)
except Exception as e:
    check("clock tzdata America/New_York", False, repr(e))

# 10. stdlib tkinter package still wins for .py (no shadowing) + Tk class
try:
    import tkinter
    check("stdlib tkinter unshadowed", "tkinter" in tkinter.__file__ and hasattr(tkinter, "Tk"),
          tkinter.__file__[:80])
except Exception as e:
    check("stdlib tkinter unshadowed", False, repr(e))

print("NOTE: GUI test (Tk() window) needs Termux:X11 + DISPLAY=127.0.0.1:0 - later phase")
print("RESULT: %d PASS, %d FAIL" % (PASS, FAIL))
sys.exit(0 if FAIL == 0 else 1)