Coverage for system_test_harness.py: 37%

731 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-10 15:08 +0100

1#------------------------------------------------------------------------------- 

2# System test harness - to support the writing of automated tests for schematic 

3# layout configurations (and by implication test the main application features) 

4# 

5# The initialise_test_harness function runs up the schematic editor application 

6# in a seperate thread (so the tkinter main-loop is running) and then makes 

7# all invocations by running the appropriate functions in that thread, with 

8# a configurable delay after each invocation to give the schematic editor time 

9# to process the function before the next invocation/assertion 

10# 

11# Basic Test harness Functions: 

12# start_application(callback_function) 

13# initialise_test_harness(filename=None) 

14# report_results(shutdown=False) 

15# sleep(sleep_time) 

16# 

17# Supported Schematic test invocations: 

18# set_signals_on(*sigids) 

19# set_signals_off(*sigids) 

20# set_subsidaries_on(*sigids) 

21# set_subsidaries_off(*sigids) 

22# set_secondary_dists_on(*sigids) - Semaphore only 

23# set_secondary_dists_off(*sigids) - Semaphore only 

24# trigger_signals_passed(*sigids) 

25# trigger_signals_released(*sigids) 

26# trigger_sensors_passed(*sigids) 

27# set_points_switched(*pointids) 

28# set_points_normal(*pointids 

29# set_fpls_on(*pointids) 

30# set_fpls_off(*pointids) 

31# set_sections_occupied(*sectionids) 

32# set_sections_clear(*sectionids) 

33# toggle_sections(*sectionids) 

34# set_instrument_blocked(*instrumentids) 

35# set_instrument_occupied(*instrumentids) 

36# set_instrument_clear(*instrumentids) 

37# click_telegraph_key(*instrumentids) 

38# simulate_gpio_triggered(*gpioids) 

39# 

40# Supported Schematic test assertions: 

41# assert_points_locked(*pointids) 

42# assert_points_unlocked(*pointids) 

43# assert_points_switched(*pointids) 

44# assert_points_normal(*pointids) 

45# assert_signals_locked(*sigids) 

46# assert_signals_unlocked(*sigids) 

47# assert_subsidaries_locked(*sigids) 

48# assert_subsidaries_unlocked(*sigids) 

49# assert_signals_override_set(*sigids) 

50# assert_signals_override_clear(*sigids) 

51# assert_signals_override_caution_set(*sigids) 

52# assert_signals_override_caution_clear(*sigids) 

53# assert_signals_app_cntl_set(*sigids) 

54# assert_signals_app_cntl_clear(*sigids) 

55# assert_signals_DANGER(*sigids) 

56# assert_signals_PROCEED(*sigids) 

57# assert_signals_CAUTION(*sigids) 

58# assert_signals_CAUTION_APP_CNTL(*sigids) 

59# assert_signals_PRELIM_CAUTION(*sigids) 

60# assert_signals_FLASH_CAUTION(*sigids) 

61# assert_signals_FLASH_PRELIM_CAUTION(*sigids) 

62# assert_signals_route_MAIN(*sigids) 

63# assert_signals_route_LH1(*sigids) 

64# assert_signals_route_LH2(*sigids) 

65# assert_signals_route_RH1(*sigids) 

66# assert_signals_route_RH2(*sigids) 

67# assert_sections_occupied(*secids) 

68# assert_sections_clear(*secids) 

69# assert_section_label(secid,label) 

70# assert_block_section_ahead_clear(instids*) 

71# assert_block_section_ahead_not_clear(instids*) 

72# 

73# Supported Menubar control invocations: 

74# set_edit_mode() 

75# set_run_mode() 

76# set_automation_on() 

77# set_automation_off() 

78# reset_layout() 

79# 

80# Supported Schematic create object invocations: 

81# create_line() 

82# create_colour_light_signal() 

83# create_semaphore_signal() 

84# create_ground_position_signal() 

85# create_ground_disc_signal() 

86# create_track_section() 

87# create_track_sensor() 

88# create_block_instrument() 

89# create_left_hand_point() 

90# create_right_hand_point() 

91# create_textbox() 

92# 

93# Supported Schematic keypress / right click menu invocations: 

94# toggle_mode() - 'Cntl-m' 

95# toggle_automation() - 'Cntl-a' 

96# toggle_snap_to_grid() - 'Cntl-s' 

97# reset_window_size() - 'Cntl-r' 

98# snap_selected_objects_to_grid() - 's' key - also right-click-menu function 

99# rotate_selected_objects() - 'r' key - also right-click-menu function 

100# delete_selected_objects() - 'del' key - also right-click-menu function 

101# nudge_selected_objects() - 'arrow' keys 

102# copy_selected_objects() - 'Cntl-c' - also right-click-menu function 

103# paste_clipboard_objects() - 'Cntl-v' - also right-click-menu function 

104# undo() / redo() - 'Cntl-x' / 'Cntl-y' 

105# select_all_objects() - Right-click-menu function 

106# deselect_all_objects() - 'esc' key 

107# 

108# Supported Schematic mouse event invocations: 

109# test_all_edit_object_windows(test_all_controls:bool=False - Opens & exercises all edit windows for all schematic objects 

110# update_object_configuration(object_id, new_values:dict) 

111# select_or_deselect_objects(*object_ids) 

112# select_single_object(object_id) 

113# select_and_edit_single_object (object_id) 

114# select_and_move_objects(object_id, xfinish:int, yfinish:int, steps:int=50, delay:float=0.0, test_cancel:bool=True) 

115# select_and_move_line_end(object_id, line_end:int, xfinish:int, yfinish:int, steps:int=50, delay:float=0.0, test_cancel:bool=True) 

116# select_area(xstart:int, ystart:int, xfinish:int, yfinish:int, steps:int=50, delay:float=0.0, test_cancel:bool=True): 

117# get_item_id(object_id) - This is a helper function 

118# get_object_id(item_type, item_id) - This is a helper function 

119# 

120# Supported Editor test assertions: 

121# assert_object_configuration(object_id, test_values:dict) 

122# assert_object_position(object_id, x1:int, y1:int, x2:int=None, y2:int=None) 

123# assert_objects_selected(*object_ids) 

124# assert_objects_deselected(*object_ids) 

125# assert_objects_exist(*object_ids) 

126# assert_objects_do_not_exist(*object_ids) 

127# 

128# Supported configuration 

129# ------------------------------------------------------------------------------ 

130 

131from inspect import getframeinfo 

132from inspect import stack 

133from os.path import basename 

134import logging 

135import tkinter 

136import time 

137import copy 

138import threading 

139 

140# ------------------------------------------------------------------------------ 

141# The following enables this module to correctly import the model_railway_signals 

142# package from the parent folder. Note that the order of precedence will always 

143# be to look for 'pip installed' model_railway_signals package - so be careful 

144# ------------------------------------------------------------------------------ 

145 

146import sys 

147sys.path.append("..") 

148from model_railway_signals.editor import settings 

149from model_railway_signals.editor import editor 

150from model_railway_signals.editor import schematic 

151from model_railway_signals.editor import objects 

152from model_railway_signals.library import common 

153from model_railway_signals.library import points 

154from model_railway_signals.library import signals 

155from model_railway_signals.library import signals_common 

156from model_railway_signals.library import signals_colour_lights 

157from model_railway_signals.library import signals_semaphores 

158from model_railway_signals.library import signals_ground_position 

159from model_railway_signals.library import signals_ground_disc 

160from model_railway_signals.library import track_sections 

161from model_railway_signals.library import block_instruments 

162from model_railway_signals.library import track_sensors 

163from model_railway_signals.library import gpio_sensors 

164 

165thread_delay_time = 0.150 

166tkinter_thread_started = False 

167main_menubar = None 

168root = None 

169 

170# ------------------------------------------------------------------------------ 

171# Global variables to keep a count on the total number of tests and failures 

172# ------------------------------------------------------------------------------ 

173 

174tests_executed = 0 

175test_failures = 0 

176test_warnings = 0 

177 

178# ------------------------------------------------------------------------------ 

179# Global variables to track the 'one up' train idenntifier for every time 

180# we set a section to 'occupied' during a test 

181# ------------------------------------------------------------------------------ 

182 

183train_identifier = 1 

184 

185# ------------------------------------------------------------------------------ 

186# Function to start the test harness in its own thread and then run up the 

187# main application (under test) in the main thread. The test harness then 

188# makes invocations by running the functions in the main thread 

189# ------------------------------------------------------------------------------ 

190 

191def test_harness_thread(callback_function): 

192 callback_function() 

193 

194def start_application(callback_function): 

195 global main_menubar, root 

196 # Set the logging 

197 logging.basicConfig(format='%(levelname)s: %(message)s') 

198 logging.getLogger().setLevel(logging.WARNING) 

199 # Start the application 

200 root = tkinter.Tk() 

201 main_menubar = editor.main_menubar(root) 

202 # Use the signals Lib function to find/store the root window reference 

203 # And then re-bind the close window event to the editor quit function 

204 common.set_root_window(root) 

205 root.protocol("WM_DELETE_WINDOW", main_menubar.quit_schematic) 

206 # Start the test harness thread 

207 test_thread = threading.Thread (target=lambda:test_harness_thread(callback_function)) 

208 test_thread.setDaemon(True) 

209 test_thread.start() 

210 # Enter the TKinter main loop (with exception handling for keyboardinterrupt) 

211 try: root.mainloop() 

212 except KeyboardInterrupt: 

213 logging.info("Keyboard Interrupt - Shutting down") 

214 schematic.shutdown() 

215 common.shutdown() 

216 

217def run_function(test_function, delay:float=thread_delay_time): 

218 common.execute_function_in_tkinter_thread (test_function) 

219 sleep(delay) 

220 

221# ------------------------------------------------------------------------------ 

222# Functions to log out test error/warning messages with the filename and line number  

223# of the parent test file that called the test assert functions in this module 

224# ------------------------------------------------------------------------------ 

225 

226def raise_test_error(message): 

227 global test_failures 

228 caller = getframeinfo(stack()[2][0]) 

229 logging.error("Line %d of %s: %s" % (caller.lineno,basename(caller.filename),message)) 

230 test_failures = test_failures+1 

231 

232def raise_test_warning(message): 

233 global test_warnings 

234 caller = getframeinfo(stack()[2][0]) 

235 logging.warning("Line %d of %s: %s" % (caller.lineno,basename(caller.filename),message)) 

