1 from calculus.remote_1 import RemoteCalculationFactory
2 from calculus.client_2 import RemoteCalculationClient
4 from twisted.trial import unittest
5 from twisted.internet import reactor, protocol
9 class RemoteRunCalculationTestCase(unittest.TestCase):
12 factory = RemoteCalculationFactory()
13 self.port = reactor.listenTCP(0, factory, interface="127.0.0.1")
18 if self.client is not None:
19 self.client.transport.loseConnection()
20 return self.port.stopListening()
23 def _test(self, op, a, b, expected):
24 creator = protocol.ClientCreator(reactor, RemoteCalculationClient)
27 return getattr(self.client, op)(a, b
28 ).addCallback(self.assertEqual, expected)
29 return creator.connectTCP('127.0.0.1', self.port.getHost().port
34 return self._test("add", 5, 9, 14)
37 def test_subtract(self):
38 return self._test("subtract", 47, 13, 34)
41 def test_multiply(self):
42 return self._test("multiply", 7, 3, 21)
45 def test_divide(self):
46 return self._test("divide", 84, 10, 8)