-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEST_report.py
executable file
·166 lines (147 loc) · 8 KB
/
TEST_report.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python
__import__('sys').path.append(__import__('os').path.join(__import__('os').path.dirname(__file__), ''))
__import__('testfwk').setup(__file__)
# - prolog marker
import time
from testfwk import cleanup_workflow, create_config, run_test, testfwk_create_workflow, testfwk_remove_files, try_catch
from grid_control.report import Report
from grid_control_gui.ansi import ANSI
from grid_control_gui.report_colorbar import JobProgressBar
from python_compat import BytesBuffer
class TestImageReport(Report.get_class('ImageReport')):
def show_report(self, job_db, jobnum_list):
buffer = BytesBuffer()
self._show_image('test.png', buffer)
buffer.close()
def test_report(name, *args, **kwargs):
job_db = args[0]
config = kwargs.get('config') or create_config()
report = Report.create_instance(name, config, 'test', *args)
report.show_report(job_db, job_db.get_job_list())
return report
class Test_Report(object):
"""
>>> workflow = testfwk_create_workflow({'jobs': {'jobs': 1}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> try_catch(lambda: Report.create_instance('Report', create_config(), 'test', workflow.job_manager.job_db).show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list()), 'AbstractError', 'is an abstract function')
caught
>>> tmp = test_report('BasicHeaderReport', workflow.job_manager.job_db)
-----------------------------------------------------------------
REPORT SUMMARY:
---------------
>>> tmp = test_report('BasicHeaderReport', workflow.job_manager.job_db, workflow.task)
-----------------------------------------------------------------
REPORT SUMMARY: unnamed / GC0000000000
---------------
>>> workflow = testfwk_create_workflow({'jobs': {'jobs': 1}, 'global': {'config id': 'very long and descriptive config name'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = test_report('BasicHeaderReport', workflow.job_manager.job_db, workflow.task)
-----------------------------------------------------------------
REPORT SUMMARY: very long and descriptive config name
---------------
>>> workflow = testfwk_create_workflow({'jobs': {'jobs': 1}, 'global': {'config id': 'incredibly and way too long and descriptive config name'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = test_report('BasicHeaderReport', workflow.job_manager.job_db, workflow.task)
-----------------------------------------------------------------
REPORT SUMMARY: GC0000000000
---------------
>>> TestImageReport(create_config(), 'image', workflow.job_manager.job_db).show_report(workflow.job_manager.job_db, [])
>>> testfwk_remove_files(['test.png'])
>>> tmp = test_report('ColorBarReport', workflow.job_manager.job_db, workflow.task)
[ ]
>>> tmp = test_report('ColorBarReport', workflow.job_manager.job_db, workflow.task, config=create_config(config_dict={'global': {'report bar show numbers': 'True'}}))
[ ] ( 0| 0| 0| 0 )
>>> jpb1 = JobProgressBar()
>>> jpb2 = JobProgressBar(jobs_on_finish=True)
>>> jpb3 = JobProgressBar(display_text=False, jobs_on_finish=True)
>>> jpb2.update(100)
>>> ANSI.strip_fmt(str(jpb3))
'[ ]'
>>> ANSI.strip_fmt(str(jpb1))
'[] ( 0| 0| 0| 0 )'
>>> jpb1.update(100)
>>> ANSI.strip_fmt(str(jpb1))
'[] ( finished )'
>>> ANSI.strip_fmt(str(jpb2))
'[] ( 100 | finished )'
>>> tmp = Report.create_instance('LeanReport', create_config(), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp._start_time = time.time() - 60 * 60
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
1 0 0 0 / SUCCESS 0 0.0%
1h00 INIT > QUEUED > RUNNING > DONE | [> 0% ]
100.0% 100.0% 100.0% 100.0% \ FAILING 0 0.0%
>>> tmp._start_time = time.time() - 24 * 60 * 60
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
1 0 0 0 / SUCCESS 0 0.0%
1d00 INIT > QUEUED > RUNNING > DONE | [> 0% ]
100.0% 100.0% 100.0% 100.0% \ FAILING 0 0.0%
>>> workflow = testfwk_create_workflow({'parameters': {'parameters': 'A B', 'A': '1 2', 'B': 'W X Y Z'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = Report.create_instance('ModernReport', create_config(config_dict={'global': {'report categories max': 4}}), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
B = W (2 subtasks)
[ ]
B = X (2 subtasks)
[ ]
B = Y (2 subtasks)
[ ]
B = Z (2 subtasks)
[ ]
>>> workflow = testfwk_create_workflow({'parameters': {'parameters': 'A B', 'A': '1 2', 'B': 'X Y Z'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = Report.create_instance('ModernReport', create_config(config_dict={'global': {'report categories max': 4}}), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
A = 1, B = X
[ ]
A = 1, B = Y
[ ]
A = 1, B = Z
[ ]
Remaining subtasks (3 subtasks)
[ ]
>>> workflow = testfwk_create_workflow({'parameters': {'parameters': 'A B', 'A': '1 2', 'B': 'X Y Z'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = Report.create_instance('ModernReport', create_config(config_dict={'global': {'report categories max': 2}}), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
A = 1 (3 subtasks)
[ ]
A = 2 (3 subtasks)
[ ]
>>> workflow = testfwk_create_workflow({'parameters': {'parameters': 'A B', 'A': '1 2', 'B': 'X Y Z'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = Report.create_instance('ModernReport', create_config(config_dict={'global': {'report categories max': 3}}), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
B = X (2 subtasks)
[ ]
B = Y (2 subtasks)
[ ]
B = Z (2 subtasks)
[ ]
>>> workflow = testfwk_create_workflow({'parameters': {'parameters': 'A (B, C)', 'A': '1 2', 'B': 'X Y Z', 'C': '1 2 3'}})
Current task ID: GC0000000000
Task started on: 0000-00-00
Using batch system: ---
>>> tmp = Report.create_instance('ModernReport', create_config(config_dict={'global': {'report categories max': 3}}), 'test', workflow.job_manager.job_db, workflow.task)
>>> tmp.show_report(workflow.job_manager.job_db, workflow.job_manager.job_db.get_job_list())
B = X (2 subtasks)
[ ]
B = Y (2 subtasks)
[ ]
B = Z (2 subtasks)
[ ]
"""
run_test(cleanup_fun=cleanup_workflow)