236 test_warnings = test_warnings+1 

237 

238def increment_tests_executed(): 

239 global tests_executed 

240 tests_executed = tests_executed+1 

241 

242# ------------------------------------------------------------------------------ 

243# Function to initialise the test harness and load a schematic file (to test) 

244# Note that if a filename is not specified then it will open a dialogue to 

245# load a layout schematic file before running the tests. Also note that it 

246# calls the 'reset_schematic' function to put the layout in the default state 

247# ------------------------------------------------------------------------------ 

248 

249def initialise_test_harness(filename=None): 

250 if filename is None: 

251 # Ensure any queued tkinter events have completed 

252 time.sleep(1.0) 

253 run_function(lambda:main_menubar.new_schematic(ask_for_confirm=False),delay=2.0) 

254 else: 

255 # Ensure any queued tkinter events have completed 

256 time.sleep(1.0) 

257 print ("System Tests: Load Scematic: '",filename,"'") 

258 run_function(lambda:main_menubar.load_schematic(filename),delay=3.0) 

259 

260# ------------------------------------------------------------------------------ 

261# Function to finish the tests and report on any failures. Then drops straight 

262# back into the tkinter main loop to allow the schematic to be edited if required 

263# ------------------------------------------------------------------------------ 

264 

265def report_results(): 

266 print ("Tests Run:",tests_executed," Tests Passed:", 

267 tests_executed-test_failures," Test failures",test_failures," Test Warnings",test_warnings) 

268 

269# ------------------------------------------------------------------------------ 

270# Sleep Function to allow pauses to be included between test steps. This enables 

271# the tests to be 'slowed down' so progress can be viewed on the schematic 

272# ------------------------------------------------------------------------------ 

273 

274def sleep(sleep_time:float): time.sleep(sleep_time) 

275 

276# ------------------------------------------------------------------------------ 

277# Functions to mimic layout 'events' - in terms of button pushes or other events 

278# ------------------------------------------------------------------------------ 

279 

280def set_signals_on(*sigids): 

281 for sigid in sigids: 281 ↛ exit,   281 ↛ 2822 missed branches: 1) line 281 didn't return from function 'set_signals_on', because the loop on line 281 didn't complete, 2) line 281 didn't jump to line 282, because the loop on line 281 never started

282 if str(sigid) not in signals_common.signals.keys(): 

283 raise_test_warning ("set_signals_on - Signal: "+str(sigid)+" does not exist") 

284 elif not signals.signal_clear(sigid): 

285 raise_test_warning ("set_signals_on - Signal: "+str(sigid)+" is already ON") 

286 else: 

287 run_function(lambda:signals_common.signal_button_event(sigid)) 

288 

289def set_signals_off(*sigids): 

290 for sigid in sigids: 290 ↛ exit,   290 ↛ 2912 missed branches: 1) line 290 didn't return from function 'set_signals_off', because the loop on line 290 didn't complete, 2) line 290 didn't jump to line 291, because the loop on line 290 never started

291 if str(sigid) not in signals_common.signals.keys(): 

292 raise_test_warning ("set_signals_off - Signal: "+str(sigid)+" does not exist") 

293 elif signals.signal_clear(sigid): 

294 raise_test_warning ("set_signals_off - Signal: "+str(sigid)+" is already OFF") 

295 else: 

296 run_function(lambda:signals_common.signal_button_event(sigid)) 

297 

298def set_subsidaries_on(*sigids): 

299 for sigid in sigids: 299 ↛ exit,   299 ↛ 3002 missed branches: 1) line 299 didn't return from function 'set_subsidaries_on', because the loop on line 299 didn't complete, 2) line 299 didn't jump to line 300, because the loop on line 299 never started

300 if str(sigid) not in signals_common.signals.keys(): 

301 raise_test_warning ("set_subsidaries_on - Signal: "+str(sigid)+" does not exist") 

302 elif not signals_common.signals[str(sigid)]["hassubsidary"]: 

303 raise_test_warning ("set_subsidaries_on - Signal: "+str(sigid)+" does not have a subsidary") 

304 elif not signals.subsidary_clear(sigid): 

305 raise_test_warning ("set_subsidaries_on - Signal: "+str(sigid)+" - subsidary is already ON") 

306 else: 

307 run_function(lambda:signals_common.subsidary_button_event(sigid)) 

308 

309def set_subsidaries_off(*sigids): 

310 for sigid in sigids: 310 ↛ exit,   310 ↛ 3112 missed branches: 1) line 310 didn't return from function 'set_subsidaries_off', because the loop on line 310 didn't complete, 2) line 310 didn't jump to line 311, because the loop on line 310 never started

311 if str(sigid) not in signals_common.signals.keys(): 

312 raise_test_warning ("set_subsidaries_off - Signal: "+str(sigid)+" does not exist") 

313 elif not signals_common.signals[str(sigid)]["hassubsidary"]: 

314 raise_test_warning ("set_subsidaries_off - Signal: "+str(sigid)+" does not have a subsidary") 

315 elif signals.subsidary_clear(sigid): 

316 raise_test_warning ("set_subsidaries_off - Signal: "+str(sigid)+" - subsidary is already OFF") 

317 else: 

318 run_function(lambda:signals_common.subsidary_button_event(sigid)) 

319 

320def set_secondary_dists_on(*sigids): 

321 for sigid in sigids: 321 ↛ exit,   321 ↛ 3222 missed branches: 1) line 321 didn't return from function 'set_secondary_dists_on', because the loop on line 321 didn't complete, 2) line 321 didn't jump to line 322, because the loop on line 321 never started

322 if str(sigid) not in signals_common.signals.keys(): 

323 raise_test_warning ("set_secondary_dists_on - Signal: "+str(sigid)+" does not exist") 

324 elif str(sigid+100) not in signals_common.signals.keys(): 

325 raise_test_warning ("set_secondary_dists_on - Signal: "+str(sigid)+" does not have a secondary distant") 

326 elif not signals.signal_clear(sigid+100): 

327 raise_test_warning ("set_secondary_dists_on - Signal: "+str(sigid)+" - Secondary distant is already ON") 

328 else: 

329 run_function(lambda:signals_common.signal_button_event(sigid+100)) 

330 

331def set_secondary_dists_off(*sigids): 

332 for sigid in sigids: 332 ↛ exit,   332 ↛ 3332 missed branches: 1) line 332 didn't return from function 'set_secondary_dists_off', because the loop on line 332 didn't complete, 2) line 332 didn't jump to line 333, because the loop on line 332 never started

333 if str(sigid) not in signals_common.signals.keys(): 

334 raise_test_warning ("set_secondary_dists_off - Signal: "+str(sigid)+" does not exist") 

335 elif str(sigid+100) not in signals_common.signals.keys(): 

336 raise_test_warning ("set_secondary_dists_off - Signal: "+str(sigid)+" does not have a secondary distant") 

337 elif signals.signal_clear(sigid+100): 

338 raise_test_warning ("set_secondary_dists_off - Signal: "+str(sigid)+" - Secondary distant is already ON") 

339 else: 

340 run_function(lambda:signals_common.signal_button_event(sigid+100)) 

341 

342def trigger_signals_passed(*sigids): 

343 for sigid in sigids: 343 ↛ exit,   343 ↛ 3442 missed branches: 1) line 343 didn't return from function 'trigger_signals_passed', because the loop on line 343 didn't complete, 2) line 343 didn't jump to line 344, because the loop on line 343 never started

344 if str(sigid) not in signals_common.signals.keys(): 

345 raise_test_warning ("trigger_signals_passed - Signal: "+str(sigid)+" does not exist") 

346 else: 

347 run_function(lambda:signals_common.sig_passed_button_event(sigid)) 

348 

349def trigger_signals_released(*sigids): 

350 for sigid in sigids: 350 ↛ exit,   350 ↛ 3512 missed branches: 1) line 350 didn't return from function 'trigger_signals_released', because the loop on line 350 didn't complete, 2) line 350 didn't jump to line 351, because the loop on line 350 never started

351 if str(sigid) not in signals_common.signals.keys(): 

352 raise_test_warning ("trigger_signals_released - Signal: "+str(sigid)+" does not exist") 

353 else: 

354 run_function(lambda:signals_common.approach_release_button_event(sigid) ) 

355 

356def trigger_sensors_passed(*sensorids): 

357 for sensorid in sensorids: 357 ↛ exit,   357 ↛ 3582 missed branches: 1) line 357 didn't return from function 'trigger_sensors_passed', because the loop on line 357 didn't complete, 2) line 357 didn't jump to line 358, because the loop on line 357 never started

358 if str(sensorid) not in track_sensors.track_sensors.keys(): 

359 raise_test_warning ("trigger_sensors_passed - Track Sensor: "+str(sensorid)+" does not exist") 

360 else: 

361 run_function(lambda:track_sensors.track_sensor_triggered(sensorid)) 

362 

363def set_points_switched(*pointids): 

364 for pointid in pointids: 364 ↛ exit,   364 ↛ 3652 missed branches: 1) line 364 didn't return from function 'set_points_switched', because the loop on line 364 didn't complete, 2) line 364 didn't jump to line 365, because the loop on line 364 never started

365 if str(pointid) not in points.points.keys(): 

366 raise_test_warning ("set_points_switched - Point: "+str(pointid)+" does not exist") 

367 elif points.point_switched(pointid): 

368 raise_test_warning ("set_points_switched - Point: "+str(pointid)+" is already switched") 

369 else: 

370 run_function(lambda:points.change_button_event(pointid)) 

371 

372def set_points_normal(*pointids): 

373 for pointid in pointids: 373 ↛ exit,   373 ↛ 3742 missed branches: 1) line 373 didn't return from function 'set_points_normal', because the loop on line 373 didn't complete, 2) line 373 didn't jump to line 374, because the loop on line 373 never started

374 if str(pointid) not in points.points.keys(): 

375 raise_test_warning ("set_points_normal - Point: "+str(pointid)+" does not exist") 

376 elif not points.point_switched(pointid): 

377 raise_test_warning ("set_points_normal - Point: "+str(pointid)+" is already normal") 

378 else: 

379 run_function(lambda:points.change_button_event(pointid)) 

380 

381def set_fpls_on(*pointids): 

382 for pointid in pointids: 382 ↛ exit,   382 ↛ 3832 missed branches: 1) line 382 didn't return from function 'set_fpls_on', because the loop on line 382 didn't complete, 2) line 382 didn't jump to line 383, because the loop on line 382 never started

