Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / trial / calculus / test / test_client_1.py
1 from calculus.client_1 import RemoteCalculationClient
2 from twisted.trial import unittest
3 from twisted.test import proto_helpers
4
5
6
7 class ClientCalculationTestCase(unittest.TestCase):
8     def setUp(self):
9         self.tr = proto_helpers.StringTransport()
10         self.proto = RemoteCalculationClient()
11         self.proto.makeConnection(self.tr)
12
13
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))
17         self.tr.clear()
18         d.addCallback(self.assertEqual, expected)
19         self.proto.dataReceived("%d\r\n" % (expected,))
20         return d
21
22
23     def test_add(self):
24         return self._test('add', 7, 6, 13)
25
26
27     def test_subtract(self):
28         return self._test('subtract', 82, 78, 4)
29
30
31     def test_multiply(self):
32         return self._test('multiply', 2, 8, 16)
33
34
35     def test_divide(self):
36         return self._test('divide', 14, 3, 4)
37