提交 9b67688b 编写于 作者: T typhoonzero

follow comments

上级 fbd1d1cf
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
__all__ = [ __all__ = [
'map_readers', 'buffered', 'compose', 'chain', 'shuffle', 'map_readers', 'buffered', 'compose', 'chain', 'shuffle',
'ComposeNotAligned', 'firstn', 'xmap_readers', 'pipe_reader' 'ComposeNotAligned', 'firstn', 'xmap_readers', 'PipeReader'
] ]
from threading import Thread from threading import Thread
......
...@@ -147,8 +147,11 @@ class TestXmap(unittest.TestCase): ...@@ -147,8 +147,11 @@ class TestXmap(unittest.TestCase):
class TestPipeReader(unittest.TestCase): class TestPipeReader(unittest.TestCase):
def test_pipe_reader(self): def test_pipe_reader(self):
def simple_parser(lines): def example_reader(myfiles):
return lines for f in myfiles:
pr = paddle.v2.reader.PipeReader("cat %s" % f, bufsize=128)
for l in pr.get_line():
yield l
import tempfile import tempfile
...@@ -159,17 +162,12 @@ class TestPipeReader(unittest.TestCase): ...@@ -159,17 +162,12 @@ class TestPipeReader(unittest.TestCase):
for r in records: for r in records:
f.write('%s\n' % r) f.write('%s\n' % r)
cmd = "cat %s" % temp.name result = []
reader = paddle.v2.reader.pipe_reader( for r in example_reader([temp.name]):
cmd, simple_parser, bufsize=128) result.append(r)
for i in xrange(4):
result = [] for idx, e in enumerate(records):
for r in reader(): self.assertEqual(e, result[idx])
result.append(r)
for idx, e in enumerate(records):
print e, result[idx]
self.assertEqual(e, result[idx])
finally: finally:
# delete the temporary file # delete the temporary file
temp.close() temp.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册