383 if str(pointid) not in points.points.keys(): 

384 raise_test_warning ("set_fpls_on - Point: "+str(pointid)+" does not exist") 

385 elif not points.points[str(pointid)]["hasfpl"]: 

386 raise_test_warning ("set_fpls_on - Point: "+str(pointid)+" does not have a FPL") 

387 elif points.fpl_active(pointid): 

388 raise_test_warning ("set_fpls_on - Point: "+str(pointid)+" - FPL is already ON") 

389 else: 

390 run_function(lambda:points.fpl_button_event(pointid)) 

391 

392def set_fpls_off(*pointids): 

393 for pointid in pointids: 393 ↛ exit,   393 ↛ 3942 missed branches: 1) line 393 didn't return from function 'set_fpls_off', because the loop on line 393 didn't complete, 2) line 393 didn't jump to line 394, because the loop on line 393 never started

394 if str(pointid) not in points.points.keys(): 

395 raise_test_warning ("set_fpls_off - Point: "+str(pointid)+" - does not exist on the schematic") 

396 elif not points.points[str(pointid)]["hasfpl"]: 

397 raise_test_warning ("set_fpls_off - Point: "+str(pointid)+" does not have a FPL") 

398 elif not points.fpl_active(pointid): 

399 raise_test_warning ("set_fpls_off - Point: "+str(pointid)+" - FPL is already OFF") 

400 else: 

401 run_function(lambda:points.fpl_button_event(pointid)) 

402 

403def set_sections_occupied(*sectionids): 

404 global train_identifier 

405 for secid in sectionids: 405 ↛ exit,   405 ↛ 4062 missed branches: 1) line 405 didn't return from function 'set_sections_occupied', because the loop on line 405 didn't complete, 2) line 405 didn't jump to line 406, because the loop on line 405 never started

406 if str(secid) not in track_sections.sections.keys(): 

407 raise_test_warning ("set_sections_occupied - Section: "+str(secid)+" does not exist") 

408 else: 

409 if track_sections.section_occupied(secid): 

410 raise_test_warning ("set_sections_occupied - Section: "+str(secid)+" is already OCCUPIED") 

411 else: 

412 # Two calls are needed - we first clear the section to set the section label 

413 # then we call the section callback library function to simulate the 'click' 

414 run_function(lambda:track_sections.clear_section_occupied(secid,str(train_identifier))) 

415 run_function(lambda:track_sections.section_button_event(secid)) 415 ↛ exit,   415 ↛ 4162 missed branches: 1) line 415 didn't run the lambda on line 415, 2) line 415 didn't jump to line 416

416 train_identifier=train_identifier+1 

417 

418def toggle_sections(*sectionids): 

419 for secid in sectionids: 419 ↛ exit,   419 ↛ 4202 missed branches: 1) line 419 didn't return from function 'toggle_sections', because the loop on line 419 didn't complete, 2) line 419 didn't jump to line 420, because the loop on line 419 never started

420 if str(secid) not in track_sections.sections.keys(): 

421 raise_test_warning ("set_sections_occupied - Section: "+str(secid)+" does not exist") 

422 else: 

423 run_function(lambda:track_sections.section_button_event(secid)) 

424 

425def set_sections_clear(*sectionids): 

426 for secid in sectionids: 426 ↛ exit,   426 ↛ 4272 missed branches: 1) line 426 didn't return from function 'set_sections_clear', because the loop on line 426 didn't complete, 2) line 426 didn't jump to line 427, because the loop on line 426 never started

427 if str(secid) not in track_sections.sections.keys(): 

428 raise_test_warning ("set_sections_clear - Section: "+str(secid)+" does not exist") 

429 else: 

430 if not track_sections.section_occupied(secid): 

431 raise_test_warning ("set_sections_clear - Section: "+str(secid)+" is already CLEAR") 

432 else: 

433 run_function(lambda:track_sections.section_button_event(secid)) 

434 

435def set_instrument_blocked(*instrumentids): 

436 for instid in instrumentids: 436 ↛ exit,   436 ↛ 4372 missed branches: 1) line 436 didn't return from function 'set_instrument_blocked', because the loop on line 436 didn't complete, 2) line 436 didn't jump to line 437, because the loop on line 436 never started

437 if str(instid) not in block_instruments.instruments.keys(): 

438 raise_test_warning ("set_instrument_blocked - Instrument: "+str(instid)+" does not exist") 

439 else: 

440 run_function(lambda:block_instruments.blocked_button_event(instid)) 

441 

442def set_instrument_occupied(*instrumentids): 

443 for instid in instrumentids: 443 ↛ exit,   443 ↛ 4442 missed branches: 1) line 443 didn't return from function 'set_instrument_occupied', because the loop on line 443 didn't complete, 2) line 443 didn't jump to line 444, because the loop on line 443 never started

444 if str(instid) not in block_instruments.instruments.keys(): 

445 raise_test_warning ("set_instrument_occupied - Instrument: "+str(instid)+" does not exist") 

446 else: 

447 run_function(lambda:block_instruments.occup_button_event(instid)) 

448 

449def set_instrument_clear(*instrumentids): 

450 for instid in instrumentids: 450 ↛ exit,   450 ↛ 4512 missed branches: 1) line 450 didn't return from function 'set_instrument_clear', because the loop on line 450 didn't complete, 2) line 450 didn't jump to line 451, because the loop on line 450 never started

451 if str(instid) not in block_instruments.instruments.keys(): 

452 raise_test_warning ("set_instrument_clear - Instrument: "+str(instid)+" does not exist") 

453 else: 

454 run_function(lambda:block_instruments.clear_button_event(instid)) 

455 

456def click_telegraph_key(*instrumentids): 

457 for instid in instrumentids: 457 ↛ exit,   457 ↛ 4582 missed branches: 1) line 457 didn't return from function 'click_telegraph_key', because the loop on line 457 didn't complete, 2) line 457 didn't jump to line 458, because the loop on line 457 never started

458 if str(instid) not in block_instruments.instruments.keys(): 

459 raise_test_warning ("click_telegraph_key - Instrument: "+str(instid)+" does not exist") 

460 else: 

461 run_function(lambda:block_instruments.telegraph_key_button(instid)) 

462 

463def simulate_gpio_triggered(*gpioids): 

464 for gpioid in gpioids: 464 ↛ exit,   464 ↛ 4652 missed branches: 1) line 464 didn't return from function 'simulate_gpio_triggered', because the loop on line 464 didn't complete, 2) line 464 didn't jump to line 465, because the loop on line 464 never started

465 if str(gpioid) not in gpio_sensors.gpio_port_mappings.keys(): 

466 raise_test_warning ("simulate_gpio_triggered - GPIO: "+str(gpioid)+" has not been mapped") 

467 else: 

468 run_function(lambda:gpio_sensors.gpio_sensor_triggered(gpioid,testing=True)) 

469 

470# ------------------------------------------------------------------------------ 

471# Functions to make test 'asserts' - in terms of expected state/behavior 

472# ------------------------------------------------------------------------------ 

473 

474def assert_points_locked(*pointids): 

475 for pointid in pointids: 475 ↛ exit,   475 ↛ 4762 missed branches: 1) line 475 didn't return from function 'assert_points_locked', because the loop on line 475 didn't complete, 2) line 475 didn't jump to line 476, because the loop on line 475 never started

476 if str(pointid) not in points.points.keys(): 

477 raise_test_warning ("assert_points_locked - Point: "+str(pointid)+" does not exist") 

478 elif not points.points[str(pointid)]["locked"]: 

479 raise_test_error ("assert_points_locked - Point: "+str(pointid)+" - Test Fail") 

480 increment_tests_executed() 

481 

482def assert_points_unlocked(*pointids): 

483 for pointid in pointids: 483 ↛ exit,   483 ↛ 4842 missed branches: 1) line 483 didn't return from function 'assert_points_unlocked', because the loop on line 483 didn't complete, 2) line 483 didn't jump to line 484, because the loop on line 483 never started

484 if str(pointid) not in points.points.keys(): 

485 raise_test_warning ("assert_points_unlocked - Point: "+str(pointid)+" does not exist") 

486 elif points.points[str(pointid)]["locked"]: 

487 raise_test_error ("assert_points_unlocked - Point: "+str(pointid)+" - Test Fail") 

488 increment_tests_executed() 

489 

490def assert_points_switched(*pointids): 

491 for pointid in pointids: 491 ↛ exit,   491 ↛ 4922 missed branches: 1) line 491 didn't return from function 'assert_points_switched', because the loop on line 491 didn't complete, 2) line 491 didn't jump to line 492, because the loop on line 491 never started

492 if str(pointid) not in points.points.keys(): 

493 raise_test_warning ("assert_points_switched - Point: "+str(pointid)+" does not exist") 

494 elif not points.points[str(pointid)]["switched"]: 

495 raise_test_error ("assert_points_switched - Point: "+str(pointid)+" - Test Fail") 

496 increment_tests_executed() 

497 

498def assert_points_normal(*pointids): 

499 for pointid in pointids: 499 ↛ exit,   499 ↛ 5002 missed branches: 1) line 499 didn't return from function 'assert_points_normal', because the loop on line 499 didn't complete, 2) line 499 didn't jump to line 500, because the loop on line 499 never started

500 if str(pointid) not in points.points.keys(): 

501 raise_test_warning ("assert_points_normal - Point: "+str(pointid)+" does not exist") 

502 elif points.points[str(pointid)]["switched"]: 

503 raise_test_error ("assert_points_normal - Point: "+str(pointid)+" - Test Fail") 

504 increment_tests_executed() 

505 

506def assert_signals_locked(*sigids): 

507 for sigid in sigids: 507 ↛ exit,   507 ↛ 5082 missed branches: 1) line 507 didn't return from function 'assert_signals_locked', because the loop on line 507 didn't complete, 2) line 507 didn't jump to line 508, because the loop on line 507 never started

508 if str(sigid) not in signals_common.signals.keys(): 

509 raise_test_warning ("assert_signals_locked - Signal: "+str(sigid)+" does not exist") 

510 elif not signals_common.signals[str(sigid)]["siglocked"]: 510 ↛ 512line 510 didn't jump to line 512, because the condition on line 510 was never false

511 raise_test_error ("assert_signals_locked - Signal: "+str(sigid)+" - Test Fail") 

