1 | import unittest
|
---|
2 | from unittest.mock import Mock
|
---|
3 |
|
---|
4 | from tudelft_utilities_logging.ReportToLogger import ReportToLogger
|
---|
5 | from tudelft_utilities_logging.Reporter import Reporter
|
---|
6 |
|
---|
7 | from geniusweb.actions.PartyId import PartyId
|
---|
8 | from geniusweb.protocol.CurrentNegoState import CurrentNegoState
|
---|
9 | from geniusweb.protocol.ProtocolException import ProtocolException
|
---|
10 | from geniusweb.protocol.session.SessionProtocol import SessionProtocol
|
---|
11 | from geniusweb.protocol.session.SessionSettings import SessionSettings
|
---|
12 | from geniusweb.protocol.session.SessionState import SessionState
|
---|
13 | from geniusweb.simplerunner.ClassPathConnectionFactory import ClassPathConnectionFactory
|
---|
14 | from geniusweb.simplerunner.NegoRunner import NegoRunner
|
---|
15 | import unittest.mock as mock
|
---|
16 |
|
---|
17 |
|
---|
18 | class SessionRunnerTest(unittest.TestCase):
|
---|
19 | PROTOCOL_EXC = ProtocolException(
|
---|
20 | "fake protocol exception", PartyId("test"))
|
---|
21 | NOW = 1000
|
---|
22 | logger = ReportToLogger("test")
|
---|
23 |
|
---|
24 | def setUp(self):
|
---|
25 | self.finishedEvent = Mock(CurrentNegoState)
|
---|
26 | self.finishedstate = Mock(SessionState)
|
---|
27 | self.finishedstate.isFinal=Mock(return_value=True)
|
---|
28 | self.finishedEvent.getState=Mock(return_value=self.finishedstate)
|
---|
29 |
|
---|
30 | def testSmoke(self):
|
---|
31 | NegoRunner(Mock(SessionSettings),
|
---|
32 | Mock(ClassPathConnectionFactory), self.logger, 5000)
|
---|
33 |
|
---|
34 | def testRun(self):
|
---|
35 | settings = Mock(SessionSettings)
|
---|
36 | protocol = Mock(SessionProtocol)
|
---|
37 | settings.getProtocol=Mock(return_value=protocol)
|
---|
38 | factory = Mock( ClassPathConnectionFactory)
|
---|
39 |
|
---|
40 | runner=NegoRunner(settings, factory, self.logger, 5000)
|
---|
41 |
|
---|
42 | spyProtocolAddlistener = mock.patch.object(protocol, 'addListener',wraps=protocol.addListener)
|
---|
43 | spyProtocolStart = mock.patch.object(protocol, 'start',wraps=protocol.start)
|
---|
44 | spyRunnerStop:Mock = mock.patch.object(runner, 'stop', wraps=runner._stop)
|
---|
45 |
|
---|
46 | runner.run();
|
---|
47 | spyProtocolAddlistener.test_assert_called_once()
|
---|
48 | spyProtocolStart.test_assert_called_once()
|
---|
49 | spyRunnerStop.test_assert_not_called()
|
---|
50 |
|
---|
51 |
|
---|
52 | def testStopNormally(self):
|
---|
53 | # CAN NOT TEST: PYTHON HAS NO SPY WITH ARG CAPTURE
|
---|
54 | pass
|
---|
55 |
|
---|
56 | def testStopWithError(self) :
|
---|
57 | # CAN NOT TEST: PYTHON HAS NO SPY WITH ARG CAPTURE
|
---|
58 | pass |
---|