source: geniuswebcore/test/geniusweb/simplerunner/SessionRunnerTest.py1@ 88

Last change on this file since 88 was 88, checked in by Bart Vastenhouw, 3 years ago

Added python SimpleRunner GUI

File size: 2.0 KB
Line 
1import unittest
2from unittest.mock import Mock
3
4from tudelft_utilities_logging.ReportToLogger import ReportToLogger
5from tudelft_utilities_logging.Reporter import Reporter
6
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.protocol.CurrentNegoState import CurrentNegoState
9from geniusweb.protocol.ProtocolException import ProtocolException
10from geniusweb.protocol.session.SessionProtocol import SessionProtocol
11from geniusweb.protocol.session.SessionSettings import SessionSettings
12from geniusweb.protocol.session.SessionState import SessionState
13from geniusweb.simplerunner.ClassPathConnectionFactory import ClassPathConnectionFactory
14from geniusweb.simplerunner.NegoRunner import NegoRunner
15import unittest.mock as mock
16
17
18class 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
Note: See TracBrowser for help on using the repository browser.