512 increment_tests_executed() 

513 

514def assert_signals_unlocked(*sigids): 

515 for sigid in sigids: 515 ↛ exit,   515 ↛ 5162 missed branches: 1) line 515 didn't return from function 'assert_signals_unlocked', because the loop on line 515 didn't complete, 2) line 515 didn't jump to line 516, because the loop on line 515 never started

516 if str(sigid) not in signals_common.signals.keys(): 

517 raise_test_warning ("assert_signals_unlocked - Signal: "+str(sigid)+" does not exist") 

518 elif signals_common.signals[str(sigid)]["siglocked"]: 

519 raise_test_error ("assert_signals_unlocked - Signal: "+str(sigid)+" - Test Fail") 

520 increment_tests_executed() 

521 

522def assert_subsidaries_locked(*sigids): 

523 for sigid in sigids: 523 ↛ exit,   523 ↛ 5242 missed branches: 1) line 523 didn't return from function 'assert_subsidaries_locked', because the loop on line 523 didn't complete, 2) line 523 didn't jump to line 524, because the loop on line 523 never started

524 if str(sigid) not in signals_common.signals.keys(): 

525 raise_test_warning ("assert_subsidaries_locked - Signal: "+str(sigid)+" does not exist") 

526 elif not signals_common.signals[str(sigid)]["hassubsidary"]: 

527 raise_test_warning ("assert_subsidaries_locked - Signal: "+str(sigid)+" does not have a subsidary") 

528 elif not signals_common.signals[str(sigid)]["sublocked"]: 

529 raise_test_error ("assert_subsidaries_locked - Signal: "+str(sigid)+" - Test Fail") 

530 increment_tests_executed() 

531 

532def assert_subsidaries_unlocked(*sigids): 

533 for sigid in sigids: 533 ↛ exit,   533 ↛ 5342 missed branches: 1) line 533 didn't return from function 'assert_subsidaries_unlocked', because the loop on line 533 didn't complete, 2) line 533 didn't jump to line 534, because the loop on line 533 never started

534 if str(sigid) not in signals_common.signals.keys(): 

535 raise_test_warning ("assert_subsidaries_unlocked - Signal: "+str(sigid)+" does not exist") 

536 elif not signals_common.signals[str(sigid)]["hassubsidary"]: 

537 raise_test_warning ("assert_subsidaries_unlocked - Signal: "+str(sigid)+" does not have a subsidary") 

538 elif signals_common.signals[str(sigid)]["sublocked"]: 

539 raise_test_error ("assert_subsidaries_unlocked - Signal: "+str(sigid)+" - Test Fail") 

540 increment_tests_executed() 

541 

542def assert_signals_override_set(*sigids): 

543 for sigid in sigids: 543 ↛ exit,   543 ↛ 5442 missed branches: 1) line 543 didn't return from function 'assert_signals_override_set', because the loop on line 543 didn't complete, 2) line 543 didn't jump to line 544, because the loop on line 543 never started

544 if str(sigid) not in signals_common.signals.keys(): 

545 raise_test_warning ("assert_signals_override_set - Signal: "+str(sigid)+" does not exist") 

546 elif not signals_common.signals[str(sigid)]["override"]: 

547 raise_test_error ("assert_signals_override_set - Signal: "+str(sigid)+" - Test Fail") 

548 increment_tests_executed() 

549 

550def assert_signals_override_clear(*sigids): 

551 for sigid in sigids: 551 ↛ exit,   551 ↛ 5522 missed branches: 1) line 551 didn't return from function 'assert_signals_override_clear', because the loop on line 551 didn't complete, 2) line 551 didn't jump to line 552, because the loop on line 551 never started

552 if str(sigid) not in signals_common.signals.keys(): 

553 raise_test_warning ("assert_signals_override_clear - Signal: "+str(sigid)+" does not exist") 

554 elif signals_common.signals[str(sigid)]["override"]: 

555 raise_test_error ("assert_signals_override_clear - Signal: "+str(sigid)+" - Test Fail") 

556 increment_tests_executed() 

557 

558def assert_signals_override_caution_set(*sigids): 

559 for sigid in sigids: 559 ↛ exit,   559 ↛ 5602 missed branches: 1) line 559 didn't return from function 'assert_signals_override_caution_set', because the loop on line 559 didn't complete, 2) line 559 didn't jump to line 560, because the loop on line 559 never started

560 if str(sigid) not in signals_common.signals.keys(): 

561 raise_test_warning ("assert_signals_override_caution_set - Signal: "+str(sigid)+" does not exist") 

562 elif not signals_common.signals[str(sigid)]["overcaution"]: 

563 raise_test_error ("assert_signals_override_caution_set - Signal: "+str(sigid)+" - Test Fail") 

564 increment_tests_executed() 

565 

566def assert_signals_override_caution_clear(*sigids): 

567 for sigid in sigids: 567 ↛ exit,   567 ↛ 5682 missed branches: 1) line 567 didn't return from function 'assert_signals_override_caution_clear', because the loop on line 567 didn't complete, 2) line 567 didn't jump to line 568, because the loop on line 567 never started

568 if str(sigid) not in signals_common.signals.keys(): 

569 raise_test_warning ("assert_signals_override_caution_clear - Signal: "+str(sigid)+" - does not exist") 

570 elif signals_common.signals[str(sigid)]["overcaution"]: 

571 raise_test_error ("assert_signals_override_caution_clear - Signal: "+str(sigid)+" - Test Fail") 

572 increment_tests_executed() 

573 

574def assert_signals_app_cntl_set(*sigids): 

575 for sigid in sigids: 575 ↛ exit,   575 ↛ 5762 missed branches: 1) line 575 didn't return from function 'assert_signals_app_cntl_set', because the loop on line 575 didn't complete, 2) line 575 didn't jump to line 576, because the loop on line 575 never started

576 if str(sigid) not in signals_common.signals.keys(): 

577 raise_test_warning ("assert_signals_app_cntl_set - Signal: "+str(sigid)+" does not exist") 

578 elif ( "releaseonred" not in signals_common.signals[str(sigid)].keys() or 578 ↛ 581line 578 didn't jump to line 581, because the condition on line 578 was never false

579 "releaseonyel" not in signals_common.signals[str(sigid)].keys() ): 

580 raise_test_warning ("assert_signals_app_cntl_set - Signal: "+str(sigid)+" does not support approach control") 

581 elif ( not signals_common.signals[str(sigid)]["releaseonred"] and 581 ↛ 584line 581 didn't jump to line 584, because the condition on line 581 was never false

582 not signals_common.signals[str(sigid)]["releaseonyel"] ): 

583 raise_test_error ("Signal:"+str(sigid)+" - Test Fail") 

584 increment_tests_executed() 

585 

586def assert_signals_app_cntl_clear(*sigids): 

587 for sigid in sigids: 587 ↛ exit,   587 ↛ 5882 missed branches: 1) line 587 didn't return from function 'assert_signals_app_cntl_clear', because the loop on line 587 didn't complete, 2) line 587 didn't jump to line 588, because the loop on line 587 never started

588 if str(sigid) not in signals_common.signals.keys(): 

589 raise_test_warning ("assert_signals_app_cntl_clear - Signal: "+str(sigid)+" does not exist") 

590 elif ( "releaseonred" not in signals_common.signals[str(sigid)].keys() or 590 ↛ 593line 590 didn't jump to line 593, because the condition on line 590 was never false

591 "releaseonyel" not in signals_common.signals[str(sigid)].keys() ): 

592 raise_test_warning ("assert_signals_app_cntl_clear - Signal: "+str(sigid)+" does not support approach control") 

593 elif ( signals_common.signals[str(sigid)]["releaseonred"] or 593 ↛ 596line 593 didn't jump to line 596, because the condition on line 593 was never false

594 signals_common.signals[str(sigid)]["releaseonyel"] ): 

595 raise_test_error ("Signal:"+str(sigid)+" - Test Fail") 

596 increment_tests_executed() 

597 

598def assert_signals_DANGER(*sigids): 

599 for sigid in sigids: 599 ↛ exit,   599 ↛ 6002 missed branches: 1) line 599 didn't return from function 'assert_signals_DANGER', because the loop on line 599 didn't complete, 2) line 599 didn't jump to line 600, because the loop on line 599 never started

600 if str(sigid) not in signals_common.signals.keys(): 

601 raise_test_warning ("assert_signals_DANGER - Signal: "+str(sigid)+" does not exist") 

602 else: 

603 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

604 if signal_state != signals_common.signal_state_type.DANGER: 

605 raise_test_error ("assert_signals_DANGER - Signal: "+str(sigid)+" - Test Fail "+ 

606 "- Signal state: "+str(signal_state)) 

607 increment_tests_executed() 

608 

609def assert_signals_PROCEED(*sigids): 

610 for sigid in sigids: 610 ↛ exit,   610 ↛ 6112 missed branches: 1) line 610 didn't return from function 'assert_signals_PROCEED', because the loop on line 610 didn't complete, 2) line 610 didn't jump to line 611, because the loop on line 610 never started

611 if str(sigid) not in signals_common.signals.keys(): 

612 raise_test_warning ("assert_signals_PROCEED - Signal: "+str(sigid)+" does not exist") 

613 else: 

614 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

615 if signal_state != signals_common.signal_state_type.PROCEED: 615 ↛ 618line 615 didn't jump to line 618, because the condition on line 615 was never false

616 raise_test_error ("assert_signals_PROCEED - Signal: "+str(sigid)+" - Test Fail "+ 

617 "- Signal state: "+str(signal_state)) 

618 increment_tests_executed() 

619 

620def assert_signals_CAUTION(*sigids): 

621 for sigid in sigids: 621 ↛ exit,   621 ↛ 6222 missed branches: 1) line 621 didn't return from function 'assert_signals_CAUTION', because the loop on line 621 didn't complete, 2) line 621 didn't jump to line 622, because the loop on line 621 never started

622 if str(sigid) not in signals_common.signals.keys(): 

623 raise_test_warning ("assert_signals_CAUTION - Signal: "+str(sigid)+" does not exist") 

624 else: 

625 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

626 if signal_state != signals_common.signal_state_type.CAUTION: 

627 raise_test_error ("assert_signals_CAUTION - Signal: "+str(sigid)+" - Test Fail "+ 

628 "- Signal state: "+str(signal_state)) 

629 increment_tests_executed() 

