diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common.py | 2 | ||||
-rw-r--r-- | tests/test_gio.py | 49 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/common.py b/tests/common.py index d0ff439..8568635 100644 --- a/tests/common.py +++ b/tests/common.py @@ -9,6 +9,7 @@ def importModules(buildDir, srcDir): sys.path.insert(0, srcDir) sys.path.insert(0, buildDir) sys.path.insert(0, os.path.join(buildDir, 'gobject')) + sys.path.insert(0, os.path.join(buildDir, 'gio')) import ltihooks # testhelper @@ -17,6 +18,7 @@ def importModules(buildDir, srcDir): testhelper = importModule('testhelper', '.') gobject = importModule('gobject', buildDir, 'gobject') + gio = importModule('gio', buildDir, 'gio') ltihooks.uninstall() del ltihooks diff --git a/tests/test_gio.py b/tests/test_gio.py new file mode 100644 index 0000000..696a80a --- /dev/null +++ b/tests/test_gio.py @@ -0,0 +1,49 @@ +# -*- Mode: Python -*- + +import os +import unittest + +from common import gio, gobject + + +class TestInputStream(unittest.TestCase): + def setUp(self): + f = open("inputstream.txt", "w") + f.write("testing") + + self._f = open("inputstream.txt", "r") + self.stream = gio.unix.InputStream(self._f.fileno(), False) + + def tearDown(self): + self._f.close() + os.unlink("inputstream.txt") + + def testWrite(self): + self.assertEquals(self.stream.read(), "testing") + + +class TestOutputStream(unittest.TestCase): + def setUp(self): + self._f = open("outputstream.txt", "w") + self.stream = gio.unix.OutputStream(self._f.fileno(), False) + + def tearDown(self): + self._f.close() + os.unlink("outputstream.txt") + + def testWrite(self): + self.stream.write("testing") + self.stream.close() + self.failUnless(os.path.exists("outputstream.txt")) + self.assertEquals(open("outputstream.txt").read(), "testing") + + def testWriteAsync(self): + def callback(stream, result): + loop.quit() + + f = gio.file_new_for_path("outputstream.txt") + stream = f.read() + stream.read_async(10240, 0, None, callback) + + loop = gobject.MainLoop() + loop.run() |