-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
89 lines (63 loc) · 1.69 KB
/
test.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
import sys
import time
import fuse
from threading import Thread
from remarkable_update_fuse import KillableThread
from remarkable_update_fuse.fuse import lock
from remarkable_update_fuse.fuse import _lock
from remarkable_update_fuse.fuse import FuseArgs
FAILED = False
def assert_value(name, value, expected):
global FAILED
print(f"checking {name}: ", end="")
if value != expected:
print("fail")
FAILED = True
print(f" {value} != {expected}")
return
print("pass")
def assert_true(name, value):
global FAILED
print(f"checking {name}: ", end="")
if not value:
print("fail")
FAILED = True
return
print("pass")
def assert_subclass(value, cls):
global FAILED
print(f"checking {value.__name__} is subclass of {cls.__name__}: ", end="")
if not issubclass(value, cls):
print("fail")
FAILED = True
return
print("pass")
assert_subclass(KillableThread, Thread)
def _while_true():
while True:
pass
thread = KillableThread(
target=_while_true,
name="while-true",
)
thread.start()
assert_true("thread.is_alive()", thread.is_alive())
thread.kill()
time.sleep(0.1) # Wait for thread to exit
assert_true("not thread.is_alive()", not thread.is_alive())
assert_true("not locked", not _lock.locked())
with lock():
assert_true("locked", _lock.locked())
assert_true("not locked", not _lock.locked())
assert_value("fuse.fuse_python_api", fuse.fuse_python_api, (0, 2))
assert_value(
"FuseArgs.__str__",
str(FuseArgs()),
"""
< None on None:
{'showhelp': False, 'showversion': False, 'foreground': False}
-o (none) >
""".strip(),
)
if FAILED:
sys.exit(1)