def test_seek_on_buffered_pipe (self): f = GreenPipe(self.tempdir + "/TestFile", 'w+', 1024) self.assertEquals(f.tell(), 0) f.seek(0, 2) self.assertEquals(f.tell(), 0) f.write('1234567890') f.seek(0, 2) self.assertEquals(f.tell(), 10) f.seek(0) value = f.read(1) self.assertEqual(value, '1') self.assertEquals(f.tell(), 1) value = f.read(1) self.assertEqual(value, '2') self.assertEquals(f.tell(), 2) f.seek(0, 1) self.assertEqual(f.readline(), '34567890') f.seek(0) self.assertEqual(f.readline(), '1234567890') f.seek(0, 2) self.assertEqual(f.readline(), '')
def test_seek_on_buffered_pipe(self): f = GreenPipe(self.tempdir + "/TestFile", 'w+', 1024) self.assertEquals(f.tell(), 0) f.seek(0, 2) self.assertEquals(f.tell(), 0) f.write('1234567890') f.seek(0, 2) self.assertEquals(f.tell(), 10) f.seek(0) value = f.read(1) self.assertEqual(value, '1') self.assertEquals(f.tell(), 1) value = f.read(1) self.assertEqual(value, '2') self.assertEquals(f.tell(), 2) f.seek(0, 1) self.assertEqual(f.readline(), '34567890') f.seek(0) self.assertEqual(f.readline(), '1234567890') f.seek(0, 2) self.assertEqual(f.readline(), '')
def test_pipe_writes_large_messages (self): r, w = os.pipe() r = GreenPipe(r) w = GreenPipe(w, 'w') large_message = "".join([1024 * chr(i) for i in xrange(65)]) def writer (): w.write(large_message) w.close() gt = spawn(writer) for i in xrange(65): buf = r.read(1024) expected = 1024 * chr(i) self.assertEquals(buf, expected, "expected=%r..%r, found=%r..%r iter=%d" % (expected[:4], expected[-4:], buf[:4], buf[-4:], i)) gt.wait()
def test_pipe_writes_large_messages(self): r, w = os.pipe() r = GreenPipe(r) w = GreenPipe(w, 'w') large_message = "".join([1024 * chr(i) for i in xrange(65)]) def writer(): w.write(large_message) w.close() gt = spawn(writer) for i in xrange(65): buf = r.read(1024) expected = 1024 * chr(i) self.assertEquals( buf, expected, "expected=%r..%r, found=%r..%r iter=%d" % (expected[:4], expected[-4:], buf[:4], buf[-4:], i)) gt.wait()