630 

631def assert_signals_CAUTION_APP_CNTL(*sigids): 

632 for sigid in sigids: 632 ↛ exit,   632 ↛ 6332 missed branches: 1) line 632 didn't return from function 'assert_signals_CAUTION_APP_CNTL', because the loop on line 632 didn't complete, 2) line 632 didn't jump to line 633, because the loop on line 632 never started

633 if str(sigid) not in signals_common.signals.keys(): 

634 raise_test_warning ("assert_signals_CAUTION_APP_CNTL - Signal: "+str(sigid)+" does not exist") 

635 else: 

636 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

637 if signal_state != signals_common.signal_state_type.CAUTION_APP_CNTL: 

638 raise_test_error ("assert_signals_CAUTION_APP_CNTL - Signal: "+str(sigid)+" - Test Fail "+ 

639 "- Signal state: "+str(signal_state)) 

640 increment_tests_executed() 

641 

642def assert_signals_PRELIM_CAUTION(*sigids): 

643 for sigid in sigids: 643 ↛ exit,   643 ↛ 6442 missed branches: 1) line 643 didn't return from function 'assert_signals_PRELIM_CAUTION', because the loop on line 643 didn't complete, 2) line 643 didn't jump to line 644, because the loop on line 643 never started

644 if str(sigid) not in signals_common.signals.keys(): 

645 raise_test_warning ("assert_signals_PRELIM_CAUTION - Signal: "+str(sigid)+" does not exist") 

646 else: 

647 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

648 if signal_state != signals_common.signal_state_type.PRELIM_CAUTION: 

649 raise_test_error ("assert_signals_PRELIM_CAUTION - Signal: "+str(sigid)+" - Test Fail "+ 

650 "- Signal state: "+str(signal_state)) 

651 increment_tests_executed() 

652 

653def assert_signals_FLASH_CAUTION(*sigids): 

654 for sigid in sigids: 654 ↛ exit,   654 ↛ 6552 missed branches: 1) line 654 didn't return from function 'assert_signals_FLASH_CAUTION', because the loop on line 654 didn't complete, 2) line 654 didn't jump to line 655, because the loop on line 654 never started

655 if str(sigid) not in signals_common.signals.keys(): 

656 raise_test_warning ("assert_signals_FLASH_CAUTION - Signal: "+str(sigid)+" does not exist") 

657 else: 

658 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

659 if signal_state != signals_common.signal_state_type.FLASH_CAUTION: 

660 raise_test_error ("assert_signals_FLASH_CAUTION - Signal: "+str(sigid)+" - Test Fail "+ 

661 "- Signal state: "+str(signal_state)) 

662 increment_tests_executed() 

663 

664def assert_signals_FLASH_PRELIM_CAUTION(*sigids): 

665 for sigid in sigids: 665 ↛ exit,   665 ↛ 6662 missed branches: 1) line 665 didn't return from function 'assert_signals_FLASH_PRELIM_CAUTION', because the loop on line 665 didn't complete, 2) line 665 didn't jump to line 666, because the loop on line 665 never started

666 if str(sigid) not in signals_common.signals.keys(): 

667 raise_test_warning ("assert_signals_FLASH_PRELIM_CAUTION - Signal: "+str(sigid)+" does not exist") 

668 else: 

669 signal_state = signals_common.signals[str(sigid)]["sigstate"] 

670 if signal_state != signals_common.signal_state_type.FLASH_PRELIM_CAUTION: 

671 raise_test_error ("assert_signals_FLASH_PRELIM_CAUTION - Signal: "+str(sigid)+" - Test Fail "+ 

672 "- Signal state: "+str(signal_state)) 

673 increment_tests_executed() 

674 

675def assert_signals_route_MAIN(*sigids): 

676 for sigid in sigids: 676 ↛ exit,   676 ↛ 6772 missed branches: 1) line 676 didn't return from function 'assert_signals_route_MAIN', because the loop on line 676 didn't complete, 2) line 676 didn't jump to line 677, because the loop on line 676 never started

677 if str(sigid) not in signals_common.signals.keys(): 

678 raise_test_warning ("assert_signals_route_MAIN - Signal: "+str(sigid)+" does not exist") 

679 else: 

680 signal_route = signals_common.signals[str(sigid)]["routeset"] 

681 if signal_route != signals_common.route_type.MAIN: 

682 raise_test_error ("assert_signals_route_MAIN - Signal: "+str(sigid)+" - Test Fail "+ 

683 "- Signal route: "+str(signal_route)) 

684 increment_tests_executed() 

685 

686def assert_signals_route_LH1(*sigids): 

687 for sigid in sigids: 687 ↛ exit,   687 ↛ 6882 missed branches: 1) line 687 didn't return from function 'assert_signals_route_LH1', because the loop on line 687 didn't complete, 2) line 687 didn't jump to line 688, because the loop on line 687 never started

688 if str(sigid) not in signals_common.signals.keys(): 

689 raise_test_warning ("assert_signals_route_LH1 - Signal: "+str(sigid)+" does not exist") 

690 else: 

691 signal_route = signals_common.signals[str(sigid)]["routeset"] 

692 if signal_route != signals_common.route_type.LH1: 

693 raise_test_error ("assert_signals_route_LH1 - Signal: "+str(sigid)+" - Test Fail "+ 

694 "- Signal route: "+str(signal_route)) 

695 increment_tests_executed() 

696 

697def assert_signals_route_LH2(*sigids): 

698 for sigid in sigids: 698 ↛ exit,   698 ↛ 6992 missed branches: 1) line 698 didn't return from function 'assert_signals_route_LH2', because the loop on line 698 didn't complete, 2) line 698 didn't jump to line 699, because the loop on line 698 never started

699 if str(sigid) not in signals_common.signals.keys(): 

700 raise_test_warning ("assert_signals_route_LH2 - Signal: "+str(sigid)+" does not exist") 

701 else: 

702 signal_route = signals_common.signals[str(sigid)]["routeset"] 

703 if signal_route != signals_common.route_type.LH2: 

704 raise_test_error ("assert_signals_route_LH2 - Signal: "+str(sigid)+" - Test Fail "+ 

705 "- Signal route: "+str(signal_route)) 

706 increment_tests_executed() 

707 

708def assert_signals_route_RH1(*sigids): 

709 for sigid in sigids: 709 ↛ exit,   709 ↛ 7102 missed branches: 1) line 709 didn't return from function 'assert_signals_route_RH1', because the loop on line 709 didn't complete, 2) line 709 didn't jump to line 710, because the loop on line 709 never started

710 if str(sigid) not in signals_common.signals.keys(): 

711 raise_test_warning ("assert_signals_route_RH1 - Signal: "+str(sigid)+" does not exist") 

712 else: 

713 signal_route = signals_common.signals[str(sigid)]["routeset"] 

714 if signal_route != signals_common.route_type.RH1: 

715 raise_test_error ("assert_signals_route_RH1 - Signal: "+str(sigid)+" - Test Fail "+ 

716 "- Signal route: "+str(signal_route)) 

717 increment_tests_executed() 

718 

719def assert_signals_route_RH2(*sigids): 

720 for sigid in sigids: 720 ↛ exit,   720 ↛ 7212 missed branches: 1) line 720 didn't return from function 'assert_signals_route_RH2', because the loop on line 720 didn't complete, 2) line 720 didn't jump to line 721, because the loop on line 720 never started

721 if str(sigid) not in signals_common.signals.keys(): 

722 raise_test_warning ("assert_signals_route_RH2 - Signal: "+str(sigid)+" does not exist") 

723 else: 

724 signal_route = signals_common.signals[str(sigid)]["routeset"] 

725 if signal_route != signals_common.route_type.RH2: 

726 raise_test_error ("assert_signals_route_RH2 - Signal: "+str(sigid)+" - Test Fail "+ 

727 "- Signal route: "+str(signal_route)) 

728 increment_tests_executed() 

729 

730def assert_sections_occupied(*secids): 

731 for secid in secids: 731 ↛ exit,   731 ↛ 7322 missed branches: 1) line 731 didn't return from function 'assert_sections_occupied', because the loop on line 731 didn't complete, 2) line 731 didn't jump to line 732, because the loop on line 731 never started

732 if str(secid) not in track_sections.sections.keys(): 

733 raise_test_warning ("assert_sections_occupied - Section: "+str(secid)+" does not exist") 

734 elif not track_sections.sections[str(secid)]["occupied"]: 

735 raise_test_error ("assert_sections_occupied - Section: "+str(secid)+" - Test Fail") 

736 increment_tests_executed() 

737 

738def assert_sections_clear(*secids): 

739 for secid in secids: 739 ↛ exit,   739 ↛ 7402 missed branches: 1) line 739 didn't return from function 'assert_sections_clear', because the loop on line 739 didn't complete, 2) line 739 didn't jump to line 740, because the loop on line 739 never started

740 if str(secid) not in track_sections.sections.keys(): 

741 raise_test_warning ("assert_sections_clear - Section: "+str(secid)+" does not exist") 

742 elif track_sections.sections[str(secid)]["occupied"]: 

743 raise_test_error ("assert_sections_clear - Section: "+str(secid)+" - Test Fail") 

744 increment_tests_executed() 

745 

746def assert_section_label(secid,label): 

747 if str(secid) not in track_sections.sections.keys(): 

748 raise_test_warning ("assert_section_label - Section: "+str(secid)+" does not exist") 

749 elif track_sections.sections[str(secid)]["labeltext"] != label: 

750 raise_test_error ("assert_section_label - Section: "+str(secid)+" - Test Fail - Label is: " 

751 + track_sections.sections[str(secid)]["labeltext"]) 

752 increment_tests_executed() 

753 

754def assert_block_section_ahead_clear(*instrumentids): 

755 for instid in instrumentids: 755 ↛ exit,   755 ↛ 7562 missed branches: 1) line 755 didn't return from function 'assert_block_section_ahead_clear', because the loop on line 755 didn't complete, 2) line 755 didn't jump to line 756, because the loop on line 755 never started

756 if str(instid) not in block_instruments.instruments.keys(): 

757 raise_test_warning ("assert_block_section_ahead_clear - Instrument: "+str(instid)+" does not exist") 

758 elif not block_instruments.block_section_ahead_clear(instid): 

759 raise_test_error ("assert_block_section_ahead_clear - Section: "+str(instid)+" - Test Fail") 

760 increment_tests_executed() 

