Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / listings / trial / calculus / test / test_remote_1.py
1 from calculus.remote_1 import RemoteCalculationFactory
2 from twisted.trial import unittest
3 from twisted.test import proto_helpers
4
5
6
7 class RemoteCalculationTestCase(unittest.TestCase):
8     def setUp(self):
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)
13
14
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)
18
19
20     def test_add(self):
21         return self._test('add', 7, 6, 13)
22
23
24     def test_subtract(self):
25         return self._test('subtract', 82, 78, 4)
26
27
28     def test_multiply(self):
29         return self._test('multiply', 2, 8, 16)
30
31
32     def test_divide(self):
33         return self._test('divide', 14, 3, 4)
34