-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTEST_activity.py
executable file
·79 lines (71 loc) · 2.33 KB
/
TEST_activity.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
#!/usr/bin/env python
__import__('sys').path.append(__import__('os').path.join(__import__('os').path.dirname(__file__), ''))
__import__('testfwk').setup(__file__)
# - prolog marker
from testfwk import run_test, try_catch
from grid_control.utils.activity import Activity, ProgressActivity
from grid_control_gui.report_bar import ProgressBarActivity
def display_activity(root):
for entry in root.get_children():
print('%s %s' % ('-' * entry.depth, entry.get_msg(truncate = 30, last = 10)))
class Test_Activity:
"""
>>> try_catch(lambda: Activity(parent = 'nobody'), 'APIError', 'Invalid parent')
caught
>>> Activity.root.finish()
>>> del Activity.root
>>> Activity.root = Activity('Testing', name = 'root')
>>> Activity.root
Activity(name: 'root', msg_dict: {'msg': 'Testing'}, lvl: 20, depth: 0, parent: None)
>>> a = Activity('Working on A', name = 'a')
>>> a1 = Activity('Working on A1')
>>> try_catch(lambda: Activity('Working on AX', parent='a1'), 'APIError', 'Invalid parent given')
caught
>>> p1 = ProgressActivity(parent = 'a')
>>> a2 = Activity('Working on A2', parent = 'a')
>>> a2x = Activity('Working on A2' + 'x'*100)
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- ...
-- Working on A2...
--- Working on A2xxxx...xxxxxxx...
>>> a2
Activity(name: None, msg_dict: {'msg': 'Working on A2'}, lvl: 20, depth: 2, parent: a)
>>> a2.finish()
>>> p1.update_progress(12)
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- [13]...
>>> p1.update_progress(12, 14)
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- [13 / 14]...
>>> p1.update_progress(20, 100, 'progressing')
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- progressing [21 / 100]...
>>> pb1 = ProgressBarActivity('bar_test', 12, width=12)
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- progressing [21 / 100]...
--- [> 0% ] bar_test...
>>> pb1.update('test_bar')
>>> pb1.update_progress(6)
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- progressing [21 / 100]...
--- [====50% ] test_bar...
>>> pb1.update_progress(12, msg='finish')
>>> display_activity(Activity.root)
- Working on A...
-- Working on A1...
-- progressing [21 / 100]...
--- [===100%===] finish...
"""
run_test()