761 

762def assert_block_section_ahead_not_clear(*instrumentids): 

763 for instid in instrumentids: 763 ↛ exit,   763 ↛ 7642 missed branches: 1) line 763 didn't return from function 'assert_block_section_ahead_not_clear', because the loop on line 763 didn't complete, 2) line 763 didn't jump to line 764, because the loop on line 763 never started

764 if str(instid) not in block_instruments.instruments.keys(): 

765 raise_test_warning ("assert_block_section_ahead_clear - Instrument: "+str(instid)+" does not exist") 

766 elif block_instruments.block_section_ahead_clear(instid): 

767 raise_test_error ("assert_block_section_ahead_not_clear - Section: "+str(instid)+" - Test Fail") 

768 increment_tests_executed() 

769 

770# ------------------------------------------------------------------------------ 

771# Dummy event class for generating mouse events (for the schematic tests) 

772# ------------------------------------------------------------------------------ 

773 

774class dummy_event(): 

775 def __init__(self, x=0, y=0, x_root=0, y_root=0, keysym=""): 

776 self.x = x 

777 self.y = y 

778 self.x_root = x_root 

779 self.y_root = y_root 

780 self.widget = schematic.canvas 

781 self.keysym = keysym 

782 

783# ------------------------------------------------------------------------------ 

784# Functions to excersise the schematic Editor - Create Functions 

785# ------------------------------------------------------------------------------ 

786 

787def create_line(): 

788 run_function(lambda:schematic.create_object(objects.object_type.line)) 788 ↛ exitline 788 didn't run the lambda on line 788

789 object_id = list(objects.schematic_objects)[-1] 

790 return(object_id) 

791 

792def create_track_sensor(): 

793 run_function(lambda:schematic.create_object(objects.object_type.track_sensor)) 793 ↛ exitline 793 didn't run the lambda on line 793

794 object_id = list(objects.schematic_objects)[-1] 

795 return(object_id) 

796 

797def create_colour_light_signal(): 

798 run_function(lambda:schematic.create_object(objects.object_type.signal, 798 ↛ exitline 798 didn't run the lambda on line 798

799 signals_common.sig_type.colour_light.value, 

800 signals_colour_lights.signal_sub_type.four_aspect.value)) 

801 object_id = list(objects.schematic_objects)[-1] 

802 return(object_id) 

803 

804def create_semaphore_signal(): 

805 run_function(lambda:schematic.create_object(objects.object_type.signal, 805 ↛ exitline 805 didn't run the lambda on line 805

806 signals_common.sig_type.semaphore.value, 

807 signals_semaphores.semaphore_sub_type.home.value)) 

808 object_id = list(objects.schematic_objects)[-1] 

809 return(object_id) 

810 

811def create_ground_position_signal(): 

812 run_function(lambda:schematic.create_object(objects.object_type.signal, 812 ↛ exitline 812 didn't run the lambda on line 812

813 signals_common.sig_type.ground_position.value, 

814 signals_ground_position.ground_pos_sub_type.standard.value)) 

815 object_id = list(objects.schematic_objects)[-1] 

816 return(object_id) 

817 

818def create_ground_disc_signal(): 

819 run_function(lambda:schematic.create_object(objects.object_type.signal, 819 ↛ exitline 819 didn't run the lambda on line 819

820 signals_common.sig_type.ground_disc.value, 

821 signals_ground_disc.ground_disc_sub_type.standard.value)) 

822 object_id = list(objects.schematic_objects)[-1] 

823 return(object_id) 

824 

825def create_track_section(): 

826 run_function(lambda:schematic.create_object(objects.object_type.section)) 826 ↛ exitline 826 didn't run the lambda on line 826

827 object_id = list(objects.schematic_objects)[-1] 

828 return(object_id) 

829 

830def create_block_instrument(): 

831 run_function(lambda:schematic.create_object(objects.object_type.instrument, 831 ↛ exitline 831 didn't run the lambda on line 831

832 block_instruments.instrument_type.single_line.value)) 

833 object_id = list(objects.schematic_objects)[-1] 

834 return(object_id) 

835 

836def create_left_hand_point(): 

837 run_function(lambda:schematic.create_object(objects.object_type.point,points.point_type.LH.value)) 837 ↛ exitline 837 didn't run the lambda on line 837

838 object_id = list(objects.schematic_objects)[-1] 

839 return(object_id) 

840 

841def create_right_hand_point(): 

842 run_function(lambda:schematic.create_object(objects.object_type.point,points.point_type.LH.value)) 842 ↛ exitline 842 didn't run the lambda on line 842

843 object_id = list(objects.schematic_objects)[-1] 

844 return(object_id) 

845 

846def create_textbox(): 

847 run_function(lambda:schematic.create_object(objects.object_type.textbox)) 847 ↛ exitline 847 didn't run the lambda on line 847

848 object_id = list(objects.schematic_objects)[-1] 

849 return(object_id) 

850 

851# ------------------------------------------------------------------------------ 

852# Internal functions to get the selection position and simulate a move 

853# ------------------------------------------------------------------------------ 

854 

855def get_selection_position (object_id): 

856 if objects.schematic_objects[object_id]["item"] == objects.object_type.line: 856 ↛ 864line 856 didn't jump to line 864, because the condition on line 856 was never false

857 x1 = objects.schematic_objects[object_id]["posx"] 

858 y1 = objects.schematic_objects[object_id]["posy"] 

859 x2 = objects.schematic_objects[object_id]["endx"] 

860 y2 = objects.schematic_objects[object_id]["endy"] 

861 xpos = (x1+x2) / 2 

862 ypos = (y1+y2) / 2 

863 else: 

864 xpos = objects.schematic_objects[object_id]["posx"] 

865 ypos = objects.schematic_objects[object_id]["posy"] 

866 return(xpos, ypos) 

867 

868def move_cursor (xstart:int, ystart:int, xfinish:int, yfinish:int, steps:int, delay:float): 

869 xdiff = xfinish - xstart 

870 ydiff = yfinish - ystart 

871 sleep_delay = delay/steps 

872 for step in range(steps+1): 872 ↛ exitline 872 didn't return from function 'move_cursor', because the loop on line 872 didn't complete

873 event = dummy_event(x=xstart+step*(xdiff/steps),y=ystart+step*(ydiff/steps)) 

874 run_function(lambda:schematic.track_cursor(event)) 874 ↛ exit,   874 ↛ 8752 missed branches: 1) line 874 didn't run the lambda on line 874, 2) line 874 didn't jump to line 875

875 sleep(sleep_delay) 

876 

877# ------------------------------------------------------------------------------ 

878# Helper functions to get the ID of an item from the Object ID and vice-versa 

879# ------------------------------------------------------------------------------ 

880 

881def get_item_id(object_id): 

882 if object_id not in objects.schematic_objects.keys(): 

883 raise_test_warning ("get_item_id - object: "+str(object_id)+" does not exist") 

884 return(0) 

885 else: 

886 return(objects.schematic_objects[object_id]["itemid"]) 

887 

888def get_object_id(item_type:str, item_id:int): 

889 for object_id in objects.schematic_objects.keys(): 889 ↛ 893line 889 didn't jump to line 893, because the loop on line 889 didn't complete

890 object_to_test = objects.schematic_objects[object_id] 

891 if object_to_test["item"] == item_type and object_to_test["itemid"] == item_id: 891 ↛ 889,   891 ↛ 8922 missed branches: 1) line 891 didn't jump to line 889, because the condition on line 891 was never false, 2) line 891 didn't jump to line 892, because the condition on line 891 was never true

892 return(object_id) 

893 raise_test_warning ("get_object_id - item: "+item_type+" "+str(item_id)+" does not exist") 

894 return(0) 

895 

896# ------------------------------------------------------------------------------ 

897# Functions to exercise the Main Menubar Controls 

898# ------------------------------------------------------------------------------ 

899 

900def set_edit_mode(): 

901 run_function(lambda:main_menubar.edit_mode(),delay=0.5) 

902 

903def set_run_mode(): 

904 run_function(lambda:main_menubar.run_mode(),delay=0.5) 

905 

906def set_automation_on(): 

907 run_function(lambda:main_menubar.automation_enable(),delay=0.5) 

908 

909def set_automation_off(): 

910 run_function(lambda:main_menubar.automation_disable(),delay=0.5) 

911 

912def reset_layout(): 

913 run_function(lambda:main_menubar.reset_layout(ask_for_confirm=False),delay=1.0) 

914 

915# ------------------------------------------------------------------------------ 

916# Functions to exercise the schematic Editor 

917# ------------------------------------------------------------------------------ 

918 

919# Simulates the <cntl-a> keypress on the canvas 

920# This event is normally only enabled in RUN Mode 

921def toggle_automation(): 

922 event = dummy_event(keysym="a") 

923 run_function(lambda:main_menubar.handle_canvas_event(event),delay=0.5) 

924 

925# Simulates the <cntl-m> keypress on the canvas 

926# This event is normally enabled in both EDIT Mode (disabled when move in progress) and RUN mode 

927def toggle_mode(): 

928 event = dummy_event(keysym="m") 

929 run_function(lambda:main_menubar.handle_canvas_event(event),delay=0.5) 

930 

931# Simulates the <cntl-s> keypress on the canvas 

932# This event is normally only enabled in EDIT Mode (disabled when move in progress) 

933def toggle_snap_to_grid(): 

934 event = dummy_event(keysym="s") 

935 run_function(lambda:main_menubar.handle_canvas_event(event),delay=0.5) 

936 

937# Simulates the <cntl-r> keypress on the canvas 

938# This event is normally enabled in EDIT Mode (disabled when move in progress) and RUN mode 

939def reset_window_size(): 

940 run_function(lambda:schematic.reset_window_size(),delay=0.5) 

941 

942# This function enables object configurations to be changed in support of the testing 

943# (effectively simulating OK/Apply from an object configuration window to save the changes) 

944def update_object_configuration(object_id, new_values:dict): 

945 if object_id not in objects.schematic_objects.keys(): 

946 raise_test_warning ("update_object_configuration - object: "+str(object_id)+" does not exist") 

947 else: 

948 new_object = copy.deepcopy(objects.schematic_objects[object_id]) 

949 for element in new_values.keys(): 949 ↛ 950,   949 ↛ 9552 missed branches: 1) line 949 didn't jump to line 950, because the loop on line 949 never started, 2) line 949 didn't jump to line 955, because the loop on line 949 didn't complete

