1 from calculus.remote_1 import RemoteCalculationFactory
2 from twisted.trial import unittest
3 from twisted.test import proto_helpers
7 class RemoteCalculationTestCase(unittest.TestCase):
9 factory = RemoteCalculationFactory()
10 self.proto = factory.buildProtocol(('127.0.0.1', 0))
11 self.tr = proto_helpers.StringTransport()
12 self.proto.makeConnection(self.tr)
15 def _test(self, operation, a, b, expected):
16 self.proto.dataReceived('%s %d %d\r\n' % (operation, a, b))
17 self.assertEqual(int(self.tr.value()), expected)
21 return self._test('add', 7, 6, 13)
24 def test_subtract(self):
25 return self._test('subtract', 82, 78, 4)
28 def test_multiply(self):
29 return self._test('multiply', 2, 8, 16)
32 def test_divide(self):
33 return self._test('divide', 14, 3, 4)