Changeset 2806b5e for .tests/btlib.py
- Timestamp:
- 2021-03-29T11:32:17Z (4 years ago)
- Children:
- 6066443
- Parents:
- 7b1fd83
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
.tests/btlib.py
r7b1fd83 r2806b5e 3 3 import time 4 4 import select 5 6 SHOWLOG = False7 SHOWTESTLOG = True8 9 FUN = [10 "Did I ask you something?",11 "Oh yeah, that's right.",12 "Alright, alright. Now go back to work.",13 "Buuuuuuuuuuuuuuuurp... Excuse me!",14 "Yes?",15 "No?",16 ]17 5 18 6 SEPARATOR = "="*60 … … 96 84 return received 97 85 98 def debug_check(debug_file): 99 error_found = False 100 debug_log = '' 101 while True: 102 line = debug_file.readline() 103 if len(line) == 0: 104 break 105 debug_log += line 106 error_found = error_found or (line.lower().find('error') != -1) 107 return error_found, debug_log 108 109 def perform_test(failed, clis, test_function, test_name, debug_file): 110 for cli in clis: 111 cli.tmplog="" 112 113 print("\n"+SEPARATOR) 114 print("Test: "+test_name) 86 87 def perform_test(clis, test_function): 88 clis = [] 89 clis += [btlib.IrcClient('test1', 'asd')] 90 clis += [btlib.IrcClient('test2', 'asd')] 91 for cli in clis: 92 cli.connect() 115 93 116 94 fail = not test_function(clis) 117 95 118 debug_error, debug_log = debug_check(debug_file) 119 120 fail = fail or debug_error 96 for cli in clis: 97 cli.receive() 98 print(SEPARATOR) 99 print("Test Log "+ cli.nick+":") 100 print(cli.tmplog) 101 print(SEPARATOR) 102 121 103 122 104 if fail: 123 print("Test failed") 124 failed += [test_name] 125 else: 126 print("Test passed") 127 128 for cli in clis: 129 cli.receive() 130 131 if fail or SHOWTESTLOG: 132 for cli in clis: 133 if cli.tmplog != "": 134 print(SMOLPARATOR) 135 print("Test Log "+ cli.nick+":") 136 print(cli.tmplog) 137 138 if debug_error: 139 print(SMOLPARATOR) 140 print("Debug Log:") 141 print(debug_log) 142 143 print(SEPARATOR) 105 sys.exit(1) 106 144 107 145 108 def yes_test(clis): … … 270 233 return ret 271 234 272 273 235 def run_tests(failed): 274 debug_file = open('./debuglog','r')275 236 clis = [] 276 237 clis += [IrcClient('test1', 'asd')] … … 285 246 cli.jabber_login() 286 247 287 perform_test(failed, clis, add_buddy_test, "Add/remove buddy" , debug_file)288 perform_test(failed, clis, message_test, "Send message" , debug_file)248 perform_test(failed, clis, add_buddy_test, "Add/remove buddy") 249 perform_test(failed, clis, message_test, "Send message") 289 250 #perform_test(failed, clis, block_test, "Block user", debug_file) 290 perform_test(failed, clis, rename_test, "Rename user" , debug_file)291 perform_test(failed, clis, status_test, "Change status" , debug_file)292 perform_test(failed, clis, offline_test, "Go offline" , debug_file)293 perform_test(failed, clis, default_target_test, "Change default target" , debug_file)294 perform_test(failed, clis, help_test, "Ask for help" , debug_file)251 perform_test(failed, clis, rename_test, "Rename user") 252 perform_test(failed, clis, status_test, "Change status") 253 perform_test(failed, clis, offline_test, "Go offline") 254 perform_test(failed, clis, default_target_test, "Change default target") 255 perform_test(failed, clis, help_test, "Ask for help") 295 256 296 257 if failed or SHOWLOG: … … 309 270 print("\n" + SEPARATOR + "\nAll tests have passed") 310 271 311 debug_file.close()312 313 272 if __name__ == "__main__": 314 273 failed = []
Note: See TracChangeset
for help on using the changeset viewer.