source: geniuswebcore/test/geniusweb/partystdio/StdInOutTest.py@ 100

Last change on this file since 100 was 100, checked in by ruud, 20 months ago

python installs also wheel to avoid error messages

File size: 1.4 KB
Line 
1import io
2import sys
3import time
4import unittest
5
6from tudelft.utilities.listener.Listener import Listener
7
8from geniusweb.inform.Inform import Inform
9from geniusweb.inform.Settings import Settings
10from geniusweb.inform.YourTurn import YourTurn
11from geniusweb.partystdio.StdInOutConnectionEnd import StdInOutConnectionEnd
12
13
14class SimpleListener(Listener[Inform]):
15 def __init__(self):
16 self.received=[]
17
18 def notifyChange(self, info: Inform):
19 self.received.append(info)
20
21
22class StdInOutTest(unittest.TestCase):
23 def testSmoke(self):
24 StdInOutConnectionEnd()
25
26
27 #disabled, hangs for now.
28 def testRun(self):
29 print("TESTING STDINOUT")
30 data=bytes('{"Settings": {"id": "party1", "profile": "profile:1", "protocol": "protocol:1", "progress": {"ProgressTime": {"duration": 1000, "start": 12345000}}, "parameters": {"params": {}}}}', 'utf-8')
31 data2=bytes('{"YourTurn": {}}', 'utf-8')
32 fname="test.bin"
33
34 listener=SimpleListener()
35
36 with open(fname, "wb") as f:
37 f.write(len(data).to_bytes(4,'little'))
38 f.write(data)
39
40 f.write(len(data2).to_bytes(4,'little'))
41 f.write(data2)
42
43
44 std=sys.stdin
45 sys.stdin = open(fname,'r')
46 StdInOutConnectionEnd().run(listener)
47 #sys.stderr.write("test")
48 sys.stdin=std
49 self.assertTrue( isinstance(listener.received[0], Settings))
50 self.assertTrue( isinstance(listener.received[1], YourTurn))
51
52def printsize(buf):
53 print("args="+str(buf))
54 time.sleep(0.1)
55 buf.write('82128')
56
Note: See TracBrowser for help on using the repository browser.