950 if element not in new_object.keys(): 

951 raise_test_warning ("update_object_configuration - object: "+str(object_id)+ 

952 " - element: "+element+" is not valid") 

953 else: 

954 new_object[element] = new_values[element] 

955 run_function(lambda:objects.update_object(object_id, new_object) ) 

956 

957# Simulates <left_shift_click> followed by <left_button_release> 

958# The canvas coords of the events are determined from the object position so calling scripts need 

959# to be careful that there are no overlapping objects at that position (that might get selected instead) 

960# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress)  

961def select_or_deselect_objects(*object_ids): 

962 for object_id in object_ids: 962 ↛ exit,   962 ↛ 9632 missed branches: 1) line 962 didn't return from function 'select_or_deselect_objects', because the loop on line 962 didn't complete, 2) line 962 didn't jump to line 963, because the loop on line 962 never started

963 if object_id not in objects.schematic_objects.keys(): 

964 raise_test_warning ("select_or_deselect_objects - object: "+str(object_id)+" does not exist") 

965 else: 

966 xpos, ypos = get_selection_position(object_id) 

967 event = dummy_event(x=xpos, y=ypos) 

968 run_function(lambda:schematic.left_shift_click(event)) 968 ↛ 969line 968 didn't jump to line 969

969 run_function(lambda:schematic.left_button_release(event)) 

970 

971# Simulates <left_button_click> followed by <left_button_release> 

972# The canvas coords of the events are determined from the object position so calling scripts need 

973# to be careful that there are no overlapping objects at that position (that might get selected instead) 

974# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress)  

975def select_single_object(object_id): 

976 if object_id not in objects.schematic_objects.keys(): 

977 raise_test_warning ("select_or_deselect_objects - object: "+str(object_id)+" does not exist") 

978 else: 

979 xpos, ypos = get_selection_position(object_id) 

980 event = dummy_event(x=xpos, y=ypos) 

981 run_function(lambda:schematic.left_button_click(event)) 981 ↛ 982line 981 didn't jump to line 982

982 run_function(lambda:schematic.left_button_release(event)) 

983 

984# Simulates a <double_left_click> event on the canvas (to bring up the object editing window) 

985# As this function is intended to excersise the schematic editor, we close the window straight afterwards 

986# The canvas coords of the event is determined from the object position so calling scripts need 

987# to be careful that there are no overlapping objects at that position (that might get selected instead) 

988# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress)  

989def select_and_edit_single_object(object_id): 

990 if object_id not in objects.schematic_objects.keys(): 

991 raise_test_warning ("select_and_edit_single_object - object: "+str(object_id)+" does not exist") 

992 else: 

993 xpos, ypos = get_selection_position(object_id) 

994 event = dummy_event(x=xpos, y=ypos) 

995 run_function(lambda:schematic.left_double_click(event), delay=1.0) 995 ↛ 996line 995 didn't jump to line 996

996 run_function(lambda:schematic.close_edit_window(cancel=True)) 

997 

998# Simulates <left_button_click> followed by a series of <motion> events then <left_button_release> 

999# The canvas coords of the initial event is determined from the line position so calling scripts need 

1000# to be careful that there are no overlapping objects at that position (that might get selected instead) 

1001# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress) 

1002# If the 'test_cancel' flag is set then an <esc> event is raised before the <left_button_release> 

1003# event to cancel the move and return all selected objects to their initial positions 

1004def select_and_move_objects(object_id, xfinish:int, yfinish:int, steps:int=10, delay:float=0.0, test_cancel:bool=False): 

1005 if object_id not in objects.schematic_objects.keys(): 

1006 raise_test_warning ("select_and_move_objects - object: "+str(object_id)+" does not exist") 

1007 else: 

1008 xstart, ystart = get_selection_position(object_id) 

1009 event = dummy_event(x=xstart, y=ystart) 

1010 run_function(lambda:schematic.left_button_click(event)) 1010 ↛ exitline 1010 didn't run the lambda on line 1010

1011 if object_id in schematic.schematic_state["selectedobjects"]: 1011 ↛ 1012line 1011 didn't jump to line 1012, because the condition on line 1011 was never true

1012 move_cursor(xstart, ystart, xfinish, yfinish, steps, delay) 

1013 else: 

1014 raise_test_warning("select_and_move_objects - move aborted - object: "+str(object_id)+" was not selected") 

1015 if test_cancel: run_function(lambda:schematic.cancel_move_in_progress()) 1015 ↛ 1016line 1015 didn't jump to line 1016, because the condition on line 1015 was never false

1016 run_function(lambda:schematic.left_button_release(event)) 

1017 

1018# Simulates <right_button_click> followed by a series of <motion> events then <right_button_release> 

1019# The canvas coords of the events are determined from the coordinates passed into the test function. Note 

1020# that calling scripts need to be careful that there are no objects at that position (otherwise the 

1021# initial right click will bring up the Object popup menu rather than starting the area selection) 

1022# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress) 

1023# If the 'test_cancel' flag is set then an <esc> event is raised before the <left_button_release> 

1024# event to cancel the move and return all selected objects to their initial positions 

1025def select_area(xstart:int, ystart:int, xfinish:int, yfinish:int, steps:int=10, delay:float=0.0, test_cancel:bool=False): 

1026 event = dummy_event(x=xstart, y=ystart) 

1027 run_function(lambda:schematic.left_button_click(event)) 1027 ↛ exit,   1027 ↛ 10282 missed branches: 1) line 1027 didn't run the lambda on line 1027, 2) line 1027 didn't jump to line 1028

1028 if schematic.schematic_state["selectedobjects"] != []: 

1029 raise_test_warning ("select_area - area selection aborted - cursor was over an object") 

1030 else: 

1031 move_cursor(xstart, ystart, xfinish, yfinish, steps, delay) 

1032 if test_cancel: run_function(lambda:schematic.cancel_move_in_progress()) 1032 ↛ 1033line 1032 didn't jump to line 1033, because the condition on line 1032 was never false

1033 run_function(lambda:schematic.left_button_release(event)) 

1034 

1035# Simulates <left_button_click> followed by a series of <motion> events then <left_button_release> 

1036# The canvas coords of the initial event is determined from the line position so calling scripts need 

1037# to be careful that there are no overlapping objects at that position (that might get selected instead) 

1038# These events are only enabled in EDIT Mode (NOT disabled when a move is in progress) 

1039# If the 'test_cancel' flag is set then an <esc> event is raised before the <left_button_release> 

1040# event to cancel the move and return all selected objects to their initial positions 

1041def select_and_move_line_end(object_id, line_end:int, xfinish:int, yfinish:int, steps:int=10, delay:float=0.0, test_cancel:bool=False): 

1042 if object_id not in objects.schematic_objects.keys(): 

1043 raise_test_warning ("select_and_move_line_end - object: "+str(object_id)+" does not exist") 

1044 elif line_end != 1 and line_end != 2: 

1045 raise_test_warning ("select_and_move_line_end - object:"+str(object_id)+ 

1046 " - Line end must be specified as '1' or '2'") 

1047 elif object_id not in schematic.schematic_state["selectedobjects"]: 

1048 raise_test_warning ("select_and_move_line_end - move aborted - object: "+str(object_id)+" must be selected first") 

1049 else: 

1050 if line_end == 1: 1050 ↛ 1053line 1050 didn't jump to line 1053, because the condition on line 1050 was never false

1051 xstart = objects.schematic_objects[object_id]["posx"] 

1052 ystart = objects.schematic_objects[object_id]["posy"] 

1053 elif line_end == 2: 1053 ↛ 1056line 1053 didn't jump to line 1056, because the condition on line 1053 was never false

1054 xstart = objects.schematic_objects[object_id]["endx"] 

1055 ystart = objects.schematic_objects[object_id]["endy"] 

1056 event = dummy_event(x=xstart, y=ystart) 

1057 run_function(lambda:schematic.left_button_click(event)) 1057 ↛ exit,   1057 ↛ 10582 missed branches: 1) line 1057 didn't run the lambda on line 1057, 2) line 1057 didn't jump to line 1058

1058 if not schematic.schematic_state["editlineend1"] and not schematic.schematic_state["editlineend2"]: 

1059 raise_test_warning ("select_and_move_line_end - move aborted - Line end was not selected") 

1060 else: 

1061 move_cursor(xstart, ystart, xfinish, yfinish, steps, delay) 

1062 if test_cancel: run_function(lambda:schematic.cancel_move_in_progress()) 1062 ↛ 1063line 1062 didn't jump to line 1063, because the condition on line 1062 was never false

1063 run_function(lambda:schematic.left_button_release(event)) 

1064 

1065# Simulates the <up>, <down>, <left> or <right> 'arrow' keypresses 

1066# These events are enabled in both EDIT Mode (disabled when move in progress) and RUN Mode 

1067# In RUN Mode they are used to scroll the canvas (if the canvas is bigger than the window) 

1068def nudge_selected_objects(direction:str="Left"): 

1069 if not direction in ("Left", "Right", "Up", "Down"): 

1070 raise_test_warning ("nudge_selected_objects - invalid direction: '"+direction+"'") 

1071 else: 

1072 event=dummy_event(keysym=direction) 

1073 run_function(lambda:schematic.nudge_selected_objects(event)) 

1074 

1075# Simulates the <s> keypress or 'snap-to-grid' selection from object popup menu 

1076# These events are only enabled in EDIT Mode (disabled when move in progress) 

1077def snap_selected_objects_to_grid(): 

1078 run_function(lambda:schematic.snap_selected_objects_to_grid(), delay=0.5) 

1079 

1080# Simulates the 'select_all' selection from the canvas popup menu 

1081# These events are normally only enabled in EDIT Mode (disabled when move in progress) 

1082def select_all_objects(): 

1083 run_function(lambda:schematic.select_all_objects()) 

1084 

1085# Simulates the <esc> keypress to de-select all objects when a move is not in progress 

1086# Note that if a move is in progress the <esc> key has a different function to cancel the move 

1087# This event is normally only enabled in EDIT Mode (disabled when move in progress) 

1088def deselect_all_objects(): 

1089 run_function(lambda:schematic.deselect_all_objects()) 

1090 

1091# Simulates the <r> keypress or 'rotate' selection from the object popup menu 

1092# These events are normally only enabled in EDIT Mode (disabled when move in progress) 

