-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.py
58 lines (47 loc) · 1.54 KB
/
module.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
def test_pybonjour():
import pybonjour
print pybonjour.DNSServiceConstructFullName(regtype="_test._tcp", domain="local")
def test_pysfml():
import sfml
for video_mode in sfml.VideoMode.get_fullscreen_modes():
print (video_mode.width, video_mode.height, video_mode.bpp)
def test_lupa():
import lupa
from lupa import LuaRuntime
lua = LuaRuntime(unpack_returned_tuples=True)
print lua.eval('1+1')
lua_func = lua.eval('function(f, n) return f(n) end')
def py_add1(n): return n+1
print lua_func(py_add1, 2)
print lua.eval('python.eval(" 2 ** 2 ")') == 4
print lua.eval('python.builtins.str(4)') == '4'
def test():
import sys
import traceback
tests = {
'pybonjour': test_pybonjour,
'PySFML': test_pysfml,
'lupa': test_lupa,
}
class FakeStdout:
def __init__(self):
self.text = ''
def write(self, text):
self.text += text
real_stdout = sys.stdout
real_stderr = sys.stderr
for name in tests:
print "Testing %s" % (name,),
fake_stdout = sys.stdout = sys.stderr = FakeStdout()
try:
tests[name]()
sys.stdout = real_stdout
sys.stderr = real_stderr
print "OK"
except:
sys.stdout = real_stdout
sys.stderr = real_stderr
print "KO"
sys.stdout.write(traceback.format_exc())
sys.stdout.write(fake_stdout.text)
print