| 1 |
import unittest |
| 2 |
from unittest import mock |
| 3 |
|
| 4 |
import asyncio |
| 5 |
|
| 6 |
|
| 7 |
def tearDownModule(): |
| 8 |
# not needed for the test file but added for uniformness with all other |
| 9 |
# asyncio test files for the sake of unified cleanup |
| 10 |
asyncio.events._set_event_loop_policy(None) |
| 11 |
|
| 12 |
|
| 13 |
class ProtocolsAbsTests(unittest.TestCase): |
| 14 |
|
| 15 |
def test_base_protocol(self): |
| 16 |
f = mock.Mock() |
| 17 |
p = asyncio.BaseProtocol() |
| 18 |
self.assertIsNone(p.connection_made(f)) |
| 19 |
self.assertIsNone(p.connection_lost(f)) |
| 20 |
self.assertIsNone(p.pause_writing()) |
| 21 |
self.assertIsNone(p.resume_writing()) |
| 22 |
self.assertNotHasAttr(p, '__dict__') |
| 23 |
|
| 24 |
def test_protocol(self): |
| 25 |
f = mock.Mock() |
| 26 |
p = asyncio.Protocol() |
| 27 |
self.assertIsNone(p.connection_made(f)) |
| 28 |
self.assertIsNone(p.connection_lost(f)) |
| 29 |
self.assertIsNone(p.data_received(f)) |
| 30 |
self.assertIsNone(p.eof_received()) |
| 31 |
self.assertIsNone(p.pause_writing()) |
| 32 |
self.assertIsNone(p.resume_writing()) |
| 33 |
self.assertNotHasAttr(p, '__dict__') |
| 34 |
|
| 35 |
def test_buffered_protocol(self): |
| 36 |
f = mock.Mock() |
| 37 |
p = asyncio.BufferedProtocol() |
| 38 |
self.assertIsNone(p.connection_made(f)) |
| 39 |
self.assertIsNone(p.connection_lost(f)) |
| 40 |
self.assertIsNone(p.get_buffer(100)) |
| 41 |
self.assertIsNone(p.buffer_updated(150)) |
| 42 |
self.assertIsNone(p.pause_writing()) |
| 43 |
self.assertIsNone(p.resume_writing()) |
| 44 |
self.assertNotHasAttr(p, '__dict__') |
| 45 |
|
| 46 |
def test_datagram_protocol(self): |
| 47 |
f = mock.Mock() |
| 48 |
dp = asyncio.DatagramProtocol() |
| 49 |
self.assertIsNone(dp.connection_made(f)) |
| 50 |
self.assertIsNone(dp.connection_lost(f)) |
| 51 |
self.assertIsNone(dp.error_received(f)) |
| 52 |
self.assertIsNone(dp.datagram_received(f, f)) |
| 53 |
self.assertNotHasAttr(dp, '__dict__') |
| 54 |
|
| 55 |
def test_subprocess_protocol(self): |
| 56 |
f = mock.Mock() |
| 57 |
sp = asyncio.SubprocessProtocol() |
| 58 |
self.assertIsNone(sp.connection_made(f)) |
| 59 |
self.assertIsNone(sp.connection_lost(f)) |
| 60 |
self.assertIsNone(sp.pipe_data_received(1, f)) |
| 61 |
self.assertIsNone(sp.pipe_connection_lost(1, f)) |
| 62 |
self.assertIsNone(sp.process_exited()) |
| 63 |
self.assertNotHasAttr(sp, '__dict__') |
| 64 |
|
| 65 |
|
| 66 |
if __name__ == '__main__': |
| 67 |
unittest.main() |