Here are the examples of the python api twisted.test.proto_helpers.StringIOWithoutClosing taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
11 Examples
3
Example 1
Project: mythbox Source File: test_protocols.py
def testBuffer(self):
"""
Test buffering for different packet size, checking received matches
expected data.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.buffer)/packet_size + 1):
s = self.buffer[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.failUnlessEqual(self.output, a.received)
3
Example 2
Project: mythbox Source File: test_protocols.py
def test_pausing(self):
"""
Test pause inside data receiving. It uses fake clock to see if
pausing/resuming work.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.pause_buf)/packet_size + 1):
s = self.pause_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEquals(self.pause_output1, a.received)
clock.advance(0)
self.assertEquals(self.pause_output2, a.received)
3
Example 3
Project: mythbox Source File: test_protocols.py
def test_rawPausing(self):
"""
Test pause inside raw date receiving.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.rawpause_buf)/packet_size + 1):
s = self.rawpause_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEquals(self.rawpause_output1, a.received)
clock.advance(0)
self.assertEquals(self.rawpause_output2, a.received)
3
Example 4
Project: mythbox Source File: test_protocols.py
def test_stopProducing(self):
"""
Test stop inside producing.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.stop_buf)/packet_size + 1):
s = self.stop_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEquals(self.stop_output, a.received)
3
Example 5
Project: mythbox Source File: test_protocols.py
def test_lineReceiverAsProducer(self):
"""
Test produce/unproduce in receiving.
"""
a = LineTester()
t = proto_helpers.StringIOWithoutClosing()
a.makeConnection(protocol.FileWrapper(t))
a.dataReceived('produce\nhello world\nunproduce\ngoodbye\n')
self.assertEquals(a.received,
['produce', 'hello world', 'unproduce', 'goodbye'])
3
Example 6
def testBuffer(self):
"""
Test buffering for different packet size, checking received matches
expected data.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.buffer) // packet_size + 1):
s = self.buffer[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEqual(self.output, a.received)
3
Example 7
def test_pausing(self):
"""
Test pause inside data receiving. It uses fake clock to see if
pausing/resuming work.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.pause_buf) // packet_size + 1):
s = self.pause_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEqual(self.pause_output1, a.received)
clock.advance(0)
self.assertEqual(self.pause_output2, a.received)
3
Example 8
def test_rawPausing(self):
"""
Test pause inside raw date receiving.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
clock = task.Clock()
a = LineTester(clock)
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.rawpause_buf) // packet_size + 1):
s = self.rawpause_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEqual(self.rawpause_output1, a.received)
clock.advance(0)
self.assertEqual(self.rawpause_output2, a.received)
3
Example 9
def test_stopProducing(self):
"""
Test stop inside producing.
"""
for packet_size in range(1, 10):
t = proto_helpers.StringIOWithoutClosing()
a = LineTester()
a.makeConnection(protocol.FileWrapper(t))
for i in range(len(self.stop_buf) // packet_size + 1):
s = self.stop_buf[i*packet_size:(i+1)*packet_size]
a.dataReceived(s)
self.assertEqual(self.stop_output, a.received)
3
Example 10
def test_lineReceiverAsProducer(self):
"""
Test produce/unproduce in receiving.
"""
a = LineTester()
t = proto_helpers.StringIOWithoutClosing()
a.makeConnection(protocol.FileWrapper(t))
a.dataReceived('produce\nhello world\nunproduce\ngoodbye\n')
self.assertEqual(a.received,
['produce', 'hello world', 'unproduce', 'goodbye'])
0
Example 11
def setUp(self):
self.input = 'a' * 7000
self.output = StringIOWithoutClosing()