3
3
test_client.py in wsproto.
4
4
'''
5
5
import argparse
6
+ import json
6
7
import logging
8
+ import sys
7
9
8
10
import trio
9
11
from trio_websocket import open_websocket_url , ConnectionClosed
@@ -23,6 +25,12 @@ async def get_case_count(url):
23
25
return int (case_count )
24
26
25
27
28
+ async def get_case_info (url , case ):
29
+ url = f'{ url } /getCaseInfo?case={ case } '
30
+ async with open_websocket_url (url ) as conn :
31
+ return json .loads (await conn .get_message ())
32
+
33
+
26
34
async def run_case (url , case ):
27
35
url = f'{ url } /runCase?case={ case } &agent={ AGENT } '
28
36
try :
@@ -52,13 +60,23 @@ async def run_tests(args):
52
60
logging .getLogger ('trio-websocket' ).setLevel (logging .DEBUG )
53
61
else :
54
62
case_count = await get_case_count (args .url )
55
- test_cases = range (1 , case_count + 1 )
63
+ test_cases = list (range (1 , case_count + 1 ))
64
+ exception_cases = []
56
65
for case in test_cases :
66
+ case_id = (await get_case_info (args .url , case ))['id' ]
57
67
if case_count :
58
- logger .info ("Running test case %d of %d" , case , case_count )
68
+ logger .info ("Running test case %s (% d of %d)" , case_id , case , case_count )
59
69
else :
60
- logger .info ("Debugging test case %d" , case )
61
- await run_case (args .url , case )
70
+ logger .info ("Debugging test case %s (%d)" , case_id , case )
71
+ try :
72
+ await run_case (args .url , case )
73
+ except Exception : # pylint: disable=broad-exception-caught
74
+ logger .exception (' runtime exception during test case %s (%d)' , case_id , case )
75
+ exception_cases .append (case_id )
76
+ if exception_cases :
77
+ logger .error ('Runtime exception in %d of %d test cases: %s' ,
78
+ len (exception_cases ), len (test_cases ), exception_cases )
79
+ sys .exit (1 )
62
80
if not args .debug_cases :
63
81
# Don't update report when debugging a single test case. It adds noise
64
82
# to the debug logging.
@@ -71,6 +89,7 @@ def parse_args():
71
89
parser = argparse .ArgumentParser (description = 'Autobahn client for'
72
90
' trio-websocket' )
73
91
parser .add_argument ('url' , help = 'WebSocket URL for server' )
92
+ # TODO: accept case ID's rather than indices
74
93
parser .add_argument ('debug_cases' , type = int , nargs = '*' , help = 'Run'
75
94
' individual test cases with debug logging (optional)' )
76
95
return parser .parse_args ()
0 commit comments