def test_bad_property_values(self): sock = socket.socket() adapter = PollingSocketStreamAdapter(sock, poll_period=1, max_read=32) with self.assertRaises(ValueError): adapter.poll_period = 0 with self.assertRaises(ValueError): adapter.max_read = -1 sock.close()
def test_timeout(self): source, drain = socket.socketpair() try: with testfixtures.Replacer() as r: mock_time = testfixtures.test_time(delta=0.1, delta_type='seconds') r.replace('streamexpect.time.time', mock_time) adapter = PollingSocketStreamAdapter(drain) with self.assertRaises(ExpectTimeout): adapter.poll(0.01) finally: source.close() drain.close()
def test_poll(self): source, drain = socket.socketpair() try: with testfixtures.Replacer() as r: mock_time = testfixtures.test_time(delta=0.1, delta_type='seconds') r.replace('streamexpect.time.time', mock_time) adapter = PollingSocketStreamAdapter(drain) for chunk in (b'alpha', b' beta', b' gamm', b'a ome'): source.send(chunk) self.assertEqual(chunk, adapter.poll(1.0)) finally: source.close() drain.close()
def test_constructor(self): sock = socket.socket() try: adapter = PollingSocketStreamAdapter(sock, poll_period=1, max_read=32) self.assertEqual(1, adapter.poll_period) self.assertEqual(32, adapter.max_read) finally: sock.close()