1 from calculus.client_1 import RemoteCalculationClient
2 from twisted.trial import unittest
3 from twisted.test import proto_helpers
7 class ClientCalculationTestCase(unittest.TestCase):
9 self.tr = proto_helpers.StringTransport()
10 self.proto = RemoteCalculationClient()
11 self.proto.makeConnection(self.tr)
14 def _test(self, operation, a, b, expected):
15 d = getattr(self.proto, operation)(a, b)
16 self.assertEqual(self.tr.value(), '%s %d %d\r\n' % (operation, a, b))
18 d.addCallback(self.assertEqual, expected)
19 self.proto.dataReceived("%d\r\n" % (expected,))
24 return self._test('add', 7, 6, 13)
27 def test_subtract(self):
28 return self._test('subtract', 82, 78, 4)
31 def test_multiply(self):
32 return self._test('multiply', 2, 8, 16)
35 def test_divide(self):
36 return self._test('divide', 14, 3, 4)