1093def rotate_selected_objects(): 

1094 run_function(lambda:schematic.rotate_selected_objects(),delay=0.5) 

1095 

1096# Simulates the <backspace>/<delete> keypress or 'delete' selection from the object popup menu 

1097# These events are normally only enabled in EDIT Mode (disabled when move in progress) 

1098def delete_selected_objects(): 

1099 run_function(lambda:schematic.delete_selected_objects(),delay=0.5) 

1100 

1101# Simulates the <cntl-c> keypress or 'copy' selection from the object popup menu 

1102# These events are normally only enabled in EDIT Mode (disabled when move in progress) 

1103def copy_selected_objects(): 

1104 run_function(lambda:schematic.copy_selected_objects()) 

1105 

1106# Simulates the <cntl-v> keypress or 'paste' selection from the canvas popup menu 

1107# These events are normally only enabled in EDIT Mode (disabled when move in progress) 

1108def paste_clipboard_objects(): 

1109 run_function(lambda:schematic.paste_clipboard_objects(),delay=0.5) 1109 ↛ exit,   1109 ↛ 11102 missed branches: 1) line 1109 didn't run the lambda on line 1109, 2) line 1109 didn't jump to line 1110

1110 return(schematic.schematic_state["selectedobjects"]) 

1111 

1112# Simulates the <cntl-z> keypress event on the canvas 

1113# This event is normally only enabled in EDIT Mode (disabled when move in progress) 

1114def undo(): 

1115 run_function(lambda:schematic.schematic_undo(),delay=0.5) 

1116 

1117# Simulates the <cntl-v> keypress event on the canvas 

1118# This event is normally only enabled in EDIT Mode (disabled when move in progress) 

1119def redo(): 

1120 run_function(lambda:schematic.schematic_redo(),delay=0.5) 

1121 

1122def test_all_edit_object_windows(test_all_controls:bool=False, report_object_tested:bool=False): 

1123 object_types = (objects.object_type.textbox, objects.object_type.line, objects.object_type.point, objects.object_type.signal, 

1124 objects.object_type.section, objects.object_type.instrument, objects.object_type.track_sensor) 

1125 for object_type in object_types: 1125 ↛ exitline 1125 didn't return from function 'test_all_edit_object_windows', because the loop on line 1125 didn't complete

1126 for object_id in objects.schematic_objects.keys(): 

1127 if objects.schematic_objects[object_id]["item"] == object_type: 1127 ↛ 1126line 1127 didn't jump to line 1126, because the condition on line 1127 was never false

1128 configuration = copy.deepcopy(objects.schematic_objects[object_id]) 

1129 if report_object_tested: 

1130 print("Testing object edit window for:",configuration["item"],configuration["itemid"]) 

1131 # Get rid of the bits we dont need 

1132 if configuration["item"] == objects.object_type.line: 1132 ↛ 1138line 1132 didn't jump to line 1138, because the condition on line 1132 was never false

1133 del configuration["line"] ## Tkinter drawing object - re-created on re-draw 

1134 del configuration["end1"] ## Tkinter drawing object - re-created on re-draw 

1135 del configuration["end2"] ## Tkinter drawing object - re-created on re-draw 

1136 del configuration["stop1"] ## Tkinter drawing object - re-created on re-draw 

1137 del configuration["stop2"] ## Tkinter drawing object - re-created on re-draw 

1138 elif configuration["item"] == objects.object_type.section: 1138 ↛ 1141line 1138 didn't jump to line 1141, because the condition on line 1138 was never false

1139 del configuration["label"] ## Always reset to default after editing 

1140 del configuration["state"] ## Always reset to default after editing 

1141 run_function(lambda:schematic.deselect_all_objects()) 

1142 run_function(lambda:schematic.select_object(object_id)) 

1143 run_function(lambda:schematic.edit_selected_object(), delay=1.0) 1143 ↛ exitline 1143 didn't run the lambda on line 1143

1144 if test_all_controls: 1144 ↛ 1149line 1144 didn't jump to line 1149, because the condition on line 1144 was never false

1145 run_function(lambda:schematic.close_edit_window(reset=True), delay=0.2) 

1146 run_function(lambda:schematic.close_edit_window(apply=True), delay=0.2) 

1147 run_function(lambda:schematic.close_edit_window(cancel=True), delay=0.2) 

1148 run_function(lambda:schematic.edit_selected_object(), delay=1.0) 

1149 run_function(lambda:schematic.close_edit_window(ok=True), delay=0.5) 1149 ↛ exit,   1149 ↛ 11502 missed branches: 1) line 1149 didn't run the lambda on line 1149, 2) line 1149 didn't jump to line 1150

1150 assert_object_configuration(object_id, configuration) 

1151 

1152# ------------------------------------------------------------------------------ 

1153# Functions to make test 'asserts' - in terms of expected state/behavior 

1154# ------------------------------------------------------------------------------ 

1155 

1156def assert_object_configuration(object_id, test_values:dict): 

1157 if object_id not in objects.schematic_objects.keys(): 

1158 raise_test_warning ("assert_object_configuration - object: "+str(object_id)+" does not exist") 

1159 else: 

1160 object_to_test = (objects.schematic_objects[object_id]) 

1161 for element in test_values.keys(): 1161 ↛ exit,   1161 ↛ 11622 missed branches: 1) line 1161 didn't return from function 'assert_object_configuration', because the loop on line 1161 didn't complete, 2) line 1161 didn't jump to line 1162, because the loop on line 1161 never started

1162 if element not in object_to_test.keys(): 

1163 raise_test_warning ("assert_object_configuration - object: "+str(object_id)+ 

1164 " - element: "+element+" is not valid") 

1165 elif object_to_test[element] != test_values[element]: 

1166 raise_test_error ("assert_object_configuration - object:" +str(object_id)+" - element: "+element+ 

1167 " - Test Fail" +"\nExpected: "+str(test_values[element])+"\nActual: "+str(object_to_test[element])) 

1168 increment_tests_executed() 

1169 

1170def assert_object_position(object_id, x1:int, y1:int, x2:int=None, y2:int=None): 

1171 if object_id not in objects.schematic_objects.keys(): 

1172 raise_test_warning ("assert_object_position - object: "+str(object_id)+" does not exist") 

1173 else: 

1174 object_to_test = (objects.schematic_objects[object_id]) 

1175 if object_to_test["posx"] != x1: 

1176 raise_test_error ("assert_object_position - object:" +str(object_id)+ 

1177 " - x1 - Test Fail - value : "+str(object_to_test["posx"])) 

1178 increment_tests_executed() 

1179 if object_to_test["posy"] != y1: 

1180 raise_test_error ("assert_object_position - object:" +str(object_id)+ 

1181 " - y1 - Test Fail - value : "+str(object_to_test["posy"])) 

1182 increment_tests_executed() 

1183 if x2 is not None and y2 is not None: 1183 ↛ exit,   1183 ↛ 11842 missed branches: 1) line 1183 didn't return from function 'assert_object_position', because the condition on line 1183 was never false, 2) line 1183 didn't jump to line 1184, because the condition on line 1183 was never true

1184 if object_to_test["item"] is not objects.object_type.line: 

1185 raise_test_warning ("assert_object_position - object:" +str(object_id)+ 

1186 " is not a line - its a "+str(object_to_test["item"])) 

1187 else: 

1188 if object_to_test["endx"] != x2: 

1189 raise_test_error ("assert_object_position - object:" +str(object_id)+ 

1190 " - x2 - Test Fail - value : "+str(object_to_test["endx"])) 

1191 increment_tests_executed() 

1192 if object_to_test["endy"] != y2: 

1193 raise_test_error ("assert_object_position - object:" +str(object_id)+ 

1194 " - y2 - Test Fail - value : "+str(object_to_test["endy"])) 

1195 increment_tests_executed() 

1196 

1197def assert_objects_selected(*object_ids): 

1198 for object_id in object_ids: 1198 ↛ exit,   1198 ↛ 11992 missed branches: 1) line 1198 didn't return from function 'assert_objects_selected', because the loop on line 1198 didn't complete, 2) line 1198 didn't jump to line 1199, because the loop on line 1198 never started

1199 if object_id not in objects.schematic_objects.keys(): 

1200 raise_test_warning ("assert_objects_selected - object: "+str(object_id)+" does not exist") 

1201 else: 

1202 if object_id not in schematic.schematic_state["selectedobjects"]: 

1203 raise_test_error ("assert_objects_selected - object:" +str(object_id)+" is not selected") 

1204 increment_tests_executed() 

1205 

1206def assert_objects_deselected(*object_ids): 

1207 for object_id in object_ids: 1207 ↛ exit,   1207 ↛ 12082 missed branches: 1) line 1207 didn't return from function 'assert_objects_deselected', because the loop on line 1207 didn't complete, 2) line 1207 didn't jump to line 1208, because the loop on line 1207 never started

1208 if object_id not in objects.schematic_objects.keys(): 

1209 raise_test_warning ("assert_objects_deselected - object: "+str(object_id)+" does not exist") 

1210 else: 

1211 if object_id in schematic.schematic_state["selectedobjects"]: 

1212 raise_test_error ("assert_objects_deselected - object:" +str(object_id)+" is selected") 

1213 increment_tests_executed() 

1214 

1215def assert_objects_exist(*object_ids): 

1216 for object_id in object_ids: 1216 ↛ exit,   1216 ↛ 12172 missed branches: 1) line 1216 didn't return from function 'assert_objects_exist', because the loop on line 1216 didn't complete, 2) line 1216 didn't jump to line 1217, because the loop on line 1216 never started

1217 if object_id not in objects.schematic_objects.keys(): 

1218 raise_test_error ("assert_objects_exist - object: "+str(object_id)+" does not exist") 

1219 increment_tests_executed() 

1220 

1221def assert_objects_do_not_exist(*object_ids): 

1222 for object_id in object_ids: 1222 ↛ exit,   1222 ↛ 12232 missed branches: 1) line 1222 didn't return from function 'assert_objects_do_not_exist', because the loop on line 1222 didn't complete, 2) line 1222 didn't jump to line 1223, because the loop on line 1222 never started

1223 if object_id in objects.schematic_objects.keys(): 

1224 raise_test_error ("assert_objects_does_not_exist - object: "+str(object_id)+" exists") 

1225 increment_tests_executed() 

1226 

1227 

1228############################################################################################# 

1229 

1230