Debian Codegraph @

compliance/sync/client.py

raw
1 import json
2 import logging
3
4 from websockets.exceptions import WebSocketException
5 from websockets.sync.client import connect
6
7
8 logging.basicConfig(level=logging.WARNING)
9
10 SERVER = "ws://localhost:9001"
11
12 AGENT = "websockets.sync"
13
14
15 def get_case_count():
16 with connect(f"{SERVER}/getCaseCount") as ws:
17 return json.loads(ws.recv())
18
19
20 def run_case(case):
21 with connect(
22 f"{SERVER}/runCase?case={case}&agent={AGENT}",
23 max_size=2**25,
24 ) as ws:
25 try:
26 for msg in ws:
27 ws.send(msg)
28 except WebSocketException:
29 pass
30
31
32 def update_reports():
33 with connect(
34 f"{SERVER}/updateReports?agent={AGENT}",
35 open_timeout=60,
36 ):
37 pass
38
39
40 def main():
41 cases = get_case_count()
42 for case in range(1, cases + 1):
43 print(f"Running test case {case:03d} / {cases}... ", end="\t")
44 try:
45 run_case(case)
46 except WebSocketException as exc:
47 print(f"ERROR: {type(exc).__name__}: {exc}")
48 except Exception as exc:
49 print(f"FAIL: {type(exc).__name__}: {exc}")
50 else:
51 print("OK")
52 print(f"Ran {cases} test cases")
53 update_reports()
54 print("Updated reports")
55
56
57 if __name__ == "__main__":
58 main()