1 | import io
|
---|
2 | import sys
|
---|
3 | import time
|
---|
4 | import unittest
|
---|
5 |
|
---|
6 | from tudelft.utilities.listener.Listener import Listener
|
---|
7 |
|
---|
8 | from geniusweb.inform.Inform import Inform
|
---|
9 | from geniusweb.inform.Settings import Settings
|
---|
10 | from geniusweb.inform.YourTurn import YourTurn
|
---|
11 | from geniusweb.partystdio.StdInOutConnectionEnd import StdInOutConnectionEnd
|
---|
12 |
|
---|
13 |
|
---|
14 | class SimpleListener(Listener[Inform]):
|
---|
15 | def __init__(self):
|
---|
16 | self.received=[]
|
---|
17 |
|
---|
18 | def notifyChange(self, info: Inform):
|
---|
19 | self.received.append(info)
|
---|
20 |
|
---|
21 |
|
---|
22 | class 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 |
|
---|
52 | def printsize(buf):
|
---|
53 | print("args="+str(buf))
|
---|
54 | time.sleep(0.1)
|
---|
55 | buf.write('82128')
|
---|
56 | |
---|