summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Pogonyshev <pogonyshev@gmx.net>2009-05-30 16:57:49 +0300
committerPaul Pogonyshev <pogonyshev@gmx.net>2009-05-31 17:20:29 +0300
commit833d4da202bcfcb01a414f8aec4b751ec8e1ccb2 (patch)
treee8ed82611d46cdc090f41cac0f21777e4e75a36d /tests
parent2cb569c0ced49f9ed5ca83292d5f15c837066688 (diff)
downloadpygobject-833d4da202bcfcb01a414f8aec4b751ec8e1ccb2.tar.gz
pygobject-833d4da202bcfcb01a414f8aec4b751ec8e1ccb2.tar.xz
pygobject-833d4da202bcfcb01a414f8aec4b751ec8e1ccb2.zip
Wrap gio.DataInputStream.read_line_async and read_until_async
Wrap the functions and their corresponding *_finish() functions. Create 'gdatainputstream.override' for these and move two existing functions there. Add unit tests. Re-enable synchronous read_line unit test and adjust it for new official GIO behavior. Bug #584285.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_gio.py51
1 files changed, 46 insertions, 5 deletions
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 05b82b3..2d33e8f 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -691,20 +691,61 @@ class TestDataInputStream(unittest.TestCase):
self.data_stream = gio.DataInputStream(self.base_stream)
def test_read_line(self):
- # Currently fails because GIO itself is buggy. See bug 547481.
- return
self.base_stream.add_data('foo\nbar\n\nbaz')
- self.assertEquals('foo\n', self.data_stream.read_line())
- self.assertEquals('bar\n', self.data_stream.read_line())
- self.assertEquals('\n', self.data_stream.read_line())
+ self.assertEquals('foo', self.data_stream.read_line())
+ self.assertEquals('bar', self.data_stream.read_line())
+ self.assertEquals('', self.data_stream.read_line())
self.assertEquals('baz', self.data_stream.read_line())
+ def test_read_line_async(self):
+ def do_read_line_async():
+ loop = glib.MainLoop()
+ line = []
+
+ def callback(stream, result):
+ try:
+ line.append(stream.read_line_finish(result))
+ finally:
+ loop.quit()
+
+ self.data_stream.read_line_async(callback)
+ loop.run()
+ return line[0]
+
+ self.base_stream.add_data('foo\nbar\n\nbaz')
+ self.assertEquals('foo', do_read_line_async())
+ self.assertEquals('bar', do_read_line_async())
+ self.assertEquals('', do_read_line_async())
+ self.assertEquals('baz', do_read_line_async())
+
def test_read_until(self):
self.base_stream.add_data('sentence.end of line\nthe rest')
self.assertEquals('sentence', self.data_stream.read_until('.!?'))
self.assertEquals('end of line', self.data_stream.read_until('\n\r'))
self.assertEquals('the rest', self.data_stream.read_until('#$%^&'))
+ def test_read_until_async(self):
+ def do_read_until_async(stop_chars):
+ loop = glib.MainLoop()
+ data = []
+
+ def callback(stream, result):
+ try:
+ data.append(stream.read_until_finish(result))
+ finally:
+ loop.quit()
+
+ self.data_stream.read_until_async(stop_chars, callback)
+ loop.run()
+ return data[0]
+
+ # Note the weird difference between synchronous and
+ # asynchronous version. See bug #584284.
+ self.base_stream.add_data('sentence.end of line\nthe rest')
+ self.assertEquals('sentence', do_read_until_async('.!?'))
+ self.assertEquals('.end of line', do_read_until_async('\n\r'))
+ self.assertEquals('\nthe rest', do_read_until_async('#$%^&'))
+
class TestMemoryInputStream(unittest.TestCase):
def setUp(self):