1
"These tests depend on a working Config DB."
4
from datetime import datetime
6
sys.path.insert(0, "../")
8
from cdb import CdbError
9
from cdb import AlarmHandler
10
from cdb import Beamline
11
from cdb import BeamlineSuperMouse
12
from cdb import Cabling
13
from cdb import CablingSuperMouse
14
from cdb import Control
15
from cdb import ControlSuperMouse
16
from cdb import Geometry
17
from cdb import GeometrySuperMouse
19
def _alarm_handler_test():
20
""" Test AlarmHandler methods """
21
print '\nALARMHANDLER TESTS'
22
print '~~~~~~~~~~~~~~~~~~'
28
print "ERROR - set_url should have thrown a CdbError"
31
print '\nPassed duff URL test'
33
raise CdbError("set_url should have thrown a CdbError")
34
print '\nget_status()'
35
print _ah.get_status()
38
print '\nget_tagged_alh("Harry")'
39
print _ah.get_tagged_alh("Harry")
40
print '\nget_used_alh("2011-02-12 23:59:59.0")'
41
print _ah.get_used_alh(datetime.strptime("2011-02-12 23:59:59.0",
42
"%Y-%m-%d %H:%M:%S.%f"))
43
print '\nget_used_tags("2011-02-09 08:56:18.5", "2011-12-12 23:59:59.0")'
44
print _ah.get_used_tags(datetime.strptime("2011-02-09 08:56:18.5",
45
"%Y-%m-%d %H:%M:%S.%f"),
46
datetime.strptime("2011-12-12 23:59:59.0",
47
"%Y-%m-%d %H:%M:%S.%f"))
51
""" Test Beamline methods """
52
print '\nBEAMLINE TESTS'
53
print '~~~~~~~~~~~~~~'
59
print "ERROR - set_url should have thrown a CdbError"
62
print '\nPassed duff URL test'
64
raise CdbError("set_url should have thrown a CdbError")
65
print '\nget_status()'
66
print _bl.get_status()
67
print '\nget_beamline_for_run(2879)'
68
print _bl.get_beamline_for_run(2879)
69
print '\nget_beamlines_for_pulses(565665,565864)'
70
_runs = _bl.get_beamlines_for_pulses(565665, 565864)
71
print "beamlines returned:" + str(len(_runs))
74
_runs = _bl.get_beamlines_for_dates("2009-01-01 10:23:00",
75
"2010-12-12 23:59:69")
76
print "ERROR - get_beamlines_for_dates should have thrown a CdbError"
79
print '\nPassed duff timestamp test'
81
raise CdbError("get_beamlines_for_dates should have thrown a CdbError")
82
print ('\nget_beamlines_for_dates("2009-01-01 10:23:00.5", "2010-12-12 '
83
'23:59:59") - only printing data for first run in dictionary')
84
_runs = _bl.get_beamlines_for_dates(
85
datetime.strptime("2009-01-01 10:23:00.5", "%Y-%m-%d %H:%M:%S.%f"),
86
datetime.strptime("2010-12-12 23:59:59", "%Y-%m-%d %H:%M:%S"))
87
print "beamlines returned:" + str(len(_runs))
88
for k, value in _runs.iteritems():
91
print ('\nget_beamlines_for_dates("2009-01-01 10:23:00.5", None)')
92
_runs = _bl.get_beamlines_for_dates(
93
datetime.strptime("2009-01-01 10:23:00.5", "%Y-%m-%d %H:%M:%S.%f"),
95
print "beamlines returned:" + str(len(_runs))
97
print ('\nget_beamlines_for_dates("2009-01-01 10:23:00.5")')
98
_runs = _bl.get_beamlines_for_dates(
99
datetime.strptime("2009-01-01 10:23:00.5", "%Y-%m-%d %H:%M:%S.%f"))
100
print "beamlines returned:" + str(len(_runs))
102
print ('\nget_all_beamlines() - '
103
'only printing data for first run in dictionary')
104
_runs = _bl.get_all_beamlines()
105
print "beamlines returned:" + str(len(_runs))
106
for k, value in _runs.iteritems():
109
print '\nget_beamline_for_run(999999)'
110
print _bl.get_beamline_for_run(999999,)
114
""" Test Cabling methods """
115
print '\nCABLING TESTS'
116
print '~~~~~~~~~~~~~~~'
121
_cabling.set_url("duff")
122
print "ERROR - set_url should have thrown a CdbError"
125
print '\nPassed duff URL test'
127
raise CdbError("set_url should have thrown a CdbError")
128
print '\nget_status()'
129
print _cabling.get_status()
130
print '\nget_current_cabling("control")'
131
print _cabling.get_current_cabling("control")
132
print '\nget_current_cabling("tracker 0")'
133
print _cabling.get_current_cabling("tracker 0")
134
print '\nget_controls_for_date("tracker 0", "2011-08-14 12:32:59.8")'
135
print _cabling.get_cabling_for_date("tracker 0", "2011-08-14 12:32:59.8")
136
print '\nget_controls_for_date("control", "2011-08-14 12:32:59.8")'
137
print _cabling.get_cabling_for_date("control", "2011-08-14 12:32:59.8")
138
print '\nlist_devices()'
139
print _cabling.list_devices()
142
def _cabling_super_mouse_test():
143
""" Test Cabling SuperMouse methods """
144
print '\nCABLING SUPERMOUSE TESTS'
145
print '~~~~~~~~~~~~~~~~~~~~~~~~~~'
146
_cabling = CablingSuperMouse()
150
_cabling.set_url("duff")
151
print "ERROR - set_url should have thrown a CdbError"
154
print '\nPassed duff URL test'
156
raise CdbError("set_url should have thrown a CdbError")
157
print '\nget_status()'
158
print _cabling.get_status()
160
print '\nadd_control(9, 8, 7, "x1")'
161
print _cabling.add_control(9, 8, 2, "x1")
162
print '\nupdate_control(9, 8, 7, "x1")'
163
print _cabling.update_control(9, 8, 7, "x1")
164
print '\nadd_tracker("tracker 0", 1, 2, 3, 4, 5, 6, 7)'
165
print _cabling.add_tracker("tracker 0", 1, 2, 5, 4, 5, 6, 7)
166
print '\nupdate_tracker("tracker 0", 1, 2, 3, 4, 5, 6, 7)'
167
print _cabling.update_tracker("tracker 0", 1, 2, 3, 4, 5, 6, 7)
169
print '\nget_current_cabling("control")'
170
print _cabling.get_current_cabling("control")
171
print '\nget_current_cabling("tracker 0")'
172
print _cabling.get_current_cabling("tracker 0")
173
print '\nget_controls_for_date("tracker 0", "2011-08-14 12:32:59.8")'
174
print _cabling.get_cabling_for_date("tracker 0", "2011-08-14 12:32:59.8")
175
print '\nget_controls_for_date("control", "2011-08-14 12:32:59.8")'
176
print _cabling.get_cabling_for_date("control", "2011-08-14 12:32:59.8")
183
""" Test Control methods """
184
print '\nCONTROL TESTS'
185
print '~~~~~~~~~~~~~'
190
_control.set_url("duff")
191
print "ERROR - set_url should have thrown a CdbError"
194
print '\nPassed duff URL test'
196
raise CdbError("set_url should have thrown a CdbError")
197
print '\nget_status()'
198
print _control.get_status()
199
print '\ngetControls()'
200
print _control.get_controls()
201
print '\ngetControlsForCrate(2)'
202
print _control.get_controls_for_crate(2)
203
# print '\ngetPreviousSettings("2010-12-12 23:59:59")'
204
# print _control.get_previous_settings(
205
# datetime.strptime("2010-12-12 23:59:59", "%Y-%m-%d %H:%M:%S"))
208
def _geometry_test():
209
""" Test Geometry methods """
210
print '\nGEOMETRY TESTS'
211
print '~~~~~~~~~~~~~~'
212
_geometry = Geometry()
216
_geometry.set_url("duff")
217
print "ERROR - set_url should have thrown a CdbError"
220
print '\nPassed duff URL test'
222
raise CdbError("set_url should have thrown a CdbError")
223
print '\nget_status()'
224
print _geometry.get_status()
225
print '\nget_current_gdml()'
226
print 'GDML length:' + str(len(_geometry.get_current_gdml()))
227
print '\nget_gdml_for_id(9)'
228
print 'GDML length:' + str(len(_geometry.get_gdml_for_id(9)))
229
print '\nget_gdml_for_run(1)'
230
print 'GDML length:' + str(len(_geometry.get_gdml_for_run(1)))
232
print _geometry.get_ids("2010-12-12 23:69:59", "2010-12-12 23:59:59")
233
print "ERROR - get_ids should have thrown a CdbError"
236
print '\nPassed duff timestamp test'
238
raise CdbError("get_ids should have thrown a CdbError")
239
print '\nget_ids("2010-12-12 23:59:58.5", "2010-12-12 23:59:59")'
240
print _geometry.get_ids(datetime.strptime("2010-12-12 23:59:58.5",
241
"%Y-%m-%d %H:%M:%S.%f"),
242
datetime.strptime("2010-12-12 23:59:59",
243
"%Y-%m-%d %H:%M:%S"))
245
print '\nget_ids("2010-12-12 23:59:58.5", None)'
246
print _geometry.get_ids(datetime.strptime("2010-12-12 23:59:58.5",
247
"%Y-%m-%d %H:%M:%S.%f"), None)
248
print '\nget_ids("2010-12-12 23:59:58.5")'
249
print _geometry.get_ids(datetime.strptime("2010-12-12 23:59:58.5",
250
"%Y-%m-%d %H:%M:%S.%f"))
254
""" Runs the tests for each class. """
257
_alarm_handler_test()
258
except CdbError, error:
259
message = message + "ERROR while running alarm_handler tests\n"
260
message = message + str(error) + "\n"
263
except CdbError, error:
264
message = message + "ERROR while running beamline tests\n"
265
message = message + str(error) + "\n"
268
except CdbError, error:
269
message = message + "ERROR while running cabling tests\n"
270
message = message + str(error) + "\n"
272
_cabling_super_mouse_test()
273
except CdbError, error:
274
message = message + "ERROR while running cabling super mouse tests\n"
275
message = message + str(error) + "\n"
278
except CdbError, error:
279
message = message + "ERROR while running control tests\n"
280
message = message + str(error) + "\n"
283
except CdbError, error:
284
message = message + "ERROR while running geometry tests\n"
285
message = message + str(error) + "\n"
288
print "\n\nERROR running tests"
289
print "~~~~~~~~~~~~~~~~~~~\n"
292
print "\nAll tests passed"
295
if __name__ == "__main__":