This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
/
test_windows.py
100 lines (88 loc) · 2.77 KB
/
test_windows.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
"""
@brief test log(time=1s)
"""
import os
import sys
import unittest
import warnings
if sys.version_info[0] == 2:
from Tkinter import TclError
else:
from tkinter import TclError
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
from src.pyquickhelper.loghelper.flog import fLOG
from src.pyquickhelper.pycode import fix_tkinter_issues_virtualenv
from src.pyquickhelper.funcwin import open_window_params, open_window_function
from src.pyquickhelper.funcwin.function_helper import get_function_list, has_unknown_parameters, private_get_function
def my_tst_function(a, b):
"""
return a+b
@param a (float) float
@param b (float) float
@return a+b
"""
return (a or 1) + (b or 1)
class TestWindows (unittest.TestCase):
def test_open_window_params(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
fix_tkinter_issues_virtualenv(fLOG=fLOG)
params = dict(p1="p1", p2=3)
try:
win = open_window_params(params, do_not_open=True)
except TclError as e:
warnings.warn("TclError" + str(e))
return
fLOG(type(win))
assert isinstance(
win,
src.pyquickhelper.funcwin.frame_params.FrameParams)
def test_open_window_function(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
fix_tkinter_issues_virtualenv(fLOG=fLOG)
func = my_tst_function
try:
win = open_window_function(func, do_not_open=True)
except TclError as e:
warnings.warn("TclError" + str(e))
return
fLOG(type(win))
assert isinstance(
win,
src.pyquickhelper.funcwin.frame_function.FrameFunction)
win.refresh()
win.update()
win.run_function(0, 1)
def test_get_function_list(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
fix_tkinter_issues_virtualenv(fLOG=fLOG)
funcs = get_function_list(src.pyquickhelper)
assert isinstance(funcs, dict)
assert len(funcs) > 0
if "load_ipython_extension" not in funcs:
raise Exception("\n".join(sorted(funcs.keys())))
r = has_unknown_parameters(funcs["load_ipython_extension"])
assert not r
f = private_get_function("os.listdir")
fLOG("**", f)
if __name__ == "__main__":
unittest.main()